如何使此响应?我希望渐变和文本调整大小并保持居中,因为屏幕大小会发生变化。现在,渐变有时会重复,字体保持不变。我希望第一部分是100vh,第二部分(还没有标记)不应该有渐变。
https://codepen.io/Shalise/pen/QOwbZJ
html {
height: 100%;
margin: 0;
}
h1 {
width: 100%;
top: 50%;
left: 0;
line-height: 200px;
margin-top: -100px;
position: absolute;
text-align: center;
font-family: Raleway;
color: white;
font-size: 3em;
}
body {
background: #ff7043; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(left top, #ff7043, #ffc17); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(bottom right, #ff7043, #300032); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(bottom right, #ff7043, #300032); /* For Firefox 3.6 to 15 */
background: linear-gradient(to bottom right, #f79f79, #f7d08a); /* Standard syntax (must be last) */
}
<section id="gradient">
<h1>The Sun Will Come Out Tomorrow</h1>
</section>
答案 0 :(得分:1)
改为使用vw,所以
html, body {
height: 100vw;
margin: 0;
}
和
h1 {
width: 100%;
top: 50%;
left: 0;
line-height: 200px;
margin-top: -100px;
position: absolute;
text-align: center;
font-family: Raleway;
color: white;
font-size: 3vw;
}
当窗体在体内变窄时,停止垂直重复使用:
body{
background-repeat: no-repeat;
background-attachment: fixed;
}
以下是更新:Jsfiddle
答案 1 :(得分:0)
您应该使用position: relative;
代替position: absolute;
还要使用此代码font-size: 3vw;
答案 2 :(得分:0)
html, body {
height: 100vw;
margin: 0;
}
h1 {
width: 100%;
top: 50%;
left: 0;
line-height: 200px;
margin-top: -100px;
position: absolute;
text-align: center;
font-family: Raleway;
color: white;
font-size: 2vw;
}
body {
background: #ff7043; /* For browsers that do not support gradients */
}
#sun {
width: 100vw;
height: 100vh;
background: -webkit-linear-gradient(left top, #ff7043, #ffc17); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(bottom right, #ff7043, #300032); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(bottom right, #ff7043, #300032); /* For Firefox 3.6 to 15 */
background: linear-gradient(to bottom right, #f79f79, #f7d08a); /* Standard syntax (must be last) */
}
<section id="sun">
<h1>The Sun Will Come Out Tomorrow</h1>
</section>