gpt4 book ai didi

html - Bootstrap 列间距

转载 作者:太空宇宙 更新时间:2023-11-04 06:16:23 26 4
gpt4 key购买 nike

我想在每列之间添加一个间隙。如果我添加一个 margin 属性,这些列不适合一行。我怎样才能实现每行 4 列有间隙?

<style>
.test {
border: 5px solid red;
}
</style>

<div class="container-fluid test">
<div class="row">
<div class="col-md-3 test m-2">
Hello
</div>
<div class="col-md-3 test m-2">
Hello
</div>
<div class="col-md-3 test m-2">
Hello
</div>
<div class="col-md-3 test m-2">
Hello
</div>
</div>
</div>

enter image description here

编辑:我想我忽略了一些东西......这很好用:

.gap {
margin: 10px;
border: 1px solid black;
width: fit-content;
padding: 10px;
}

.row {
display: flex;
border: 1px solid black;
}
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Startseite</title>

<!-- Basic Icons-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- Custom CSS -->
<link rel="stylesheet" href="styletest.css">

</head>

<body>
<div class="container">
<div class="row">
<div class="col-sm-3 gap">
columns 1
</div>
<div class="col-sm-3 gap">
columns 2
</div>
<div class="col-sm-3 gap">
columns 3
</div>
<div class="col-sm-3 gap">
columns 4
</div>
<div class="col-sm-3 gap">
columns 5
</div>
</div>
</div>
</body>

</html>

但如果我添加最新的 Bootstrap 引用,它就不起作用。像这样:

<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.gap {
margin: 10px;
border: 1px solid black;
width: fit-content;
padding: 10px;
}

.row {
display: flex;
border: 1px solid black;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Startseite</title>

<!-- Basic Icons-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">


<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<!-- Custom CSS -->
<link rel="stylesheet" href="styletest.css">

</head>

<body>
<div class="container">
<div class="row">
<div class="col-sm-3 gap">
columns 1
</div>
<div class="col-sm-3 gap">
columns 2
</div>
<div class="col-sm-3 gap">
columns 3
</div>
<div class="col-sm-3 gap">
columns 4
</div>
<div class="col-sm-3 gap">
columns 5
</div>
</div>
</div>
</body>

</html></code></pre>
</div>
</div>

最佳答案

页边距对于 how the grid columns work 至关重要.而是调整填充来影响列内容周围的空间......

https://codeply.com/go/YySEuVELp6

 <div class="container-fluid test">
<div class="row">
<div class="col-md-3 p-2">
<div class="test">Hello</div>
</div>
<div class="col-md-3 p-2">
<div class="test">Hello</div>
</div>
<div class="col-md-3 p-2">
<div class="test">Hello</div>
</div>
<div class="col-md-3 p-2">
<div class="test">Hello</div>
</div>
</div>
</div>

注意:列之间的空间称为“装订线”。

关于html - Bootstrap 列间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55920367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com