CSS: 图像有固定高度 header
CSS: have a fixed height for image header
我有一个 header 样式如下:
header {
position: relative;
width: 100%;
height:50%;
color: #fff;
background-image: url(../images/header.jpg);
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
这会填满整个屏幕,我怎样才能使它的高度固定(以像素为单位)?
将高度更改为px;而不是 %
如果我理解问题
如 Acrux 所说,将高度更改为 px 而不是 %,并将这些行添加到您的代码中:
header {
overflow: hidden;
}
或者您可以尝试通过添加以下行将 Div 更改为显示块:
header {
display:block;
}
我有一个 header 样式如下:
header {
position: relative;
width: 100%;
height:50%;
color: #fff;
background-image: url(../images/header.jpg);
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
这会填满整个屏幕,我怎样才能使它的高度固定(以像素为单位)?
将高度更改为px;而不是 %
如果我理解问题
如 Acrux 所说,将高度更改为 px 而不是 %,并将这些行添加到您的代码中:
header {
overflow: hidden;
}
或者您可以尝试通过添加以下行将 Div 更改为显示块:
header {
display:block;
}