gpt4 book ai didi

html - 使 div 元素坚持到顶部

转载 作者:太空宇宙 更新时间:2023-11-04 08:10:59 24 4
gpt4 key购买 nike

我希望我的选项类 div 遵循我的注册类 div,就像我的注册类 div 遵循主标题类 div 一样。由于某种原因,选项类 div float 在注册类 div 下面。有人可以为此提供响应式解决方案吗?非常有必要解释为什么我的选项 div 没有直接显示在我的注册类 div 下面。

html, body {
height: 100%;
}
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}

[class*="col-"] {
float: left;
padding: 15px;
border: 1px solid red;
}
.row::after {
content: "";
clear: both;
display: table;
}

* {
box-sizing: border-box;
}
.header {
background-color: black;
color: white;
padding: 5px 20px 5px 5px;
margin-top: 0;
text-align: right;

}

a {
color: white;
text-decoration: none;
}

.row {
height: 100%;
border-color: red;
}

.footer {
height: 25%;
}

.top-space {
height: 25%;
}

.middle {
height:150%;
}

.left-aside {
height: 100%;
}

.main {
height: 100%;
padding: 0;
margin: 0;
}

.right-aside {
height: 100%;
}

.main-heading {
height: 3%;
margin: 0;
}

.registration {
height: 60%;
margin: 0;
}

.options {
height: 50%;
margin: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-2.1.0.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script language="JavaScript" type="text/javascript" src="js/indexController.js"></script>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<div class="header">
<span><a href="#">Login</a> | <a href="#">Countries</a></span>
</div>

<div class="row top-space">
<div class="col-3" style="height: 100%">
</div>
<div class="col-9" style="height: 100%">
</div>
</div>

<div class="row middle">
<div class="col-3 left-aside">
</div>
<div class="col-6 main">
<div class="row main-heading">
<div class="col-2">
</div>
<div class="col-2">
</div>
<div class="col-2">
</div>
<div class="col-2">
</div>
<div class="col-4">
</div>
</div>
<div class="row registration">
<div class="col-6 registration">
</div>
<div class="col-6 registration">
</div>
</div>
<div class="row options">
<div class="col-12 options">
</div>
</div>
</div>
<div class="col-3 right-aside">
</div>
</div>

<div class="row footer">
<div class="col-3" style="height: 100%">
</div>
<div class="col-3" style="height: 100%">
</div>
<div class="col-3" style="height: 100%">
</div>
<div class="col-3" style="height: 100%">
</div>
</div>

</body>
</html>

最佳答案

发生这种情况是因为您的类(class) registration 在父级和子级上使用了两次,所以这意味着子级将占用 60% 60%。所以再给 children 一个100%高度的类

.registration-item {
height: 100;
margin: 0;
}

html, body {
height: 100%;
}
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}

[class*="col-"] {
float: left;
padding: 15px;
border: 1px solid red;
}
.row::after {
content: "";
clear: both;
display: table;
}

* {
box-sizing: border-box;
}
.header {
background-color: black;
color: white;
padding: 5px 20px 5px 5px;
margin-top: 0;
text-align: right;

}

a {
color: white;
text-decoration: none;
}

.row {
height: 100%;
border-color: red;
}

.footer {
height: 25%;
}

.top-space {
height: 25%;
}

.middle {
height:150%;
}

.left-aside {
height: 100%;
}

.main {
height: 100%;
padding: 0;
margin: 0;
}

.right-aside {
height: 100%;
}

.main-heading {
height: 3%;
margin: 0;
}

.registration {
height: 60%;
margin: 0;
}

.options {
height: 50%;
margin: 0;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-2.1.0.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script language="JavaScript" type="text/javascript" src="js/indexController.js"></script>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<div class="header">
<span><a href="#">Login</a> | <a href="#">Countries</a></span>
</div>

<div class="row top-space">
<div class="col-3" style="height: 100%">
</div>
<div class="col-9" style="height: 100%">
</div>
</div>

<div class="row middle">
<div class="col-3 left-aside">
</div>
<div class="col-6 main">
<div class="row main-heading">
<div class="col-2">
</div>
<div class="col-2">
</div>
<div class="col-2">
</div>
<div class="col-2">
</div>
<div class="col-4">
</div>
</div>
<div class="row registration" style="background-color: deeppink;">
<div class="col-6 registration" style="background-color: deepskyblue;">
</div>
<div class="col-6 registration">
</div>
</div>
<div class="row options">
<div class="col-12 options" style="background-color: deepskyblue;">
</div>
</div>
</div>
<div class="col-3 right-aside">
</div>
</div>

<div class="row footer">
<div class="col-3" style="height: 100%">
</div>
<div class="col-3" style="height: 100%">
</div>
<div class="col-3" style="height: 100%">
</div>
<div class="col-3" style="height: 100%">
</div>
</div>

</body>
</html>

关于html - 使 div 元素坚持到顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46302377/

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