[英]Cant center an image inside of a div?
So basically, I am trying to center a div with an image inside of a div with left and right divs and the middle div won't center. 所以基本上,我正在尝试将div的图像居中放置在具有左右div的div内,而中间div不会居中。 I have tried positioning absolute and setting
left:0
and right:0
我尝试定位绝对并设置
left:0
和right:0
here is the structure of the html logoLeft is float:left
and logoRight is float:right
. 这是html的结构logoLeft是
float:left
而logoRight是float:right
。
Thank you. 谢谢。
First of all, I added an external div to align the items 首先,我添加了一个外部div来对齐项目
<div class="flex">
<div class="logoLeft"></div>
<div></div>
<div class="logoRight"></div>
</div>
In css we do the magic 在CSS中,我们做魔术
.flex{
display: flex;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
justify-content: space-between;
-webkit-justify-content: space-between;
}
You could also use display: table
with a container : 您还可以使用
display: table
带容器的display: table
:
<div class="table">
<div class="logoLeft"></div>
<div></div>
<div class="logoRight"></div>
</div>
and the CSS : 和CSS:
.table {
display: table;
}
.table > div {
display: table-cell;
text-align: center;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.