【问题标题】:Vertical align of divdiv的垂直对齐
【发布时间】:2014-04-21 23:18:41
【问题描述】:

我正在尝试创建一个简单的 html/css 图表,它必须为大于 0 的值和小于 0 的值分隔条形。 它看起来像这样:http://jsfiddle.net/km27Q/3/ 而且我坚持将顶部 div 的垂直对齐居中到底部。所以我需要类 bar 的 div 与类 graph_top 的 div 中的底部垂直对齐有人可以帮我吗? 我找了几个教程,但找不到任何可以使用百分比作为宽度值的东西。

图片说明: http://s21.postimg.org/wnjcvjism/Screenshot_from_2014_04_21_16_26_01.jpg

代码如下:

HTML

<div class="graph">
<div class="graph_top">
    <div class="lol">
<div class="bar" style="height: 1px;"></div><div class="bar" style="height: 11px;"></div>
    </div>
</div>
<div class="horizontal_line"></div>
<div class="graph_bottom">
<div class="bar2" style="height: 1px;"></div><div class="bar2" style="height: 11px;"></div>
</div>

</div>

CSS

.graph {
    width: 95%;

    height: 101px;
    border: 1px solid #aeaeae;
    background-color: #eaeaea;
}
.graph_top
{
    width: 100%;
    height: 50px;
    max-height: 50px;
    position: relative;
}
.graph_bottom
{
    width: 100%;
    height: 50px;
    max-height: 50px;
}
.horizontal_line
{
    width: 100%;
    border-bottom: 1px solid #aeaeae;
    height: 1px;
    padding: 0px;
}
.bar
{
    width: 10%;
    background-color: #aeaeae;
    float: left;
}
.bar2
{
    width: 10%;
    background-color: maroon;
    float: left;
}
.lol
{
    width: 100%;
    position:absolute;
    bottom:0; 
}

感谢您的回答。

【问题讨论】:

  • 请明智地澄清您的问题点......
  • 我编辑了描述,希望它更容易理解
  • 垂直对齐抱歉

标签: css html vertical-alignment


【解决方案1】:

http://jsfiddle.net/km27Q/15/

您只需将每个条的左侧位置移动 10%。

.graph_top {
  width: 100%;
  height: 50px;
  max-height: 50px;
  position: relative;
}
.bar{
  position:absolute;
  bottom: 0;
  width: 10%;
  background-color: #aeaeae;
}


    <div class="graph">
        <div class="graph_top">
            <div class="bar" style="height: 1px;left:0;"></div>
            <div class="bar" style="height: 11px;left: 10%;"></div>
            <div class="bar" style="height: 30px;left: 20%;"></div>
            <div class="bar" style="height: 25px;left: 30%;"></div>
            <div class="bar" style="height: 15px;left: 40%;"></div>
            <div class="bar" style="height: 6px;left: 50%;"></div>
        </div>
        <div class="horizontal_line"></div>
        <div class="graph_bottom">
            <div class="bar2" style="height: 1px;"></div>
            <div class="bar2" style="height: 11px;"></div>
        </div>
    </div>

【讨论】:

  • 是的,我有,但它仍然不是我需要的。我添加了图片解释以更好地解释问题。
  • 仔细看你的屏幕我只能把你想要的灰色条形图[1px高和11px高]放到graph_top容器的底部。占据右侧全高的第三部分是什么?还有图表?
  • 是的,该图将继续使用类似的灰色条(当然具有不同的高度)。其中有 10 个空间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-04
  • 2012-12-09
  • 2011-05-31
  • 2012-10-01
相关资源
最近更新 更多