gpt4 book ai didi

html - 内容从 <header> 溢出并且未在 上设置高度

转载 作者:太空宇宙 更新时间:2023-11-04 09:35:07 25 4
gpt4 key购买 nike

我有一个 70% 高度的标题,5 个 div,每个 div 代表页面中的不同部分。 <header>元素正在获取高度属性并按预期工作,但是当将高度设置为任何百分比值时,div 元素不会。

我环顾四周,显然我需要设置根元素的高度,我在 html 和 body 上设置了 height: 100% 并且一切都按预期工作;但是现在响应的 header 不是。 header 中的任何内容都会溢出并从容器中溢出。

/* === GLOBAL === */
* {
box-sizing: border-box;
}

body {
font-family: "Lato", sans-serif;

height: 100%; /* EXPERIMENTAL */
}

/* === HEADER === */
header {
height: 70%;

background-color: #bdc3c7;
}

header h1 { /* The Heading "Saad Al-Sabbagh" */
margin: 0;

font-family: "PT Sans Narrow";
text-align: center;
padding-top: 2em;
}

header p a { /* The Link Inside The Description Paragraph */
text-decoration: none;
color: #3498db;
}

header p a:hover { /* The Link Inside The Description Paragraphs Hover Effect */
color: #d35400;
border-bottom: 3px solid #d35400;
}

header p { /* The Description Paragraph */
text-align: center;
font-size: 3rem;
padding-top: .3em;
font-weight: 700;
}

header ul { /* The Social Links List */
list-style: none;
text-align: center;
}

header ul li { /* The Social Links List Items */
display: inline-block;
font-size: 5em;
padding: 1em .5em;
}

header ul li a { /* The Social Links */
text-decoration: none;
color: black;
}

header ul li a:hover { /* The Social Links On Hover */
color: #d35400;
}

/* === ABOUT === */
#about {
height: 100;
}
<!DOCTYPE html>
<html>

<head>
<!-- Meta -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Title -->
<title>Saad Al-Sabbagh | Web Developer</title>

<!-- CSS -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,900|PT+Sans+Narrow">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/main.css">
</head>

<body>

<!-- Header -->
<header>
<h1>Saad Al-Sabbagh</h1>
<p>Front End Web Developer, <br>Educator and Author <br>@ <a href="#">SitePoint</a></p>
<ul>
<li><a href="#" class="fa fa-facebook"></a></li>
<li><a href="#" class="fa fa-twitter"></a></li>
<li><a href="#" class="fa fa-linkedin"></a></li>
</ul>
</header>

<!-- About -->
<div id="about">

</div>

<!-- Expertise -->
<div id="expertise">

</div>

<!-- Recent Works -->
<div id="recent-works">

</div>

<!-- Latest Blog Post -->
<div id="latest-blog-post">

</div>

<!-- Contact -->
<div id="contact">

</div>

<!-- Footer -->
<footer>

</footer>

</body>

</html>

最佳答案

示例中存在一些问题:

  1. div 为空时高度为 0。
  2. div 将包裹其内容,而不是“膨胀”以适合其父项的高度。
  3. 高度必须有单位,所以你的 #about { height: 100; 不会工作

我已更正 #1 和 #3,但不明白您想要实现的外观到底是什么。

/* === GLOBAL === */

* {
box-sizing: border-box;
}
body {
font-family: "Lato", sans-serif;
height: 100%;
/* EXPERIMENTAL */
}
/* === HEADER === */

header {
height: 70%;
background-color: #bdc3c7;
}
header h1 {
/* The Heading "Saad Al-Sabbagh" */
margin: 0;
font-family: "PT Sans Narrow";
text-align: center;
padding-top: 2em;
}
header p a {
/* The Link Inside The Description Paragraph */
text-decoration: none;
color: #3498db;
}
header p a:hover {
/* The Link Inside The Description Paragraphs Hover Effect */
color: #d35400;
border-bottom: 3px solid #d35400;
}
header p {
/* The Description Paragraph */
text-align: center;
font-size: 3rem;
padding-top: .3em;
font-weight: 700;
}
header ul {
/* The Social Links List */
list-style: none;
text-align: center;
}
header ul li {
/* The Social Links List Items */
display: inline-block;
font-size: 5em;
padding: 1em .5em;
}
header ul li a {
/* The Social Links */
text-decoration: none;
color: black;
}
header ul li a:hover {
/* The Social Links On Hover */
color: #d35400;
}
/* === ABOUT === */

#about {
height: 100%;
}
<!DOCTYPE html>
<html>

<head>
<!-- Meta -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Title -->
<title>Saad Al-Sabbagh | Web Developer</title>
<!-- CSS -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,900|PT+Sans+Narrow">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<!-- Header -->
<header>
<h1>Saad Al-Sabbagh</h1>
<p>Front End Web Developer,
<br>Educator and Author
<br>@ <a href="#">SitePoint</a>
</p>
<ul>
<li>
<a href="#" class="fa fa-facebook"></a>
</li>
<li>
<a href="#" class="fa fa-twitter"></a>
</li>
<li>
<a href="#" class="fa fa-linkedin"></a>
</li>
</ul>
</header>
<!-- About -->
<div id="about">
About
</div>
<!-- Expertise -->
<div id="expertise">
Expertise
</div>
<!-- Recent Works -->
<div id="recent-works">
Recent Works
</div>
<!-- Latest Blog Post -->
<div id="latest-blog-post">
Latest Blog Post
</div>
<!-- Contact -->
<div id="contact">
Contact
</div>
<!-- Footer -->
<footer>
Footer
</footer>
</body>
</html>

关于html - 内容从 &lt;header&gt; 溢出并且未在 <div's> 上设置高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40410221/

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