我创建了一个固定在页面底部的页脚,但问题是它紧跟在我最后一张图片之后,所以它们之间没有间距。我想在最后一张图片和页脚之间留出空间,所以我认为创建基于 % 的边距是一个很好的解决方案。但是,我不得不使用 margin-bottom:180%
,这对我来说似乎很草率,并且在调整窗口大小时会出现问题。我的代码本质上是(删除了额外的图像以防止困惑):
<body>
<div id='wrapper'>
<section class='gallery-set'>
<div class='wrap'>
<img class='tilesetsmall' src ='images/sample.jpg'/>
<div class='ontop'><p class='example-text'>Overlay Test text </p></div>
</div>
</section>
</div>
<div id="footer">
</div>
</body>
所以我的目标是在页脚和其余内容之间创建一个空间。
最佳答案
如果您不介意静态,请尝试使用px
。如果你想更动态一点,尝试使用 em
margin-bottom: 30px;
margin-bottom: 5em;
http://www.w3schools.com/cssref/css_units.asp
1em is equal to the current font size. 2em means 2 times the size of the current font.
E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a
very useful unit in CSS, since it can adapt automatically to the font that the reader uses
关于css - 替代主体和页脚之间间距的百分比边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25006759/