html - 如何将子 div 设置为父级的高度(100%)?

标签 html css twitter-bootstrap

这是他们的页面布局 enter image description here 这是这个的代码

<div class="newsContent row">
    <div class="newsDate col-md-2">05 August 2014</div>
    <div class="newsSeparator col-md-1">
    </div>
    <div class="newsDescription col-md-7">
        <div class="row">
            some dummy news
            <div class="newsImage"><img alt="news2" src="/Images/News/news2.jpg">
            </div>
        </div>
    </div>
    <div class="newsActions col-md-2">
        <div class="row">
            <div class="col-md-4">
                <button type="button" class="btn btn-default btn-lg edit-content" title="Edit the news" <span class="glyphicon glyphicon-pencil">
                    </span>
                </button>
            </div>
            <div class="col-md-4">
                <button type="button" class="btn btn-default btn-lg delete-content" title="Delete the news">
                    <span class="glyphicon glyphicon-trash"></span>
                </button>
            </div>
        </div>

    </div>
</div>

现在你可以看到这条绿线就是这部分

<div class="newsSeparator col-md-1">
</div>

类是

.newsSeparator
{
    background: url('my_1X1_pixel_image.png');
    background-repeat: repeat-y;
}

但它不是重复的。我只看到一个 1px 的图像,而不是这条想要的绿线。像这样。

enter image description here

为什么在我设置了 background-repeat: repeat-y; 之后它没有在 y 方向重复。我如何使它像沿 y 重复的所需行一样,并根据父 div 和新闻内容相应地拉伸(stretch)/调整大小?

编辑 这不是 that 的副本.我有需要沿 y 轴重复的背景图像。

最佳答案

您可以将新闻描述和图像包装到一个 <article> 中元素

然后你可以分配一个border-left到新插入的元素。这样做可以避免将空标记仅用于样式目的,还可以改善页面的语义。

<article>
    <div class="newsDescription col-md-7">
        <div class="row">
           ...
        </div>
    </div>
    <div class="newsActions col-md-2">
        <div class="row">
           ...
        </div>
    </div>
</article>

CSS

article {
   border-left: 1px green solid;
   padding-left: ...  /* give some space between border and contents */
}

关于html - 如何将子 div 设置为父级的高度(100%)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28628304/

相关文章:

css - 如何访问 shinyapps.io 上应用程序的 R+Shiny 代码?

javascript - 从 Controller 动态添加类

php - 如何在结帐页面中删除送货地址和送货方式-opencart2

javascript - 使用 jquery 中的悬停获取要在各个 div 中显示的内容

html - 如何覆盖 CSS 以更改 Bootstrap 的 <th>

jquery - 在鼠标悬停时淡入淡出 ul 菜单元素

HTML5 在 &lt;input&gt; 中用鼠标在可拖动的 div 上选择文本

jquery - 如何通过jQuery在PC和移动设备上加载CSS?

javascript - 如何使用javascript将图像加载到bootstrap modal

html - 页脚社交图标在调整大小时不会均匀间隔