По какой-то причине мой div
не набирает высоту, когда я применяю .section {height: 100%;}
, но когда я даю ему атрибут height
в пикселях, он работает. Идея заключается в том, что я хочу, чтобы div
использовал окно браузеров, поэтому div
будет охватывать весь раздел браузера независимо от разрешения экрана.
http://jsfiddle.net/marrto/npe2y/
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title> 10 </title>
<!-- Slidebars CSS -->
<link href="css/mystyle.css" rel="stylesheet" text="text/css" >
</head>
<body>
<!-- MAIN AREA -->
<!-- WRAPPER - WRAPPS NAVIGATION AND LOGO-->
<div id="wrapper">
<div id="header">
<div class="logo">
<a href="index.html"> <img src="logo.png" alt="Logo"> </a>
</div>
<div class="navBar">
<ul id="nav">
<li><a href="#topbar">Homepage</a></li>
<li><a href="#about">About</a></li>
<li><a href="#photos">Photos</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
<div style="clear: both;"> </div>
</div>
</div>
<!-- WRAPPER END -->
<div id="topbar" class="section">
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div id="about" class="section">
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div id="photos" class="section">
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div id="contact" class="section">
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<!-- WRAPPER - WRAPPS NAVIGATION AND LOGO-->
<div id="container">
<div id="footer">
<div class="legal">
text
</div>
<div class="site">
Text
</div>
<div style="clear: both;"> </div>
</div>
</div>
<!-- WRAPPER END -->
</body>
</html>
body { /* general font size, family and color */
font-family: Arial, Helvetica, sans-serif;
font-size: .9em;
color: #343434;
margin: 0;
padding: 0;
}
.sb-toggle-left {
display: none;
}
#wrapper { /* wrapps logo and the navigation links */
background-color: #ffffff;
height: 60px;
width: 100%;
top: 0;
left: 0px;
position: relative;
z-index: 99;
-moz-box-shadow: 0 0 3px 0 #ccc;
-webkit-box-shadow: 0 0 3px 0 #ccc;
box-shadow: 0 0 3px 0 #ccc;
}
.section:nth-child(odd) {
background-color: #b1d994;
}
.section:nth-child(even) {
background-color: #5bc473;
}
.section {
height: 100%;
padding: 5%;
}
.content {
width: 60%;
margin-right: auto;
margin-left: auto;
text-align: justify;
}
/*
#topbar {
background-image: url('banner.jpg');
}
*/
#header {
width: 60%;
position:relative;
margin-left: auto;
margin-right: auto;
min-width: 600px;
}
.logo {
float: left;
padding-top: .9em;
}
.navBar {
float: right;
padding-top: 1.3em;
}
.navBar ul {
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
.navBar li {
float:left;
}
.navBar a:link, .navBar a:visited {
display: block;
color:#4a4949;
padding:4px;
text-decoration:none;
text-transform:uppercase;
font-size: 0.8em;
}
.navBar a:hover {
color:#ababab;
}
#container { /* wrapps logo and the navigation links */
background-color: #ffffff;
height: 60px;
width: 100%;
top: 0;
left: 0px;
-moz-box-shadow: 0 0 3px 0 #ccc;
-webkit-box-shadow: 0 0 3px 0 #ccc;
box-shadow: 0 0 3px 0 #ccc;
}
#footer {
width: 60%;
position:relative;
margin-left: auto;
margin-right: auto;
}
.legal {
float: left;
padding-top: 1.3em;
}
.site {
float: right;
padding-top: 1.3em;
}
Если родительский элемент не имеет значения высоты, установленного явно,% height в нем не будет работать...
в вашем случае родительский элемент divs, имеющий section
класса, <body>
, который не имеет установленной высоты.
ЗДЕСЬ.
Я просто изменил 100% с 100vh
.section {
height: 100vh;
padding: 5%;
}
vh
далеко не выдающаяся.
Вам нужно установить следующий css:
html,body{
height:100%;}
вы можете сделать это, используя js
element = document.getElementsByClassName("section");
for(element in ele){
ele.style.width=screen.width+"px";
}
если ширина будет зафиксирована, высота не изменится