English 中文(简体)
CSS div 100% 不工作
原标题:CSS div height 100% not working
  • 时间:2015-10-23 08:50:19
  •  标签:
  • html
  • css

div2为1000px高,因为四、五和四舍五入。 我不理解的是,如果四舍五入到100%的高度,那就等于零。

<div id="div1" class="center" style="width:1024px; height:auto;">
    <div id="div2" style="float:left; width:100%; height:auto;">
        <div id="div3" style="float:left; width:460px; height:100%; background-image:url(img/bgVictorMonteiro.jpg); background-size:100% auto; background-position:bottom; background-repeat:no-repeat;"></div>
        <div id="div4" style="float:left; width:270px; height:1000px;"></div>
        <div id="div5" style="float:left; width:25px; height:1000px;"></div>
        <div id="div6" style="float:left; width:269px; height:1000px;"></div>
    </div>
</div>
最佳回答

You could set the height of parent div1 to 1000px and set the children s height to :inherit. Here s an example:

#div1
{
    width:1024px;
    height:1000px;
    background:red;
    overflow:hidden;
}
#div2
{    
    float:left;
    width:100%;
    height:inherit;
    background:yellow;
}
#div3
{    
    float:left;
    width:460px;
    height:inherit;
    background-image:url( http://www.ricoh-imaging.co.jp/english/r_dc/caplio/r7/img/sample_04.jpg );
    background-size:100% 100%;
    background-position:bottom;
    background-repeat:no-repeat;
}

#div4
{
    float:left; 
    width:270px;
    height:inherit;
    background:violet;
}

#div5
{
    float:left;
    width:25px;
    height:inherit;
    background:black;
}

#div6
{
    float:left;
    width:269px;
    height:inherit;
    background:blue;
}
<div id="div1" class="center">
    <div id="div2">
        <div id="div3"></div>
        <div id="div4"></div>
        <div id="div5" ></div>
        <div id="div6"></div>
    </div>
</div>

这可能是一项工作。 我希望它能够提供帮助。

问题回答

采用百分比表示的<代码><0>/代码>,依据的是明确的<代码>h 8,。 父母要素的价值:

Specifies a percentage height. The percentage is calculated with respect to the height of the generated box s containing block. If the height of the containing block is not specified explicitly (i.e., it depends on content height), and this element is not absolutely positioned, the value computes to auto . A percentage height on the root element is relative to the initial containing block.

http://www.w3.org/TR/CSS21/visudet.html http://www.w3.org/TR/CSS21/visudet.html#the-hels-property

在这种情况下,括号为#div2,hels: auto;。 这意味着其<条码>八<>/代码>取决于其内容的<条码>,但并未明确宣布。

If you were to apply the height explicitly to #div2 (e.g. height: 1000px;) then using height: 100%; on #div3 would work.

#div1 {
    width:1024px;
    height:auto;
}
#div2 {
    float:left;
    width:100%;
    height:1000px;
}
#div3 {
    float:left;
    width:460px;
    height:100%;
    background-color: red;
}
#div4 {
    float:left;
    width:270px;
    height:1000px;
    background-color: green;
}
#div5 {
    float:left;
    width:25px;
    height:1000px;
    background-color: blue;
}
#div6 {
    float:left;
    width:269px;
    height:1000px;
    background-color: orange;
}
<div id="div1">
    <div id="div2">
        <div id="div3"></div>
        <div id="div4"></div>
        <div id="div5"></div>
        <div id="div6"></div>
    </div>
</div>

确保<代码>#div3的可能途径 不用在<代码>#div2上明确列出的,即可使用<代码>flex Box

#div1 {
    width:1024px;
    height:auto;
}
#div2 {
    float:left;
    width:100%;
    height:auto;
    display: flex;
}
#div3 {
    width:460px;
    background-color: red;
}
#div4 {
    width:270px;
    height:1000px;
    background-color: green;
}
#div5 {
    width:25px;
    height:1000px;
    background-color: blue;
}
#div6 {
    width:269px;
    height:1000px;
    background-color: orange;
}
<div id="div1">
    <div id="div2">
        <div id="div3"></div>
        <div id="div4"></div>
        <div id="div5"></div>
        <div id="div6"></div>
    </div>
</div>

问题的根源在于,如果父母四分之四高50px,则四分之以百分之四的四分之四将意味着其高50px,但父母四分之四具有高的汽车,以达到以下任何高点:

Simple solution for the new green browsers. Answer is -webkit-fill-available


#div3 {
        min-height: -moz-available;
        min-height: -webkit-fill-available;
        min-height: fill-available;
    }




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!