【问题标题】:When using width:100vw in nuxt.js there is extra white space在 nuxt.js 中使用 width:100vw 时有额外的空白
【发布时间】:2019-09-20 14:58:16
【问题描述】:

我正在我的 nuxt.js 中构建组件横幅。

我尝试了很多方法来解决这个问题,但仍然没有解决,我尝试在我的htmlbody 标签中添加margin:0;padding:0;,但空白仍然存在。我在这个主题中尝试了另一个关于using-100vw-and-vh-creates-extra-space-beyond-viewport-size-how-do-i-get-rid-of 的解决方案,但是当我尝试它时,结果仍然是一样的。我也尝试过关于100vw-causing-horizontal-overflow-but-only-if-more-than-one 的这个话题,但没有运气。

这是我的横幅组件:

<template>
  <div id="paham-banner-career">
    <div class="banner-container">
      <h2>Let's See Where You Fit In</h2>
    </div>
  </div>
</template>

这是我的 CSS:

<style lang="css" scoped>
#paham-banner-career{
    font-family: "Nunito", sans-serif;
    background-color: #3b73c5;
    width: 100vw;
    max-width: 100%;
}

#paham-banner-career .banner-container{
    margin: 100px auto;
    padding: 25px 0px;
    text-align: center;
    max-width: 1200px;
}

#paham-banner-career h2{
    color: #ffffff;
    font-size: 2.5em;
    font-weight: bold;
}
</style>

谁能救我解决这个问题?

这就是我现在得到的

【问题讨论】:

    标签: html css


    【解决方案1】:

    尝试添加box-sizing

    <style lang="css" scoped>
    
    *{box-sizing: border-box;}
    
    #paham-banner-career{
        font-family: "Nunito", sans-serif;
        background-color: #3b73c5;
        width: 100vw;
        max-width: 100%;
    }
    
    #paham-banner-career .banner-container{
        margin: 100px auto;
        padding: 25px 0px;
        text-align: center;
        max-width: 1200px;
    }
    
    #paham-banner-career h2{
        color: #ffffff;
        font-size: 2.5em;
        font-weight: bold;
    }
    </style>
    

    【讨论】:

    • 谢谢您的回复,我必须在哪里添加它?当我尝试它时没有任何变化
    • 我已经更新了我的答案,在你的 CSS 中添加整行并检查。
    • 我尝试像你一样添加box-sizing:border-box,但仍然没有任何反应
    • 能否请您创建具有相同行为的 sn-p,以便我检查。
    • 我在这个小提琴中添加了一个我的组件,但它已经可以工作但不在我的完整代码中jsfiddle.net/RFTaurus/qx0ozLw1
    猜你喜欢
    • 1970-01-01
    • 2020-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多