【发布时间】:2017-09-12 15:52:06
【问题描述】:
我想让我的一个 div 与我以前的 div 具有相同的高度。我正在使用宽度和高度的百分比(所以它在移动设备上看起来也更好。我也尝试将父元素设置为 100% 的宽度和高度(在一些论坛帖子中看到,但它没有工作)。我也尝试过使用 display: table-cell,但也没有用。这就是我的设置的样子:
index.php:
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8"/>
<title>SiteTitle</title>
<link rel = "stylesheet" type = "text/css" href = "styles/index.css"/>
</head>
<body>
<div id = "allContent">
<div id = "header">
<div id = "siteLogo">
<h1 id = "title">Site_Title</h1>
</div>
<div id = "shortMenu">
<a href = "#">Login</a>
</div>
</div>
</div>
</body>
</html>
index.css:
body {
background-color: rgb(0, 0, 0);
margin: 0px;
padding: 0px;
color: rgb(192, 74, 0);
}
div#allContent {
width: 80%;
margin: auto;
}
div#allContent div#header {
margin: 0px;
padding: 0px;
}
div#allContent div#header div#siteLogo {
margin: 0px;
padding: 0px;
width: 70%;
border: 1px solid blue;
float: left;
}
div#allContent div#header div#siteLogo h1#title {
margin: 0px;
padding: 0px;
font-size: 300%;
font-family: Sans-Serif;
}
div#allContent div#header div#shortMenu {
width: 20%;
border: 1px solid green;
float: left;
}
div#allContent div#header div#shortMenu a {
font-family: Sans-Serif;
color: rgb(204, 204, 204);
text-decoration: none;
}
不确定现在要检查什么..
我基本上希望Login 链接的底部与网站标题的底部对齐。稍后我可能会将其更改为徽标图像,因此高度可能会更改,并且如果我决定在路上多次更改它,我不想更改这些值。现在Login 链接位于页面顶部。
编辑:我添加了以下代码行,但它为每个 div 提供了 50% 的宽度
div#allContent div#header {
margin: 0px;
padding: 0px;
display: flex;
}
div#allContent div#header div {
flex: 1;
}
【问题讨论】:
标签: html css height percentage siblings