我想在两列之间添加一个空格。我试过添加边距,但这会将第二列移动到第一列下方。我看到的任何示例都是为了引导。
这是我要复制的内容
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
#heading {
border: 1px double black;
}
.column {
float: left;
width: 50%;
border: 1px solid black;
}
.row {
padding: 5px;
border: 1px solid black;
}
.row:after {
content: "";
display: table;
clear: both;
padding: 5px;
}
h2, h3 {
text-align: center;
}
</style>
</head>
<body>
<h2 id="heading">Two Equal Columns</h2>
<div class="row">
<div class="column">
<iframe width="100%" src="https://www.youtube.com/embed/bjmYkPkjnVo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<h3>Ingredients</h3>
<ol>
<li>1 pound dry spaghetti</li>
<li>salt and freshly ground black pepper to taste</li>
<li>6 cloves garlic, sliced thin</li>
<li>1/2 cup olive oil (note: I prefer a regular olive oil for this recipe, as opposed to a strongly flavored extra virgin olive oil)</li>
<li>1/4 teaspoon red pepper flakes, or to taste</li>
<li>1/4 cup chopped Italian parsley</li>
<li>1 cup finely grated Parmesan cheese (highly recommend Parmigiano-Reggiano)</li>
<li>1 tablespoon of butter</li>
</ol>
</div>
<div class="column">
<iframe width="100%" src="https://www.youtube.com/embed/sAhUTzTJNaE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<h3>Ingredients</h3>
<ol>
<li>500g of Pasta (cooked as per packet directions)</li>
<li>30g of Butter</li>
<li>4 Cloves of Minced Garlic (about 3-4 teaspoons)</li>
<li>1 1/2 Cups of Cream (about 400ml)</li>
<li>Salt and Pepper</li>
<li>1/2 Cup of Freshly Grated Parmesan Cheese</li>
<li>2 Teaspoons of Freshly Chopped Parsley (plus extra to garnish)</li>
</ol>
</div>
</div>
</body>
</html>
最佳答案
问题是您的两列都占用了 50%
width
。您需要缩小它,以便您可以使用新创建的 margin
。
在下文中,我将此width
更改为45%
,然后添加了10% 的
到第一列(使用选择器 margin-right
.column:first-of-type
)。
请注意,具有额外边距的列仍然占据整个宽度,因为两列现在总计 90%
,为 边距留下
。如果要对此进行调整,只需确保 10%
margin
等于 100% 减去列的总 width
。
* {
box-sizing: border-box;
}
#heading {
border: 1px double black;
}
.column {
float: left;
width: 45%;
border: 1px solid black;
}
.column:first-of-type {
margin-right: 10%;
}
.row {
padding: 5px;
border: 1px solid black;
}
.row:after {
content: "";
display: table;
clear: both;
padding: 5px;
}
h2,
h3 {
text-align: center;
}
<body>
<h2 id="heading">Two Equal Columns</h2>
<div class="row">
<div class="column">
<iframe width="100%" src="https://www.youtube.com/embed/bjmYkPkjnVo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<h3>Ingredients</h3>
<ol>
<li>1 pound dry spaghetti</li>
<li>salt and freshly ground black pepper to taste</li>
<li>6 cloves garlic, sliced thin</li>
<li>1/2 cup olive oil (note: I prefer a regular olive oil for this recipe, as opposed to a strongly flavored extra virgin olive oil)</li>
<li>1/4 teaspoon red pepper flakes, or to taste</li>
<li>1/4 cup chopped Italian parsley</li>
<li>1 cup finely grated Parmesan cheese (highly recommend Parmigiano-Reggiano)</li>
<li>1 tablespoon of butter</li>
</ol>
</div>
<div class="column">
<iframe width="100%" src="https://www.youtube.com/embed/sAhUTzTJNaE" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<h3>Ingredients</h3>
<ol>
<li>500g of Pasta (cooked as per packet directions)</li>
<li>30g of Butter</li>
<li>4 Cloves of Minced Garlic (about 3-4 teaspoons)</li>
<li>1 1/2 Cups of Cream (about 400ml)</li>
<li>Salt and Pepper</li>
<li>1/2 Cup of Freshly Grated Parmesan Cheese</li>
<li>2 Teaspoons of Freshly Chopped Parsley (plus extra to garnish)</li>
</ol>
</div>
</div>
</body>
关于html - 列之间的CSS空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57317490/