html - 如何在同一列中的两个 DIV 之间留出空白

标签 html css

我有两个段落。这两段位于同一栏中。现在我的问题是我需要将这两个段落放在两个单独的框中,彼此向下。换句话说,两个盒子之间的间隙相互下降。

HTML代码

    <div class="sidebar">

                <div class="box1">
                    <p> 
                    Text is here
                    </p>
                </div>

                <div class="box2">
                    <p> 
                    Text is here 
                    </p>
                </div>

     </div>

我的CSS代码是

.sidebar {
    background: red;
    margin: 10px;
    padding: 0 7px 0 7px;
    width: 400px;
    border-radius: 10px;
}

.box1 {
    display: block;
    padding: 10px;
    margin-bottom: 30px;
    text-align: justify;
}

.box2 {
    display: block;
    padding: 10px;
    text-align: justify;
}

点赞这里 enter image description here

最佳答案

请注意2行后的评论。

.box1 {
    display: block;
    padding: 10px;
    margin-bottom: 100px; /* SIMPLY SET THIS PROPERTY AS MUCH AS YOU WANT. This changes the space below box1 */
    text-align: justify;
}

.box2 {
    display: block;
    padding: 10px;
    text-align: justify;
    margin-top: 100px; /* OR ADD THIS LINE AND SET YOUR PROPER SPACE as the space above box2 */
}

关于html - 如何在同一列中的两个 DIV 之间留出空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9248176/

相关文章:

html - div 高度取决于剩余空间

php - 导航未正确加载所有页面

html - 媒体查询最大宽度 320px 问题

php - div 和类未显示

php - 将 $_session ['username' ] 保存在 ajax 函数中

javascript - 无法在 react 组件内以html打印javascript变量文本

html - 使图像和段落并排放置

html - 在已经更改列表段的起始编号后,是否可以更改多级列表中的起始编号?

javascript - 使用 addClass() 时何时加载背景图像?

html - 如何只在最后一个盒子上设置边框半径?