html - TranslateY 不会超出 CSS 中的某个边界
问题描述
所以我试图创建一个登陆页面,当页面加载时,页面的标题会从顶部和侧面滑出。我知道基本工作,但我似乎无法将标题放在某个位置,以便在页面加载时它会回到原来的位置。我还没有实现 Javascript 但这里是其余的代码::
HTML
<body onload="slide()">
<main>
<section class="landing">
<h1>Find Your Perfect Vacation Point</h1>
<h3>Let us do the finding for your!</h3>
</section>
</main>
<script src="script.js"></script>
</body>
CSS
*{
padding: 0px;
margin: 0px;
overflow-x: hidden;
font-family: Open Sans;
}
.landing{
background-image: url("bali.jpg");
width: 100%;
height: 80%;
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center center;
background-size: cover;
opacity: .9;
}
.heading-container{
height: 100%;
width: 100%;
margin-top: 10%;
text-align: center;
}
h1{
font-weight: bold;
color: white;
margin:20px;
font-size: xx-large;
text-align: center;
position: relative;
top: 20%;
transform: translateY(-38%);
}
h3{
font-weight: lighter;
color: white;
margin:20px;
text-align: center;
position: relative;
top: 20%;
}
感谢您提前帮助我!
PS:对不起,如果我没有很好地解释我的问题。即使是一个简单的问题,也很难描述一个问题。
解决方案
您可以使用CSS 动画来做到这一点。这是您所描述的示例:
@keyframes slide-from-above {
from { transform: translate(0, -30px); color: blue }
to { transform: translate(0, 0); color: red }
}
.nav {
animation-name: slide-from-above;
animation-duration: 4s;
animation-iteration-count: 1;
animation-direction: forwards;
animation-fill-mode: backwards;
display: inline-block;
}
#nav1 {
animation-delay: 0;
}
#nav2 {
animation-delay: 1s;
}
#nav3 {
animation-delay: 2s;
}
#nav4 {
animation-delay: 3s;
}
<div id="header">
<div class="nav" id="nav1">Home</div>
◆
<div class="nav" id="nav2">About</div>
◆
<div class="nav" id="nav3">Contact</div>
◆
<div class="nav" id="nav4">Support</div>
</div>
推荐阅读
- node.js - 推荐node中最好的pdf生成包
- python - Python - Spark - RDD 日期转换
- angular - 角度改变 scss 对象变量
- python - 将 2 个列表的字符串表示形式转换为列表
- graph - 将鼠标悬停在数据点上但在其下方某处时未显示 Google 图表工具提示。为什么?
- java - 在java中恢复线程
- sass - 如何在 SaSS/CSS 中为单行禁用更漂亮
- c# - 如果我在 xamarin 表单后面的代码中编写代码,为什么我的视图不可见?
- css - 如何在 Magento 2.2.6 中实现我用 Bootsrap 3.3.7 制作的自定义菜单?
- r - 改变传说的顺序以获得多种美学