html - 如何在绝对定位元素之间应用水平空间

标签 html css

我创建了一组四个 div 标签,background-color 为黄色,并指定了 widthheight 然后我将其位置设置为 absolute 并将 bottom 设置为 0px ,如下面的代码所示:

 #votingmeter {
    width:25em;
    height:20em;
    background-color:black;
}

 .voteindex {
    width:2em;
    height:8em;
    background-color:yellow;
    float:left;
    position:absolute;
    bottom:0;
    margin:2em;
}
<div id="votingmeter"> 

 <div class="voteindex"></div>
 <div class="voteindex"></div>
 <div class="voteindex"></div>
 <div class="voteindex"></div>

</div>

(请参阅.votingindex)

但问题是 .votingindex 元素重叠。我希望在每个 div 元素之间应用一些空间。

谁能建议我一个方法吗?

此外,我希望黄色 div(.voteindex) 留在黑色 div (#votingmeter) 内。

最佳答案

用绝对位置将 .voteindex div 包裹在 div 中。

 #votingmeter {  width:25em;height:20em;background-color:black; position: relative; }

 .voteindex { width:2em;height:8em;
             background-color:yellow;float:left;
             margin:2em;}
 .bottom {
   position:absolute;bottom:0;
 }
<body>

<div id="votingmeter"> 
 <div class="bottom">
  <div class="voteindex"></div>
  <div class="voteindex"></div>
  <div class="voteindex"></div>
  <div class="voteindex"></div>
 </div>

</div>
  
</body>

关于html - 如何在绝对定位元素之间应用水平空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29713657/

相关文章:

javascript - <select> 中 HTML <option> 中的样式子字符串

html - 除了 <button> 之外,还有哪些 <tag> 可以用来触发 AJAX?

javascript - 如何检测对象是否位于 Canvas 元素的坐标处?

jquery - Css强制按钮位于绝对div的底部

javascript - 如何在客户端扩大选择范围

html - flex child 从 parent 那里长大

javascript - 改变jquery的Supersized插件的高度和宽度

javascript - 表格宽度超过容器 div

javascript - 将 CSS 转换为不同的格式 (JavaScript/jQuery)

javascript - iOS 8 滚动时背景图像闪烁问题