我不知道在这种情况下如何为 position: absolute
元素实现 margin-bottom
。
这是我的元素的 CSS:
font-family: FuturaRoundBold;
display: none;
position: absolute;
left: 15%;
top: -5%;
color: #000;
width: 75%;
padding: 1%;
background-color: rgba(233, 233, 233, 1);
border-radius: 30px;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
-khtml-border-radius: 30px;
z-index: 2;
感谢您的任何想法!
最佳答案
margin-bottom
只会对 absolute
ly-positioned 元素做任何事情,前提是该元素没有 top 属性。
删除 top: -5%
然后你的 margin-bottom
将起作用。
或者如评论中所述,您也可以像这样添加一个透明的 div
<div class="spacer"></div>
在你的外部div里面
.spacer {
height: 50px;
margin: 0 0 -50px 0;
/* margin: 20px 0 -50px 0; use this if you want #container to have a 'bottom padding', in this case of 20px */
background: transparent; /* you'll need this if #container's parent element has a different background from #container itself */
}
礼貌:乔伊
关于html - 位置: absolute element如何实现margin-bottom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21399705/