div內控制項居中
① 怎麼讓div裡面的div居中顯示
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<style>
*{margin:0;padding:0;}
.body{width:960px;margin:0 auto;}
.div1{ border:#000000 solid 1px;width:300px;height:300px;margin:0 auto;}
.div1_div1{border:#CC0000 solid 1px;width:100px;height:100px;margin:100px auto;}
</style>
</head>
<body>
<div class="div1">
<div class="div1_div1 clear">div1_div1</div>
</div>
</body>
通過margin:0 auto; 可以實現居中內 如果還要上下居中 就要算容px了
運行效果
② 怎麼樣div裡面的div一直居中顯示
你的居中是指水平居中,還是垂直居中?
水平居中:div設置:text-align:center;
img設置:專width:圖片寬度屬;
margin:0
auto;
垂直居中:div設置:position:relative;
img設置:position:absolute;
top:50%;
height:圖片高度;
margin-top:圖片高度的一半;
③ 怎樣讓一個div中div水平居中
<div style="width:200px; height:150px; background:red; padding-top:50px;">
<div style="width:100px; height:100px; background:white; margin:0px auto"></div>
</div>有一點要注意,內部標簽加margin:0px
auto即可水平居中,但是標簽必須設置內寬度容才有效,如果內部標簽需要自動伸展寬度又要水平居中,那麼div不太好辦到,不妨使用table來實現,舉例如下:
<div style="width:200px; height:150px; background:red; padding-top:50px;">
<table border="0" cellpadding="0" cellspacing="0" style="margin:0px auto">
<tr>
<td style="height:100px; background:white;">11111</td>
</tr>
</table>
</div>
④ 如何讓一個控制項(或一行文字)在一個DIV中垂直居中
使文字在div中水平來和垂直居中源的的css樣式為
1
2
text-align:center; /*水平居中*/
line-height: 20px; /*行距設為與div高度一致*/
示例如下:
HTML元素
1
<div>水平垂直居中</div>
css樣式
1
2
3
4
5
6
7
div{
width:200px;height:200px; /*設置div的大小*/
border:1px solid green; /*邊框*/
text-align: center; /*文字水平居中對齊*/
line-height: 200px; /*設置文字行距等於div的高度*/
overflow:hidden;
}
顯示效果
⑤ div裡面的div怎麼設置居中
div區域塊兒設置
<style>
.maxdiv{width:100px;height:50px;background:#F30;}
.mindiv{width:60px;height:50px;background:#09F;margin:0auto;}
</style>
<divclass="maxdiv">
<divclass="mindiv"></div>
</div>
頁面中實現的效果:
主要標簽:margin:0 auto; 設置小div 上下間距0px 左右居中;
希望我內的回答對你有所幫容助,如果還有其他疑問,請繼續追問我;
⑥ css中如何讓div中的文本框居中
1、打開Dreamweaver cc 2014軟體,選擇建立html界面,裡面自動生成一些必要代碼的代碼格式,節省時間回。
⑦ 如何讓DIV標簽居中顯示
|右可以這么考慮!text-align:center|left|right;這個是內容居中|左|右內
如果想DIV居中|左|右的話:
DIV居中:給div設置一個容寬度,然後margin:0auto;
DIV居左和居右可以用float:left|right;
⑧ 我在<td>里放了個<div>,如何讓div中的控制項居中
在設置居中屬性的時候通抄常是align關鍵字,垂直的話是vertical-align,但是通常情況下 要實現垂直居中 還要緊跟著行高屬性也就是line-height,通過這個屬性 你可以將控制項在區域中放置在任意位置。假如你要居中的話,舉個例子:line-height:5px,它的意思就是說你要放置的控制項離各邊相距了5px這么一個距離。。
⑨ 在HTML中怎麼讓div里的東西上下居中
設置浮動。
首先,先給一個大的div作為父容器.給他設置好寬,高。
父容器設置為內position:relative
子容器(想容要居中的容器),設置position:absolute; 在設置margin-top,margin-right等等,如果想要絕對居中,可設置如下CSS樣式。
.Center-Container{
position:relative;
}
.Absolute-Center{
width:50%;
height:50%;
overflow:auto;
margin:auto0;
position:absolute;
}
- 本問題關鍵處為,父子容器之間的關系。
5拓展部分:對於HTML5來說,有一種盒模型也可解決問題。簡單,易懂。
⑩ 讓div中的內容水平居中顯示
<style type="text/css">
#cc{
width:120px;
margin:0 auto;
}
</style>
</head>
<body>
<div id ="cc">
<div style="float:left; margin-top:0px;_margin-top:0px;padding-left:10px;width:120px;height:60px;">
<img style="float:left;" src="images/.png"/>
<div style="width:50px;float:left;line-height:15px;margin-top:2px;padding-left:5px;text-align:left;">
<span style="color: #747475; font-size: 14px; font-family:; font-weight: bold;"Microsoft YaHei",微軟雅黑;">網路</span>
<span style="font-size:12px;color:#6d6b6b;"></span>
</div>
</div>
</div>
</body>
</html>