gpt4 book ai didi

html - div 顶部和包装器之间的奇怪间隙

转载 作者:可可西里 更新时间:2023-11-01 15:01:17 25 4
gpt4 key购买 nike

任何人都可以帮助解决“arrow wrapper 2”div 和“about”div 之间的奇怪差距,因为我不明白为什么它在那里以及它来自哪里。因为我需要“关于”div 底部的箭头,但我不能使用 absolute,因为那样会把一切搞砸。所以我尝试制作一个包装器,但奇怪的是它不是 div 的 100vh。任何帮助都会很棒!!

@import url('https://fonts.googleapis.com/css?family=Josefin+Sans');
@import "compass/css3";
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
font-family: 'Josefin Sans', sans-serif;
}


#main{
width:100%;
height:100vh;
background:#ED4C67;
text-align: center;
display: block;
}
/* Typewriter */
.typewrite{
color:#fff;
text-decoration:none;
font-family: 'Josefin Sans', sans-serif;
font-size:60px;
display:block;
}

/* arrow */
@-moz-keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-moz-transform: translateY(0);
transform: translateY(0);
}
40% {
-moz-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-moz-transform: translateY(-15px);
transform: translateY(-15px);
}
}
@-webkit-keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-webkit-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-webkit-transform: translateY(-15px);
transform: translateY(-15px);
}
}
@keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-webkit-transform: translateY(0);
transform: translateY(0);
}
40% {
-moz-transform: translateY(-30px);
-ms-transform: translateY(-30px);
-webkit-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-moz-transform: translateY(-15px);
-ms-transform: translateY(-15px);
-webkit-transform: translateY(-15px);
transform: translateY(-15px);
}
}

i {
display: block;
color: #fff;
}
.arrow {
position: absolute;
bottom: 20px;
left: 50%;
margin-left: -20px;
width: 40px;
height: 60px;
}

.bounce {
-moz-animation: bounce 2s infinite;
-webkit-animation: bounce 2s infinite;
animation: bounce 2s infinite;
}
#about {
width:100%;
height:100vh;
background: white;
display:block;

}



.wrapper {
height: 100%;
vertical-align: middle;
display: table-cell;
text-align: center;
}

.skull {
width:50%;
float:left;
}

.about_para {
display:block;
color:#ED4C67;
font-size:40px;
}

@media only screen and (max-width: 700px) {

}

.vertical-center {
position: relative;
top:50%;
left: 0%;
transform:translate(0%, -50%);
-webkit-transform:translate(0%, -50%);
}

.arrow2 {
position: absolute;
bottom: 20px;
left: 50%;
margin-left: -20px;
width: 40px;
height: 60px;
}

#portfolio {
width:100%;
height:100vh;
background:#ED4C67;
display:block;
position:bottom;
}

.wrappert {
height: 100%;
width: 100%;
display: table;
}

.arrow-wrapper {
position: relative;
}

.arrow-wrapper-2 {
position: relative;
height:100vh;
}
<!DOCTYPE html>
<html>
<head>
<title>JAKUB ORZEG-WYDRA</title>
<link rel="stylesheet" type="text/css" href="main.css" >
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script src="main.js"></script>
<div id="main">

<div class="wrappert">
<div class="wrapper">
<h1>
<a href="" class="typewrite" data-period="2000" data-type='[ "Hi, Im Jakub Orzeg-Wydra.", "Im a web designer.", "and a Media Producer." ]'>

</a>
</h1>
</div> </div>

<div class="arrow-wrapper"><div class="arrow bounce"><A href="#about"><i class="fa fa-angle-down fa-5x" aria-hidden="true"></i></A></div></div>

</div>

<div id="about">

<div class="vertical-center">
<center><p class="about_para">I am a 15 year old from scotland who <br>
loves to code and produce media like <br>
videos. I also love sports and fitness.</p></center></div>
<div class="arrow-wrapper-2"><div class="arrow2 bounce"><A href="#about"><i class="fa fa-angle-down fa-5x" aria-hidden="true" style="color:red;"></i></A></div></div>

</div>

<div id="portfolio">

</div>
</body>

</html>

最佳答案

很简单,在该部分中有两个元素。第一个具有内容的高度,第二个具有 100vh 并且都是流入元素(因为第一个仅设置为 position:relative)所以如果你做总数你有超过 100vh。这就是为什么属于 100vh 部分的箭头在外面。

如果我们引用 documentation :

relative

The element is positioned according to the normal flow of the document, and then offset relative to itself based on the values of top, right, bottom, and left. The offset does not affect the position of any other elements; thus, the space given for the element in the page layout is the same as if position were static.

要解决此问题,您需要对第一个元素使用绝对位置(将其从流中移除,因此不再考虑高度)并使其父元素相对位置。

@import url('https://fonts.googleapis.com/css?family=Josefin+Sans');
@import "compass/css3";
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
font-family: 'Josefin Sans', sans-serif;
}

#main {
width: 100%;
height: 100vh;
background: #ED4C67;
text-align: center;
display: block;
}


/* Typewriter */

.typewrite {
color: #fff;
text-decoration: none;
font-family: 'Josefin Sans', sans-serif;
font-size: 60px;
display: block;
}


/* arrow */

@-moz-keyframes bounce {
0%,
20%,
50%,
80%,
100% {
-moz-transform: translateY(0);
transform: translateY(0);
}
40% {
-moz-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-moz-transform: translateY(-15px);
transform: translateY(-15px);
}
}

@-webkit-keyframes bounce {
0%,
20%,
50%,
80%,
100% {
-webkit-transform: translateY(0);
transform: translateY(0);
}
40% {
-webkit-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-webkit-transform: translateY(-15px);
transform: translateY(-15px);
}
}

@keyframes bounce {
0%,
20%,
50%,
80%,
100% {
-moz-transform: translateY(0);
-ms-transform: translateY(0);
-webkit-transform: translateY(0);
transform: translateY(0);
}
40% {
-moz-transform: translateY(-30px);
-ms-transform: translateY(-30px);
-webkit-transform: translateY(-30px);
transform: translateY(-30px);
}
60% {
-moz-transform: translateY(-15px);
-ms-transform: translateY(-15px);
-webkit-transform: translateY(-15px);
transform: translateY(-15px);
}
}

i {
display: block;
color: #fff;
}

.arrow {
position: absolute;
bottom: 20px;
left: 50%;
margin-left: -20px;
width: 40px;
height: 60px;
}

.bounce {
-moz-animation: bounce 2s infinite;
-webkit-animation: bounce 2s infinite;
animation: bounce 2s infinite;
}

#about {
width: 100%;
height: 100vh;
background: white;
display: block;
position:relative;
}

.wrapper {
height: 100%;
vertical-align: middle;
display: table-cell;
text-align: center;
}

.skull {
width: 50%;
float: left;
}

.about_para {
display: block;
color: #ED4C67;
font-size: 40px;
text-align:center;
}

@media only screen and (max-width: 700px) {}

.vertical-center {
position: absolute;
top: 50%;
left: 0;
right:0;
transform: translate(0%, -50%);
-webkit-transform: translate(0%, -50%);
}

.arrow2 {
position: absolute;
bottom: 20px;
left: 50%;
margin-left: -20px;
width: 40px;
height: 60px;
}

#portfolio {
width: 100%;
height: 100vh;
background: #ED4C67;
display: block;
position: bottom;
}

.wrappert {
height: 100%;
width: 100%;
display: table;
}

.arrow-wrapper {
position: relative;
}

.arrow-wrapper-2 {
position: relative;
height: 100vh;
}
<!DOCTYPE html>
<html>

<head>
<title>JAKUB ORZEG-WYDRA</title>
<link rel="stylesheet" type="text/css" href="main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>

<body>
<script src="main.js"></script>
<div id="main">

<div class="wrappert">
<div class="wrapper">
<h1>
<a href="" class="typewrite" data-period="2000" data-type='[ "Hi, Im Jakub Orzeg-Wydra.", "Im a web designer.", "and a Media Producer." ]'>

</a>
</h1>
</div>
</div>

<div class="arrow-wrapper">
<div class="arrow bounce">
<A href="#about"><i class="fa fa-angle-down fa-5x" aria-hidden="true"></i></A>
</div>
</div>

</div>

<div id="about">

<div class="vertical-center">
<p class="about_para">I am a 15 year old from scotland who <br> loves to code and produce media like <br> videos. I also love sports and fitness.</p>
</div>
<div class="arrow-wrapper-2">
<div class="arrow2 bounce">
<A href="#about"><i class="fa fa-angle-down fa-5x" aria-hidden="true" style="color:red;"></i></A>
</div>
</div>

</div>

<div id="portfolio">

</div>
</body>

</html>

关于html - div 顶部和包装器之间的奇怪间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49224895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com