[英]Center 3 div in parent div
I am trying to center 3 div into a parent div with no result. 我试图将3 div放入父div而没有结果。 Could you help me please ?
请问你能帮帮我吗 ?
HTML : HTML:
<div id="container">
<div id="left"></div>
<div id="middle"></div>
<div id="right"></div>
</div>
CSS : CSS:
#container {
text-align: center;
}
#left, #middle, #right {
width: 200px;
float: left;
background: red;
height: 90px;
}
RESULT : 结果:
Change the float:left;
改变
float:left;
to display:inline-block;
display:inline-block;
, like this: , 像这样:
#left, #middle, #right {
width: 200px;
display:inline-block;
background: red;
height: 90px;
}
Try display flex. 尝试显示flex。 You'll need to add vendor prefixes!
您需要添加供应商前缀!
#container { text-align: center; display: flex; justify-content: space-between; width: 100%; } #left, #middle, #right { width: 200px; background: red; height: 90px; }
<div id="container"> <div id="left"></div> <div id="middle"></div> <div id="right"></div> </div>
#container { text-align: center; } #left, #middle, #right { width: 200px; margin:0px auto; height: 90px; } #left { background: red; } #middle { background:blue; } #right { background: green; }
<div id="container"> <div id="left"></div> <div id="middle"></div> <div id="right"></div> </div>
Add Bootstrap CSS and have a look at this example. 添加Bootstrap CSS并查看此示例。
Here: 这里:
So 4/12=3 Panels in result. 所以4/12 = 3个小组的结果。
<div class="row">
<div class="col-md-4">left</div>
<div class="col-md-4">middle</div>
<div class="col-md-4">right</div>
</div>
Try Bootstrap it will make your life easy. 试试Bootstrap它会让你的生活变得轻松。 Here's link for the Grip System you want Bootstrap Grid System .
这里是您想要Bootstrap网格系统的Grip系统的链接。
remove float
& add display inline-block
删除
float
并添加显示inline-block
#left, #middle, #right {
width: 200px;
display:inline-block;
background: red;
height: 90px;
}
Add margin-left: auto, margin-right:auto, width: 600px
to your container. 为您的容器添加
margin-left: auto, margin-right:auto, width: 600px
。
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.