我想把一個較小的圓圈放在另一個較大的圓圈內(不完全是圓圈,但圓環。不要緊..)
兩個圓圈都應該垂直和水平居中在頁面的正文中(就好像它們有保存中心)
我的目標是製作一個雷達(如下所示 - > [http://media.photobucket.com/image/radar/scottb57/radarScreen-719485.jpg),但雷達中的環數將根據一些參數。
我應該玩Z指數?如何在另一箇中放置一個居中的圓?
0
A
回答
0
有可能是一個更好的方式來做到這一點,但是這是我見過和使用:
<html>
<head>
<style type="text/css">
img {
/* this puts every img's upper-left corner in center of page */
display: block;
position: absolute;
left: 50%;
top: 50%;
}
/* now move each img upwards and leftwards to center it */
img#a {
/* this img is 206x42 */
margin-left: -103px;
margin-top: -21px;
}
img#b {
/* this img is 84x90 */
margin-left: -42px;
margin-top: -45px;
}
img#c {
/* this img is 12x20 */
margin-left: -6px;
margin-top: -10px;
}
</style>
</head>
<body>
<img id="a" src="a.png">
<img id="b" src="b.png">
<img id="c" src="c.png">
</body>
</html>
+0
謝謝師父!保存我的時間! – thikonom 2009-10-26 17:48:02
1
有一個辦法做到這一點沒有做任何數學或硬編碼位置基於每一個人img
它的大小。
這裏有一個很大的折衷,當然—標記要求每img
被包裹在2 div
s。但是,每次添加(或刪除)img
時,都不必更新CSS。
<html>
<head>
<style type="text/css">
/**
* omit styles for 'div#i' if centering on page
*/
div#i {
position: relative;
/**
* set any positioning or sizing, just make
* sure that 'height' or 'min-height' is set
*/
height: 99.44%;
}
div#i>div {
/**
* for the outer div of each img, put its upper-
* left corner in the center (50%, 50%) of div#i
*/
position: absolute;
left: 50%;
top: 50%;
}
div#i>div>div {
/**
* the inner div of each img will be the same size
* as the img itself, so these 50% values refer to
* half the img width and height; move the center of
* this inner div to upper-left corner of outer div
*/
margin-left: -50%;
margin-top: -50%;
display: inline-block;
}
div#i>div>div>img {
/**
* this plus the above inline-block style will
* vertically center img within the inner div
* (normally it's baseline-aligned)
*/
vertical-align: middle;
}
</style>
</head>
<body>
<div id="i">
<div>
<div>
<img src="a.png">
</div>
</div>
<div>
<div>
<img src="b.png">
</div>
</div>
<div>
<div>
<img src="c.png">
</div>
</div>
<!--
etc.
-->
</div>
</body>
</html>
相關問題
- 1. 在CSS中居中放置一個框
- 2. 在ListBox.ItemTemplate中居中放置一個TextBlock
- 3. 在Android的另一個視圖中居中放置一個TextView相對佈局
- 4. 如何在Flutter中居中放置一個ListTile的標題
- 5. 如何讓一個div在另一個div中水平居中?
- 6. 如何在一個div中垂直居中放置一個標籤?
- 7. 如何在一個固定div中居中放置一個絕對div
- 8. 水平居中一個元素,並在其右側放置另一個元素
- 9. 如何放置一個橢圓形UITextField
- 10. 如何在屏幕上居中放置一個JDialog?
- 11. 在一個div中居中放置一段文本
- 12. 放置一個圖像下一個居中的表
- 13. 居中在另一個div內的div
- 14. 在一條線內居中放置一個字形圖標
- 15. 如何將兩個按鈕居中放在一個頁面上
- 16. 將div放在頂部並居中在另一個div內?
- 17. 如何居中一個JqGrid
- 18. 如何在另一個SVG文件中居中並縮放SVG文件
- 19. 如何在asp.net MVC的另一個視圖中放置一個視圖?
- 20. 如何在另一個表單上放置一個表單?
- 21. 在同一行中的兩個文本一個對齊而另一個居中
- 22. 放在另一個一個
- 23. 在畫框中居中放置一個矩形文字
- 24. 在頁腳中居中放置一個元素?
- 25. 在Highcharts條形圖中居中放置一個數據標籤
- 26. 在CSS中居中放置一個DIV元素
- 27. 在DockLayoutPanel中居中放置一個小部件
- 28. 在手風琴面板中居中放置一個自舉表
- 29. 如何在同一個MPMoviePlayerController中播放另一個視頻?
- 30. 如何將一個值放在另一個列表中?
哪個版本的CSS? – dnagirl 2009-10-26 17:00:16
最新版本!無所謂我會將我的版本更改爲您的答案!hehehehe – thikonom 2009-10-26 17:25:23