我目前正在制作一个网页(使用react.js),并试图实现一个背景。我希望背景是它的全部大小,但它只是与它的div内的文本大小。下面是我目前使用的代码:app.js
<div className="header">
<h1 className="title">blah blah blah</h1>
<h4 className="greeting">blah blah blah</h4>
</div>app.css
.header {
background: url("./blah.png");
position: relative;
background-size: cover;
background-repeat: no-repeat;
outline: 0;
display: block;
text-align: center;
color: lemonchiffon;
height: 100%;
}我尝试过将height调整为100%,但是它只会使图像稍微大一些。我也想说宽度是正确的,我唯一的问题是让高度合适。
发布于 2017-05-23 14:05:57
把背景放在body上
.background {
background: url("http://images.all-free-download.com/images/graphiclarge/black_texture_texture_background_06_hd_pictures_169901.jpg");
}
.header {
position: relative;
background-size: cover;
background-repeat: no-repeat;
outline: 0;
display: block;
text-align: center;
color: lemonchiffon;
height: 100%;
}
<body class = "background">
<div class="header">
<h1 class="title">blah blah blah</h1>
<h4 class="greeting">blah blah blah</h4>
</div>
</body>https://stackoverflow.com/questions/44136884
复制相似问题