好的,所以我创建了使用视差滚动的图像。
代码是:
<head><style>
/*Parallax*/
.hpimg1 {
/* Set a specific height */
height: 540px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
padding-left: 0px;
}
.hpimg1
{ /* The image used */
background-image: url("bg.jpg");
}
.welcome
{
height: 200px;
background-color: #fff;
word-wrap: normal;
word-break: keep-all;
font-family: 'Montserrat';
font-weight: 700;
font-size: 31px;
line-height: 1.125em;
margin-right: 0;
margin-left: 0;
margin-bottom: 0;
box-sizing: border-box;
top: 300px;
}
h5
{
color:white;
top: 300px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
text-transform: uppercase;
padding-bottom: 38px;
-webkit-margin-before:0.67em;
-webkit-margin-after:0.67em;
-webkit-margin-start:0px;
-webkit-margin-end:0px;
-webkit-tap-highlight-colour:rgba(0,0,0,0);
-webkit-font-smoothing:antialiased;
-webkit-box-direction:normal;
}
h5:after, h5:before
{
content: '';
width: 50px;
height: 2px;
background: black;
margin: 0 10px;
}</style
</head>
<body>
<div class="hpimg1"><div class="Welcome"><h5>Welcome to RyanTeaches</h5></div></div>
</body
问题是由于某种原因,我的消息“欢迎使用RyanTeaches”停留在导航栏后面的页面顶部。 (仅包含有关视差滚动和消息的相关代码)
我尝试了很多事情,例如top:300;,margin-top,padding-top等,尝试将此消息向下移动,但它坚持要保留在页面顶部(隐藏在导航栏后面)。
另外,当我尝试将代码移动到.css样式表时,视差图像隐藏在所有内容的后面,并且在屏幕上不可见?
新编码器-任何帮助将不胜感激!
干杯
最佳答案
您可以向.Welcome
添加一些flexbox属性:
/*Parallax*/
.hpimg1 {
/* Set a specific height */
height: 540px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
padding-left: 0px;
}
.hpimg1 {
/* The image used */
background-image: url("https://placehold.it/200x200");
}
.welcome {
height: 200px;
background-color: #fff;
word-wrap: normal;
word-break: keep-all;
font-family: 'Montserrat';
font-weight: 700;
font-size: 31px;
line-height: 1.125em;
margin-right: 0;
margin-left: 0;
margin-bottom: 0;
box-sizing: border-box;
top: 300px;
}
.Welcome {
display: flex;
height: 100%;
align-items: center;
justify-content: center;
}
h5 {
color: white;
top: 300px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
text-transform: uppercase;
padding-bottom: 38px;
-webkit-margin-before: 0.67em;
-webkit-margin-after: 0.67em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-tap-highlight-colour: rgba(0, 0, 0, 0);
-webkit-font-smoothing: antialiased;
-webkit-box-direction: normal;
}
h5:after,
h5:before {
content: '';
width: 50px;
height: 2px;
background: black;
margin: 0 10px;
}
<body>
<div class="hpimg1">
<div class="Welcome">
<h5>Welcome to RyanTeaches</h5>
</div>
</div>
</body>
关于html - 在视差图像上书写文字,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44930082/