Percentage of height not working for portrait screen orientation

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 06:13:48

问题


I am trying to set percentage for 2 div elements(main and header) contained in the body of html. The problem is that this is not working(the height percentages appearing are wrong) when my screen orientation is portrait. Examples dimensions i am checking are the below:

320x480

320x568

600x800

768x1024

800x1280

I use viewport resizer to check my code.

HTML code:

<body>
<header>

<div id="title">
Just a title
</div>

</header>

<main>
Main div element here
</main>

</body>

CSS code:

html, body{
    background-color:#A8F000;
    height:100%;
    }

header{
    background-color:#F80012;
    height:25%;
    }

main{
    background-color:#009E8E;
    height:70%;
    }

What is going wrong here?


回答1:


Use this: viewport

header{
    background-color:#F80012;
    height:25%;
}

Add ;




回答2:


It is working perfectly fine. Take a look at fiddle

html, body{
    background-color:#A8F000;
    height:100%;
    }

header{
    background-color:#F80012;
    height:20%;
    }

main{
    background-color:#009E8E;
    height:80%;
    }

Fiddle http://jsfiddle.net/7EEMB/



来源:https://stackoverflow.com/questions/23198237/percentage-of-height-not-working-for-portrait-screen-orientation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!