简体   繁体   English

细分父div高度以用于子div

[英]segmenting parent div height to use for child divs

I have a div with an specific height. 我有一个特定高度的div。 i want this: i put some nested div's inside this div an tell them use specific percentage of height of the parent div. 我想要这个:我在此div内放了一些嵌套div's div,并告诉他们使用父div高度的特定百分比。 for example: div1=10%, div2=50% and div3=40% . 例如: div1=10%, div2=50% and div3=40% Im talking about height. 我在谈论身高。

Im using bootstrap and i can control location of parts of a row via col-* , But i want this for height of a parent div. 即时通讯使用引导程序,我可以通过col-*来控制行的各个部分的位置,但是我希望这是父级div的高度。 How i can achieve this via Bootstrap? 我如何通过Bootstrap实现这一目标?

<div id="parent" stele="height:500px;">
 <div class="child">text 1</div>
 <div class="child">text 2</div>
 <div class="child">text 3</div>
</div>

Bootstrap grid system will make it easy for you to make responsive columns, because that is a cumbersome part to handle yourself for differing screen-sizes without horizontal scrolling. Bootstrap网格系统将使您轻松创建响应列,因为这对于在不进行水平滚动的情况下处理不同的屏幕尺寸来说很麻烦。 For height, you can rely on plain CSS styles, because vertical scrolling is not a problem. 对于高度,您可以依靠普通的CSS样式,因为垂直滚动不是问题。

Whatever your use-case be, just remember that percent dimensions are always relative to an element's parent. 无论使用哪种情况,都请记住,百分比尺寸始终是相对于元素父级的。 So if you want to give an element a height of 10% you need to consider the question: 10% of what? 因此,如果要将元素的高度设置为10% ,则需要考虑以下问题: 10%是什么? .

Following snippet will hopefully make it clear to you. 希望您能听懂以下摘要。

Snippet : 片段

 .parent { height: 120px; border: 1px solid gray; } .parent div:nth-child(1) { height: 20%; background-color: #f00; } .parent div:nth-child(2) { height: 50%; background-color: #00f; } .parent div:nth-child(3) { height: 30%; background-color: #0f0; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"/> <div class="container-fluid"> <div class="row"> <div class="parent col-xs-10 col-xs-offset-1"> <div class="child">text 1</div> <div class="child">text 2</div> <div class="child">text 3</div> </div> </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM