如何将 div
的高度设置为与另一个只有 CSS 文本的 div
相同?
例如我有一个 div,它的 max-width
是 10px 并且它包含文本
- CSS 是最著名的网页设计编程语言之一
还有另一个 max-width
也是 10px 的 div。
<div style="max-width:10px">CSS is one of the most famous Programming Language to design webpages</div>
<div style="max-width:10px"></div>
我想要的是将第二个 div 的高度设置为等于第一个 Div 相对于内容的高度。如果 div 有更多或更少的文本,它可以由它调整。
我的 fiddle :http://jsfiddle.net/p38hmoz0/
注意:我不能为此目的使用 jquery 或 javascript,因为我很难将它添加到聚合物中,因为它使用影子 dom。**
最佳答案
既然你说你可以让第二个 div
作为第一个 div
的 child :
演示: http://jsfiddle.net/p38hmoz0/6/
HTML:
<div class="parent">
CSS is one of the most famous Programming Languages to design webpages
<div></div>
</div>
CSS:
div.parent {
position: relative;
max-width: 10px;
}
div.parent > div {
max-width: 10px;
position: absolute;
top: 100%;
left: 0;
height: 100%;
border: 1px solid #0ff; /* for demo purposes */
}
关于html - 设置与其他 div 相同的 div 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28413613/