对齐顶部的内嵌块元素
如何让两个(或多个)浮动div看起来像“大按钮”,并让它们浮动并变平?我的问题是这些盒子“部分被夷为平地”......其中一个比另一个略低。我试图在adminBox上使用float: left
,但随后他们在容器外生长。谁能帮我?对齐顶部的内嵌块元素
我已经使用这个HTML代码: (http://jsfiddle.net/jf936/13/)
<div class="container">
<div class="adminBox">
<h2>Manage users</h2>
<div class="adminBoxLargeContent" data-bind="text: usersCount"></div>
<div class="adminBoxSmallContent">Registered users</div>
</div>
<div class="adminBox">
<h2>Manage templates</h2>
<div class="adminBoxLargeContent" data-bind="text: templateCount"></div>
</div>
而这种风格:
.container{
background-color: light-blue;
}
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: inline-block;
margin: 5px;
}
.adminBox h2{
color:white;
font-size:20px;
text-align:center;
}
.adminBoxLargeContent{
font-size: 70px;
text-align:center;
padding: 0;
margin: 0;
line-height: 1;
}
.adminBox .adminBoxSmallContent{
float: none;
text-align:center;
}
这有什么好做,问题是,你正在使用float
display: inline-block;
,因此元件排列基线,序来解决这个问题,你需要使用vertical-align: top;
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: inline-block;
margin: 5px;
vertical-align: top; /* Add this here */
}
注意:您不必使用float: none;
,因为这里没有任何东西在浮动,所以您可以摆脱那些未使用的属性。
谢谢Mr.Alien – thomas
@thomas欢迎:) –
也许这个代码将有助于你: jsfiddle
.container{
background-color: light-blue;
overflow:hidden;
}
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: block;
margin: 5px;
float:left;
}
.adminBox h2{
color:white;
font-size:20px;
text-align:center;
}
.adminBoxLargeContent{
font-size: 70px;
text-align:center;
padding: 0;
margin: 0;
line-height: 1;
}
.adminBox .adminBoxSmallContent{
text-align:center;
}
<div class="container">
<div class="adminBox">
<h2>Manage users</h2>
<div class="adminBoxLargeContent" data-bind="text: usersCount"></div>
<div class="adminBoxSmallContent">Registered users</div>
</div>
<div class="adminBox">
<h2>Manage templates</h2>
<div class="adminBoxLargeContent" data-bind="text: templateCount"></div>
</div>
</div>
你在这里。
CSS代码变化:
.adminBox{
height: 200px;
width: 200px;
background-color: green;
color: white;
border-radius: 7px;
padding: 7px;
display: inline-block;
margin: 5px;
float:left;
}
希望这有助于。
你可以提供一个jsfiddle链接的代码问题? – Nitesh
哦..从来没有这样做过.. – thomas
得到www.jsfiddle.net粘贴你的代码和ctrl + s这就是它 - @thomas – Nitesh