简体   繁体   English

div定位,高度为100%

[英]div positioning with 100% height

I want to have this layout like this 我想要这样的布局

在此处输入图片说明

The nav should be fixed and the height of the div with the background-image 100%. 导航应固定,并且带有背景图像的div的高度为100%。 Below the image I want to add the content. 在图像下方,我要添加内容。

My problem is - when i set the div of the image positioning 'relative' then i cant set the hight to 100% 我的问题是-当我将图像定位的div设置为“相对”时,我无法将hight设置为100%

 .container ul { margin-left: 50px; } .nav { background-color: #D3D3D3; height: 40px; position: fixed; width: 100%; z-index: 1; opacity: 0.6; } .nav li { display: inline; } a { color: white; text-transform: uppercase; text-decoration: none; padding-left: 20px; font-family: "Comic Sans MS", "Comic Sans", cursive; font-weight: bold; } .jumbotron { background-size: cover; background-image: url('http://www.apothekenkurier.de/uploads/pics/haut.rg.jpg'); position: relative; width: 100%; height: 100%; } .content { height: 100px; background-color: gray; } 
 <div class="nav"> <div class="container"> <ul class="pull-left"> <li><a href="#">Link 1</a></li> <li><a href="#">Link 2</a></li> <li><a href="#">Link 3</a></li> <li><a href="#">Link 4</a></li> </ul> </div> </div> <div class="jumbotron"> </div> <div class="content"> </div> 

Image Ratio with Padding 带填充的图像比例

I think this is what you are looking for 我想这就是你要找的

.jumbotron {
  background-size: cover;
  background-image: url('http://www.apothekenkurier.de/uploads/pics/haut.rg.jpg');
  position: relative;
  width: 100%;
  height: 0; /* Changed */
  padding-bottom: 75%; /* height:width ratio */
}

Responsive elements that retain their aspect ratio 保持纵横比的响应式元素

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

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