具有伸縮方向列的flexbox內部有未知空間。
我在左側創建了一個div名稱標題,這是一個帶有伸縮方向列的伸縮框。它包含三個部分 left_text_heading,hero-img,hero-text,hero-img和hero-text之間有未知空格。這些div中沒有邊距或填充,但仍然有空間。紅色區域的未知空間
index.html->;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PortFolio</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div class="header">
<div class="header-left">
<div class="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About me</a></li>
<li><a href="#">Product</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
<div class="left_text_heading">
<h1>HI</h1>
</div>
<div class="hero-img">
<img src="./images/person.svg" alt="person">
</div>
<div class="hero-text">
<p>My name is Shallom, I am a product designer</p>
</div>
</div>
<div class="header-right"></div>
</div>
</div>
</body>
</html>
style . CSS-& gt;
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background: #091A29;
font-family: 'DM Sans', sans-serif;
font-style: normal;
font-weight: 400;
font-size: 20px;
line-height: 30px;
color: #fff;
}
.container{
margin-left: 80px;
}
.header{
width: 100%;
display: flex;
}
.header-left{
display: flex;
flex-direction: column;
width: 584px;
margin-top: 38px;
}
.nav{
display: flex;
align-items: center;
margin-bottom: 25px;
}
.nav>ul{
display: flex;
list-style: none;
gap: 68px;
}
.nav>ul>li>a{
text-decoration: none;
color: #193A58;
}
.left_text_heading{
display: flex;
align-items: center;
justify-content: flex-start;
height: 366px;
margin-top: 25px;
font-weight: bold;
}
.left_text_heading > h1{
position: relative;
font-size: 500px;
left: -35px;
color: #183a58;
}
.hero-img{
display: flex;
align-items: center;
justify-content: center;
width: 144px;
position: relative;
bottom: 75px;
}
.hero-text{
width: 550px;
display: flex;
flex-direction: column;
}
.hero-text>p{
font-weight: 400;
font-size: 50px;
line-height: 65px;
}
空格是由h1元素字體的下行高度引起的。
您可以通過指定負margin-bottom來刪除空格。您需要相應地調整圖像的底部屬性。
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #091A29;
font-family: 'DM Sans', sans-serif;
font-style: normal;
font-weight: 400;
font-size: 20px;
line-height: 30px;
color: #fff;
}
.container {
margin-left: 80px;
}
.header {
width: 100%;
display: flex;
}
.header-left {
display: flex;
flex-direction: column;
width: 584px;
margin-top: 38px;
}
.nav {
display: flex;
align-items: center;
margin-bottom: 25px;
}
.nav > ul {
display: flex;
list-style: none;
gap: 68px;
}
.nav > ul > li > a {
text-decoration: none;
color: #193A58;
}
.left_text_heading {
display: flex;
align-items: center;
justify-content: flex-start;
height: 366px;
margin-top: 25px;
font-weight: bold;
}
.left_text_heading > h1 {
position: relative;
font-size: 500px;
left: -35px;
color: #183a58;
margin-bottom: -0.5em;
}
.hero-img {
display: flex;
align-items: center;
justify-content: center;
width: 144px;
position: relative;
bottom: 0;
}
.hero-img img {
border-radius: 50%;
}
.hero-text {
width: 550px;
display: flex;
flex-direction: column;
}
.hero-text > p {
font-weight: 400;
font-size: 50px;
line-height: 65px;
}
<div class="container">
<div class="header">
<div class="header-left">
<div class="nav">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About me</a></li>
<li><a href="#">Product</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
<div class="left_text_heading">
<h1>HI</h1>
</div>
<div class="hero-img">
<img src="https://randomuser.me/api/portraits/men/5.jpg" alt="person">
</div>
<div class="hero-text">
<p>My name is Shallom, I am a product designer</p>
</div>
</div>
<div class="header-right"></div>
</div>
</div>