css 具有Flex方向列的FlexBox内部存在未知空间

vcirk6k6  于 2023-06-07  发布在  其他
关注(0)|答案(1)|浏览(185)

带有Flex方向列的Flexbox内部的未知空间。
我创建了一个div name header left,它是一个带有flex方向列的flex框。它包含三个div left_text_heading,hero-img,hero-text,hero-img和hero-text之间有未知的空格。在这些div中没有边距或填充,但仍然有空间。The unknown space in red area
公司简介

<!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

*{
    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;
}
oyt4ldly

oyt4ldly1#

这个空间是由h1元素字体的descender高度引起的。
您可以通过指定负margin-bottom来删除空格。您需要相应地调整图像的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>

相关问题