提问者:小点点

当我收缩浏览器时,按钮会超出div


我有一个使用html和css创建的简单页面,当我收缩浏览器时,按钮small-button会出现在div之外,我不知道为什么,我想要将它保留在div中,不管我如何收缩浏览器,以便它能够响应。 我怎么能那么做?

下面是我的HTML:

  <div class="main-container">
        <div class="headers">
            <div class="nav">
                <h1 class="nav-h1">Logo</h1>
                <div class="a-container">
                    <a>About</a>
                    <a>Vision</a>
                    <a>Solutions</a>
                    <a>Technology</a>
                    <a>Contact</a>
                </div>
                <div class="logo-section">
                    <img class="logo-img" src="/assets/images/facebook.png" alt="facebook logo">
                    <img class="logo-img" src="/assets/images/linkedin.png" alt="linkedin logo">
                </div>
            </div>
        </div>
        <div class="content">
            <div class="content-inside">
                <div class="first-section">
                    <p class="first-section-p">Turnkey platforms <br> for businesses looking to rule the online market
                    </p>
                    <button class="small-button">LEARN MORE</button>
                </div>
                <div class="second-section">
                    <p class="second-section-text">WHAT</p>
                    <p class="second-section-text">WHE DO</p>
                    <p class="second-section-text">BEST</p>
                </div>
            </div>
        </div>
        <div class="footer"></div>
    </div>

和我的CSS:

* {
  padding: 0px;
  margin: 0px;

  box-sizing: border-box;    

}

.nav {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 50%;
  }
  
  .header {
    height: 8%;
  }

  
  .nav-h1 {
    text-align: center;
    margin-top: 27px;

    font-size: 40px;
  }

  a {
    display: inline-block;
    margin: 10px;
    font-family: 'Segoe UI',sans-serif;
    font-family: SegoeUI;
    font-size: 16px;
    font-weight: bold;
    color: black;
    font-weight: bold;
  }

  .a-container {
      margin-left: 10%;
      margin-top: 27px;
  }

  .footer {
    background-color: #e8e8e8;
    height: 288px;
    width: 100%;
  }

  .alignleft {
    float: left;
    margin-left: 8%;

    font-family: SegoeUI;
    font-size: 18px;
    font-weight: 900;
    color: #000000;
}

.alignright {
    float: right;
    margin-right: 8%;
    display: flex;
    flex-direction: row;
}

.logo-section {
    margin-top: 1.3%;
    margin-left: 2%;
}

.logo-img {
    padding: 6px;
}

.first-section {
    width: 100%;
    height: 800px;
    background-image: url("/assets/images/first-image.png");
    background-repeat: no-repeat;
    background-size: contain;
    position: relative;
    float: left;
}

.first-section-p {
    width: 400px;
    height: 314px;
    margin-left: 10%;
    padding-top: 10%;
    font-family: SegoeUI;
    font-weight: 900;
    font-size: 4vh;
    font-weight: 900;
    text-align: center;
    color: #262262;
}

.small-button {
    width: 331px;
    height: 92px;

    margin-left: 12%;
    background-color: #e7af17;
    font-family: SegoeUI;
    font-size: 18px;
    font-weight: 900;
    color: white;
    border: none;
}

.second-section-text {
    color: #e8e8e8;
    font-weight: 900;
    font-size: 70px;
    line-height: 0.7;
    font-family: SegoeUI;
    margin-left: 12%;
}



@media (min-width: 1281px) {
  
    .first-section {
        width: 100%;
        height: 800px;
        background-image: url("/assets/images/first-image.png");
        background-repeat: no-repeat;
        background-size: cover;
    }

    .small-button {
        width: 331px;
        height: 92px;
    
        margin-top: 8%;
        margin-left: 12%;
        background-color: #e7af17;
        font-family: SegoeUI;
        font-size: 18px;
        font-weight: 900;
        color: white;
        border: none;
    }
  }


共2个答案

匿名用户

尝试使用meta标记设置视口。

请参阅以下资源:https://www.w3schools.com/html/html_responve.asp

匿名用户

确保在html文件中有此元,并尝试更改要调整大小的元素的大小和位置,但不定义所有属性,只定义要更改的属性

null

* {
  padding: 0px;
  margin: 0px;
  box-sizing: border-box;
}

.nav {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 50%;
}

.header {
  height: 8%;
}

.nav-h1 {
  text-align: center;
  margin-top: 27px;
  font-size: 40px;
}

a {
  display: inline-block;
  margin: 10px;
  font-family: 'Segoe UI', sans-serif;
  font-family: SegoeUI;
  font-size: 16px;
  font-weight: bold;
  color: black;
  font-weight: bold;
}

.a-container {
  margin-left: 10%;
  margin-top: 27px;
}

.footer {
  background-color: #e8e8e8;
  height: 288px;
  width: 100%;
}

.alignleft {
  float: left;
  margin-left: 8%;
  font-family: SegoeUI;
  font-size: 18px;
  font-weight: 900;
  color: #000000;
}

.alignright {
  float: right;
  margin-right: 8%;
  display: flex;
  flex-direction: row;
}

.logo-section {
  margin-top: 1.3%;
  margin-left: 2%;
}

.logo-img {
  padding: 6px;
}

.first-section {
  width: 100%;
  height: 800px;
  background-image: url("/assets/images/first-image.png");
  background-repeat: no-repeat;
  background-size: contain;
  position: relative;
  float: left;
}

.first-section-p {
  width: 400px;
  height: 314px;
  margin-left: 10%;
  padding-top: 10%;
  font-family: SegoeUI;
  font-weight: 900;
  font-size: 4vh;
  font-weight: 900;
  text-align: center;
  color: #262262;
}

.small-button {
  width: 331px;
  height: 92px;
  margin-left: 12%;
  background-color: #e7af17;
  font-family: SegoeUI;
  font-size: 18px;
  font-weight: 900;
  color: white;
  border: none;
}

.second-section-text {
  color: #e8e8e8;
  font-weight: 900;
  font-size: 70px;
  line-height: 0.7;
  font-family: SegoeUI;
  margin-left: 12%;
}

@media (min-width: 1281px) {
  .first-section {
    width: 100%;
    height: 800px;
    background-image: url("/assets/images/first-image.png");
    background-repeat: no-repeat;
    background-size: cover;
  }
  .small-button {
    width: 321px;
    height: 82px;
    margin-top: -28%;
    margin-left: 12%;
    background-color: #e7af17;
    font-family: SegoeUI;
    font-size: 18px;
    font-weight: 900;
    color: white;
    border: none;
  }
}

@media (max-width: 800px) {
  .small-button {
    margin-top: -30%;
    margin-left: 14%;
  }
}
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<div class="main-container">
  <div class="headers">
    <div class="nav">
      <h1 class="nav-h1">Logo</h1>
      <div class="a-container">
        <a>About</a>
        <a>Vision</a>
        <a>Solutions</a>
        <a>Technology</a>
        <a>Contact</a>
      </div>
      <div class="logo-section">
        <img class="logo-img" src="/assets/images/facebook.png" alt="facebook logo">
        <img class="logo-img" src="/assets/images/linkedin.png" alt="linkedin logo">
      </div>
    </div>
  </div>
  <div class="content">
    <div class="content-inside">
      <div class="first-section">
        <p class="first-section-p">Turnkey platforms <br> for businesses looking to rule the online market
        </p>
        <button class="small-button">LEARN MORE</button>
      </div>
      <div class="second-section">
        <p class="second-section-text">WHAT</p>
        <p class="second-section-text">WHE DO</p>
        <p class="second-section-text">BEST</p>
      </div>
    </div>
  </div>
  <div class="footer"></div>
</div>