Bootstrap leaves margin on the right.

huangapple go评论67阅读模式
英文:

Bootstrap leaves margin on the right

问题

我在Bootstrap中编写了代码。我已经添加了"class"属性为"m-0",但仍然在此元素右侧留有间距。

这是代码:

<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">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <title>Document</title>
</head>
<body>
    <section>
        <div class="container h-100 w-100 bg-light m-0">
            <div class="row justify-content-center align-items-center h-100">
                <div class="col-lg-6 text-lg-start text-md-center">
                    <h1 class="display-1">
                        text
                    </h1>
                    <h3 class="display-5 text-muted">
                        description
                    </h3>
                </div>
                <!-- lub md--><div class="col-lg-6 text-center">
                    <iframe src="" width="450" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
                </div>
            </div>
        </div>
    </section>
</body>
</html>

我已经检查了系统(MacOs、Windows)、浏览器(Chrome、Safari)。尝试删除了

标签。我尝试将元素的宽度设置为110vw。我尝试使用"class"属性为"mx-0"。这些步骤中的任何一个都没有帮助。"max-width:100%"可以解决问题,但我不想强制解决方案,而是想找出它不起作用的原因。

英文:

I wrote code in Bootstrap. I've added the class "m-0" but it still leaves margin on the right for this element.

This is the code:

<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">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <title>Document</title>
</head>
<body>
    <section>
        <div class="container h-100 w-100 bg-light m-0">
            <div class="row justify-content-center align-items-center h-100">
                <div class="col-lg-6 text-lg-start text-md-center">
                    <h1 class="display-1">
                        text
                    </h1>
                    <h3 class="display-5 text-muted">
                        description
                    </h3>
                </div>
                <!-- lub md--><div class="col-lg-6 text-center">
                    <iframe src="" width="450" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
                </div>
            </div>
        </div>
    </section>
</body>
</html>

I checked system (MacOs, Windows), browser (Chrome, Safari). Tried deleting the section tag. I tried setting width of the element to 110vw. I tried class "mx-0" Any of these steps didn't help.
The max-width:100% works but I don't want to force the solution and find the reason of it not working

答案1

得分: 2

以下是翻译好的部分:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->
<!DOCTYPE html>
<html>
<body>
<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">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <title>Document</title>
    <style>
    .container{
        max-width:100% !important;
        text-align:left;
        width:100% !important; ;
        margin-left:0px;
    }
    
    </style>
    
</head>
<body>
    <section>
        <div class="container h-100 w-100 bg-light " style="text-align:left;margin-left:0px;">
            <div class="row justify-content-center align-items-center h-100">
                <div class="col-lg-6 text-lg-start text-md-center" style="float:left;">
                    <h1 class="display-1">
                        text
                    </h1>
                    <h3 class="display-5 text-muted">
                        description
                    </h3>
                </div>
                <!-- lub md--><div class="col-lg-6 text-center">
                    <iframe src="" width="450" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
                </div>
            </div>
        </div>
    </section>
</body>
</html>

</body>
</html>


<!-- end snippet -->

注意:我保留了原始代码中的HTML标记和属性,没有进行翻译。

英文:

little modification

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC&quot; crossorigin=&quot;anonymous&quot;&gt;
&lt;title&gt;Document&lt;/title&gt;
&lt;style&gt;

.container{
max-width:100% !important;
text-align:left;
width:100% !important;;
margin-left:0px;
}

    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;section&gt;
&lt;div class=&quot;container h-100 w-100 bg-light &quot; style=&quot;text-align:left;margin-left:0px;&gt;
&lt;div class=&quot;row justify-content-center align-items-center h-100&quot;&gt;
&lt;div class=&quot;col-lg-6 text-lg-start text-md-center&quot; style=&quot;float:left;&quot;&gt;
&lt;h1 class=&quot;display-1&quot;&gt;
text
&lt;/h1&gt;
&lt;h3 class=&quot;display-5 text-muted&quot;&gt;
description
&lt;/h3&gt;
&lt;/div&gt;
&lt;!-- lub md--&gt;&lt;div class=&quot;col-lg-6 text-center&quot;&gt;
&lt;iframe src=&quot;&quot; width=&quot;450&quot; height=&quot;450&quot; style=&quot;border:0;&quot; allowfullscreen=&quot;&quot; loading=&quot;lazy&quot; referrerpolicy=&quot;no-referrer-when-downgrade&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

答案2

得分: 1

Bootstrap的container HTML类默认情况下设置了max-width CSS属性。

要覆盖它,请添加以下CSS:

.container {
  max-width: unset !important;
}

请查看下面的示例。

英文:

Bootstrap's container HTML class has the max-width CSS property set by default.

To override it, add the following CSS:

.container {
max-width: unset !important;
}

See the snippet below.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.container {
max-width: unset !important;
}

<!-- language: lang-html -->

&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC&quot; crossorigin=&quot;anonymous&quot;&gt;
&lt;title&gt;Document&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;section&gt;
&lt;div class=&quot;container h-100 w-100 bg-light m-0&quot;&gt;
&lt;div class=&quot;row justify-content-center align-items-center h-100&quot;&gt;
&lt;div class=&quot;col-lg-6 text-lg-start text-md-center&quot;&gt;
&lt;h1 class=&quot;display-1&quot;&gt;
text
&lt;/h1&gt;
&lt;h3 class=&quot;display-5 text-muted&quot;&gt;
description
&lt;/h3&gt;
&lt;/div&gt;
&lt;!-- lub md--&gt;
&lt;div class=&quot;col-lg-6 text-center&quot;&gt;
&lt;iframe src=&quot;&quot; width=&quot;450&quot; height=&quot;450&quot; style=&quot;border:0;&quot; allowfullscreen=&quot;&quot; loading=&quot;lazy&quot; referrerpolicy=&quot;no-referrer-when-downgrade&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月5日 21:37:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76406994.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定