[英]CSS positioning divs into content
Been doing little work on my site and currently, I'm having issues with positioning. 我在网站上做的工作很少,目前在定位方面遇到问题。 I don't know why, but my divs
seem to be out of the content for some reason. 我不知道为什么,但是我的divs
出于某种原因似乎不在内容之列。 That's how it looks: 看起来就是这样:
And the way its defined: 及其定义的方式:
float: left;
font-family: 'Josefin Sans', sans-serif;
margin: 10px;
width: 100px;
height: 100px;
background:#FFFFFFFF;
text-align: center;
display: inline;
border: solid 2px #0047b3;
font-size: 28px;
The way content is defined: 内容的定义方式:
#content { background-color:#6699ff; margin: 5px; border: 2px solid #0047b3; padding-left: 10px;}
I just want to get my created div into the content div, but somehow it doesn't work. 我只想将创建的div放入内容div中,但是以某种方式不起作用。
This is happening because of 'float: left'. 这是由于“ float:left”而发生的。 Floating an element takes it "out of the flow" of the document. 浮动元素使它“脱离文档流”。 You might have better luck by removing the float property and making them 'display: inline block'. 通过删除float属性并使它们成为“ display:inline block”,可能会更好。
you may add an extra <div class="spacer"></div>
as the last child and use 您可以添加一个额外的<div class="spacer"></div>
作为最后一个孩子并使用
.spacer {
clear:both;
}
more info can be found here How do you keep parents of floated elements from collapsing? 在这里可以找到更多信息。 如何防止浮动元素的父项崩溃?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.