html - 使用 div 创建垂直条

标签 html css

我正在尝试仅使用 html 和 css 创建两个水平条,如下例所示。我正在使用以下代码:

<div style="height: 150px;">
  <div style="width: 55px;float:left;">
      <div>340.8</div>
      <div style="background-color:#95111d; height: 75px;">
          &nbsp;
      </div>
  </div>
  <div style="width:55px;float:left">
      <div>340.8</div>
      <div style="background-color:#9e9e9e; height: 115px;">
          &nbsp;
      </div>
  </div>
  <br style="clear: both" />
</div>

这个问题是两个条形图都位于它们包含的 div 的顶部而不是底部,所以你会得到下面的第二个图像效果。

我有一些代码可以生成这些条的高度,所以我不能只添加顶部填充/边距来将它们推到位。有什么方法可以做到这一点,而无需诉诸 javascript 来计算边距和底部对齐吗?

enter image description here

End Result

最佳答案

这是应该完成工作的 CSS 和标记(未使用绝对定位)-

DEMO

HTML:

<div id="wraper">
  <div id="c1">
     <div id="h1">340.8</div>
      <div id="b1">
          &nbsp;
      </div>
  </div>
  <div id="c2">
      <div id="h2">340.8</div>
      <div id="b2">
          &nbsp;
      </div>
  </div>
  <br style="clear: both" />
</div>

CSS:

#wraper {
   height: 150px;
}

#c1 {
   width: 55px;
   vertical-align: bottom;
   display: inline-block;
}

#b1 {
   background-color: #95111d;
   height: 75px;
}

#c2 {
   width: 55px;
   margin-left: -4px;
   display: inline-block;
}

#b2 {
   background-color: #9e9e9e;
   height: 115px;
}

DEMO

关于html - 使用 div 创建垂直条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14036710/

相关文章:

html - 纯CSS线性渐变边框

jquery - Safari SVG 图像缩放错误?

javascript - 添加新行时在 javascript 上不工作

javascript - TheSixyOne.com 如何按比例将图像拉伸(stretch)到整页?

jquery 图像 slider 导航选项卡背景图像在 IE 中没有改变

HTML5 CSS 页面在内容中间加载,这是不需要的

html - 固定背景的透明三 Angular 形

jquery - Jquery中#的必要性是什么

html - 实现返回顶部按钮时页脚消失

html - 如何在打印模式下将某些 html 字段的值显示到表格中