[英]Aligning contents inside a div
How to align the second div(display_bar) to the center 如何将第二个div(display_bar)对准中心
<div id="display" style="display:inline;font-size:150%;" > </div>
<div name="display_bar" id="display_bar"
style="margin-left: auto;margin-right: auto;width:125em;text-align:center;visibility=visible;display:inline;">
<img class="view_prev" src="first.png">
<img class="view_prev" src="2.png" >
<img class="view_prev" src="3.png" >
<img class="view_prev" src="4.png" >
<img class="view_prev" src="5.png" >
</div>
Also the second div should be inline with the first div 另外,第二个div应该与第一个div内联
Thanks. 谢谢。
Since it is display: inline
, set text-align: center
on its parent element and ask yourself if it should be a span instead of a div. 因为它是
display: inline
,所以将text-align: center
设置在其父元素的 text-align: center
,然后问自己是否应该是span而不是div。
(NB: CSS uses :
, not =
and the alt attribute is mandatory for img elements) (注意:CSS使用
:
,而不是=
,并且alt属性对于img元素是必需的)
Try this css: 试试这个CSS:
#display_bar
{
margin:0 auto;
width:300px; /* or whatever width */
}
You can also center an element with display: inline-block or display: inline by using text-align: center on the parent element. 您还可以通过使用text-align:在父元素上居中来将元素居中显示:inline-block或display:inline。 This will center the text inside as well.
这也将使文本居中。 I think this may be what you want, since you said you wanted to align everything to the center.
我认为这可能就是您想要的,因为您说过要使所有内容与中心对齐。 Just put it all into the div.
只需将所有内容放入div。
For example: 例如:
<div class="wraper">
<div class="inwrap">
Lorem ipsum dolor text...
</div>
</div>
CSS: CSS:
.wraper {
}
.inwrap {
width: 50%;
margin: 0 auto;
}
OR: 要么:
.wraper {
text-align: center;
}
.inwrap {
display: inline-block; /*or inline*/
width: 50%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.