英文:
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)。尝试删除了
英文:
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 -->
<!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 -->
答案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 -->
<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>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论