首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >区段高度是否与内容宽度不同?

区段高度是否与内容宽度不同?
EN

Stack Overflow用户
提问于 2020-11-27 21:45:54
回答 1查看 51关注 0票数 0

HTML

代码语言:javascript
复制
<body>
  <header>
    <nav class="navigation">
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Product</a></li>
        <li><a href="#">Faq</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
      <div class="menu-burger">
        <div class="hline"></div>
        <div class="hline"></div>
        <div class="hline"></div>
      </div>
    </nav>
  </header>


  <main class="main-section">
    <div class="main-section-container">
      <p id="line-1">Food app</p>
      <p id="line-main">Why stay hungry when you can order form Bella Onojie</p>
      <p id="line-3">Download the bella onoje’s food app now on</p>
      <div class="btn-container">
        <button class="btn1">Playstore</button>
        <button class="btn2">App store</button>
      </div>
    </div>
  </main>



  <section class="section-a">
    
  </section>

</body>

CSS

代码语言:javascript
复制
html,body{
  box-sizing: border-box;
}


/*---------------------------------NavBar------------------------------------------------*/
header{
  width: 100%;
  height: 156px;
}

.navigation{
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0px 50px;
}

.hline{
  width: 20px;
  height: 3px;
  background-color: var(--clr-4);
  margin: 3px 0px;
  border-radius: 4px;
}

.menu-burger{
  display: none;
  cursor: pointer;
}

.navigation a{
  text-decoration: none;
  color: var(--clr-3);
  font-family: var(--font-1);
  font-weight: 600;
  font-size: 1rem;
  transition: 0.3s ease;
}

.navigation a:hover{
  color: var(--clr-2);
}

.navigation ul{
  margin-left: auto;
  list-style: none;
  display: flex;
  width: 50%;
  max-width: 720px;
  justify-content: space-between;
}

@media (max-width: 600px){

  header{
    height: 112px;
  }

  .menu-burger{
    display: inline-block;
    margin-left: auto;
  }

  .navigation{
    padding: 0px 24px;
  }

  .navigation ul{
    display: none;
  }
}


/*----------------------------Main Section-------------------------------------------------*/

.main-section{
  width: 100%;
  min-height: 619px;
  max-height: 750px;
  background-image: url(../images/main-bg.png);
  background-size: cover;
  position: relative;
  overflow: hidden;
  background-repeat: no-repeat;
}

.main-section::after{
  content: "";
  height: 100%;
  width: 100%;
  background-color: var(--clr-5);
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0.7;
  z-index: 1;
}

.main-section-container{
  position: relative;
  z-index: 2;
  width: 60%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  top: 80px;
}

#line-1{
  font-family: var(--font-1);
  font-size: var(--font-size-3);
  font-weight: 700;
  color: var(--clr-1);
  margin-bottom: 20px;
}

#line-main{
  font-family: var(--font-3);
  font-size: var(--font-size-7);
  font-weight: 700;
  color: var(--clr-1);
  line-height: 5rem;
  margin-bottom: 40px;
  text-align: center;
}

#line-3{
  font-family: var(--font-1);
  font-size: var(--font-size-3);
  font-weight: 500;
  color: var(--clr-1);
  margin-bottom: 40px;
  text-align: center;
}

.btn-container{
  display: flex;
  width: 500px;
  justify-content: space-between;
}

.btn1, .btn2{
  font-family: var(--font-1);
  font-size: var(--font-size-3);
  font-weight: 700;
  color: var(--clr-1);
  width: 236px;
  height: 68px;
  border-radius: 30px;
  outline: none;
  cursor: pointer;
}

.btn1{
  background-color: var(--clr-2);
  border: none;
}

.btn2{
  background: none;
  border: 2px solid var(--clr-1);
}


@media (max-width: 850px){
  #line-1{
    font-size: var(--font-size-2);
  }
  #line-main{
    font-size: var(--font-size-4);
    line-height: 2.65rem;
  }
}

@media (max-width: 700px){
  .btn-container{
    width: 236px;
    flex-direction: column;
  }

  .btn1, .btn2{
    margin: 10px 0px;
  }
}

@media (max-width: 600px){
  .main-section{
    background-image: none;
    background-color: var(--clr-6);
  }

  .main-section::after{
    background-color: none;
    background: none;
  }

  #line-1{
    color: var(--clr-4);
  }
  #line-main{
    color: var(--clr-5);
  }
  #line-3{
    color: var(--clr-4);
  }

  .btn-container{
    width: 236px;
    flex-direction: column;
  }

  .btn1, .btn2{
    margin: 10px 0px;
  }

  .btn2{
    color: var(--clr-2);
    border-color: var(--clr-2)
  }
}

@media (max-width:500px){
  .main-section{
    min-height: 650px;
  }
}








/*----------------------------------Section a------------------------------------------*/

.section-a{
  width: 100%;
  height: 50vh;
  background-color: var(--clr-1);
}

我的问题是当我试图使它响应时,当它达到454px时,主要的两个按钮隐藏起来。因为主节没有伸展。

为了了解我的问题,我附上了一些截图。

我该如何解决这个问题?我想拉伸主部分,并在减小尺寸时保持按钮可见。(主要部分为浅灰色背景。)

非常感谢你的帮助!

EN

回答 1

Stack Overflow用户

发布于 2020-11-27 22:29:30

你必须以较低的分辨率重置top style:.main-section-container {top: 0;},或者可以删除overflow: hidden

代码语言:javascript
复制
html,body{
  box-sizing: border-box;
}


/*---------------------------------NavBar------------------------------------------------*/
header{
  width: 100%;
  height: 156px;
}

.navigation{
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0px 50px;
}

.hline{
  width: 20px;
  height: 3px;
  background-color: #ccc;
  margin: 3px 0px;
  border-radius: 4px;
}

.menu-burger{
  display: none;
  cursor: pointer;
}

.navigation a{
  text-decoration: none;
  color: var(--clr-3);
  font-family: var(--font-1);
  font-weight: 600;
  font-size: 1rem;
  transition: 0.3s ease;
}

.navigation a:hover{
  color: var(--clr-2);
}

.navigation ul{
  margin-left: auto;
  list-style: none;
  display: flex;
  width: 50%;
  max-width: 720px;
  justify-content: space-between;
}

@media (max-width: 600px){

  header{
    height: 112px;
  }

  .menu-burger{
    display: inline-block;
    margin-left: auto;
  }

  .navigation{
    padding: 0px 24px;
  }

  .navigation ul{
    display: none;
  }
}


/*----------------------------Main Section-------------------------------------------------*/

.main-section{
  width: 100%;
  min-height: 619px;
  max-height: 750px;
  background-image: url(../images/main-bg.png);
  background-size: cover;
  position: relative;
  overflow: hidden;
  background-repeat: no-repeat;
}

.main-section::after{
  content: "";
  height: 100%;
  width: 100%;
  background-color: var(--clr-5);
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0.7;
  z-index: 1;
}

.main-section-container{
  position: relative;
  z-index: 2;
  width: 60%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  top: 80px;
}

#line-1{
  font-family: var(--font-1);
  font-size: var(--font-size-3);
  font-weight: 700;
  color: var(--clr-1);
  margin-bottom: 20px;
}

#line-main{
  font-family: var(--font-3);
  font-size: var(--font-size-7);
  font-weight: 700;
  color: var(--clr-1);
  line-height: 5rem;
  margin-bottom: 40px;
  text-align: center;
}

#line-3{
  font-family: var(--font-1);
  font-size: var(--font-size-3);
  font-weight: 500;
  color: var(--clr-1);
  margin-bottom: 40px;
  text-align: center;
}

.btn-container{
  display: flex;
  width: 500px;
  justify-content: space-between;
}

.btn1, .btn2{
  font-family: var(--font-1);
  font-size: var(--font-size-3);
  font-weight: 700;
  color: var(--clr-1);
  width: 236px;
  height: 68px;
  border-radius: 30px;
  outline: none;
  cursor: pointer;
}

.btn1{
  background-color: #ddd;
  border: none;
}

.btn2{
  background: none;
  border: 2px solid var(--clr-1);
}


@media (max-width: 850px){
  #line-1{
    font-size: var(--font-size-2);
  }
  #line-main{
    font-size: var(--font-size-4);
    line-height: 2.65rem;
  }
}

@media (max-width: 700px){
  .btn-container{
    width: 236px;
    flex-direction: column;
  }

  .btn1, .btn2{
    margin: 10px 0px;
  }
}

@media (max-width: 600px){
  .main-section{
    background-image: none;
    background-color: #ccc;
  }

  .main-section::after{
    background-color: none;
    background: none;
  }

  #line-1{
    color: var(--clr-4);
  }
  #line-main{
    color: var(--clr-5);
  }
  #line-3{
    color: var(--clr-4);
  }

  .btn-container{
    width: 236px;
    flex-direction: column;
  }

  .btn1, .btn2{
    margin: 10px 0px;
  }

  .btn2{
    color: var(--clr-2);
    border-color: var(--clr-2)
  }
}

@media (max-width:500px){
  .main-section{
    min-height: 650px;
  }
  .main-section-container {
    top: 0;
  }
}








/*----------------------------------Section a------------------------------------------*/

.section-a{
  width: 100%;
  height: 50vh;
  background-color: #ddd;
}
代码语言:javascript
复制
<body>
  <header>
    <nav class="navigation">
      <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Product</a></li>
        <li><a href="#">Faq</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
      <div class="menu-burger">
        <div class="hline"></div>
        <div class="hline"></div>
        <div class="hline"></div>
      </div>
    </nav>
  </header>


  <main class="main-section">
    <div class="main-section-container">
      <p id="line-1">Food app</p>
      <p id="line-main">Why stay hungry when you can order form Bella Onojie</p>
      <p id="line-3">Download the bella onoje’s food app now on</p>
      <div class="btn-container">
        <button class="btn1">Playstore</button>
        <button class="btn2">App store</button>
      </div>
    </div>
  </main>



  <section class="section-a">
    
  </section>

</body>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65038431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档