html - 位置: absolute element如何实现margin-bottom

标签 html css

我不知道在这种情况下如何为 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;

感谢您的任何想法!

enter image description here

最佳答案

margin-bottom 只会对 absolutely-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/

相关文章:

html - 如何删除 Bootstrap 中不同列中两个 div 之间的空间

html - 无法使用 css、html 在正确的位置对齐 div

javascript - YouTube iframe 嵌入在 Internet Explorer 8 中抛出 JavaScript 错误

html - 我正在尝试设计一个带有多种 css 颜色的标题。仅从颜色

html - 美化本地链接不正确

css - 有没有办法用 CSS 选择多个输入字段类型?

html - 如何使单击按钮的效果持续 0.5 秒?

html - Django 在现场编辑静态内容

html - 填充 HTML/CSS 中的额外空间

css - 溢出:以可变的 100% 宽度隐藏