html - 是什么导致了两个元素之间的这个空间,我该如何摆脱它?

标签 html css

这是我正在尝试做的事情的蓝图:

screenshot of problem

我正试图摆脱这个丑陋的空间,但我不确定它来自哪里。

HTML:

<div class="balance">
        <h3 id="balance"><img id="bitcoin" src=Images/bitcoin.png width="25px" height="25px"> Balance: Loading...</h3>
</div>

<div class="gamebox">
       <!--- Game box markup code --->
</div>

平衡面板的 CSS:

/* Balance box */
.balance{
    height: 10%;
    margin: 20px;
    width: 30%;
    font-family: "smooth";
    background-color: white;
    color: black;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    float: right;
}

主游戏面板的 CSS:

/* Game box */
.gamebox{
    height: auto;
    margin: 20px;
    padding: 20px;
    width: 50%;
    font-family: "smooth";
    background-color: white;
    color: black;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    display:inline-block;
}

是什么造成了空间?我希望两个面板之间不要有这么大的差距。

最佳答案

将平衡盒(和/或游戏盒)的 css 中的“边距”属性更改为较小的数字。如果您仍想保留上下空间,请像这样指定边距:

.balance {
    margin-top: 20px;
    margin-bottom: 20px;
    margin-left: 0px;
    margin-right: 0px;

   /*other code*/
    height: 10%;
    width: 30%;
    font-family: "smooth";
    background-color: white;
    color: black;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    float: right;
}

宽泛地说,边距是html中div(或任何对象)周围的空间

编辑:我忽略了您将 balance div 向右浮动的情况。在 css 中,我将两个 div 都指定为内联 block (因此它们并排放置),并将 gamebox div 指定为向左浮动

 /* Balance box */
.balance{
    height: 10%;
    margin: 20px;
    width: 30%;
    font-family: "smooth";
    background-color: white;
    color: black;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    display: inline-block;
}

.gamebox{
    float: left;
    height: auto;
    margin: 20px;
    padding: 20px;
    width: 50%;
    font-family: "smooth";
    background-color: white;
    color: black;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    display:inline-block;
}

关于html - 是什么导致了两个元素之间的这个空间,我该如何摆脱它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45393657/

相关文章:

javascript - 多个下拉菜单重定向到 URL ( HTML )

javascript - Bootstrap 3 子模态?

css - 我们如何将图像放在另一个图像之上

html - 为什么我不能将一个 div 放在另一个 div 的下面?

html - 如何从分页项中移动文本

html - 设计具有不同值属性和显示文本的下拉列表

css - 标题、图表和文本的响应式布局(纵向与横向)

html - 如何使用 CSS flex 使元素占据页面的 100% 并将元素居中?

html - .class :nth-child(even) not working?

html - 更改 Bootstrap 4 复选框背景颜色