如何在CSS/HTML中给按钮之间添加换行?

3
我有一系列的2个按钮,竖直排列。它的图片表示如下:

Buttons

这些按钮的HTML代码如下:
<ul class="child">
                        <!-- ko foreach: subTabs -->
                        <li class="color-dark child active" data-bind="css: {active: $data.selected()}, click: select">
                            <span data-bind="text: i18n($data.title) ">Current coverage</span>
                        </li>

                        <li class="color-dark child" data-bind="css: {active: $data.selected()}, click: select">
                            <span data-bind="text: i18n($data.title) ">Coverage history</span>
                        </li>
                        <!-- /ko -->
                    </ul> 

我正在使用的用于合并按钮的 CSS 代码如下:

  @media screen and (max-width: 767px) and (min-width: 320px)
    div.default.tabs ul.child:first-child {
        background-color: #6f7992;
        display: flex;
        justify-content: center;
        flex-direction: column;
        margin-left: 20px;
        width: auto;
    }

    div.default.tabs ul.child:first-child {
        background-color: #6f7992;
        display: table;
        width: auto;
    }
    .default.tabs ul.child:first-child {
        margin: 0px 20px 2px 0;
        padding: 0;
        width: auto;
    }

我将使用以下CSS代码来设置单个按钮样式:
```css ``` 请注意,此处是空白的CSS代码块,您需要将所需的CSS样式放入其中。
    @media screen and (max-width: 767px) and (min-width: 320px)
    div.default.tabs ul.child:first-child li.child.active {
        color: #0b710c !important;
        background-color: #658B01 !important;
    }
    div.default.tabs ul.child:first-child li.child.active {
        color: #0b710c !important;
        background-color: #dbefb1 !important;
    }
    .benefits.header .inner.current span, .default.tabs ul.child:first-child li.child.active {
        font-weight: bold;
        color: #0074ff;
    }
    .default.tabs ul.child:first-child li.child.active {
        background: url(img/tabs-arrow.png) no-repeat bottom center;
        padding-top: 14px;
        padding-bottom: 15px;
        border: 0;
    }
    @media screen and (max-width: 767px) and (min-width: 320px)
    .default.tabs ul.child:first-child li.child, .default.tabs ul.child:first-child li.child.active {
        border-left: 0px !important;
        display: table-cell;
        position: relative;
    }
    .default.tabs ul.child:first-child li.child, .default.tabs ul.child:first-child li.child.active {
        border-left: 3px solid #fff !important;
        display: table-cell;
        position: relative;
    }
    .default.tabs ul.child:first-child li.child.active {
        background: url() !important;
    }
    .default.tabs ul.child:first-child li.active.child {
        padding-left: 3px;
        padding-right: 3px;
    }
    .default.tabs ul.child:first-child li.child {
        padding: 14px 0;
        list-style-type: none;
        display: table-cell;
        color: #182e5b;
        font-size: 16px;
        min-width: 160px;
        text-align: center;
        cursor: pointer;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
         -ms-user-select: none;
        user-select: none;
}

我的任务是以以下方式在两个按钮之间添加换行符:

enter image description here

我尝试更改display属性的值,但仍然无法在按钮之间产生换行符。


1
没有配套的HTML,CSS几乎是无用的。请编辑您的问题以包含它。 - Tyler Roper
1
添加底部边距。 - hungerstar
Santi,我已经包含了HTML代码。 - user5447339
按钮边距仅增加按钮的宽度。 - user5447339
3个回答

2
给第一个按钮添加margin-bottom属性。

我尝试过,但它只增加了按钮的宽度。您能告诉我在代码的哪个部分要包含margin-bottom吗? - user5447339
<li class="color-dark child active" style="margin-bottom:2px" data-bind="css: {active: $data.selected()}, click: select"> <span data-bind="text: i18n($data.title) ">当前覆盖率</span> </li> - DonaJose

0
您可以为第一个按钮添加margin-bottom属性,例如:
button1 { margin-bottom: 5px; }

你可能还需要添加一个 display: block,因为默认情况下 span 标签是内联元素,而内联元素不受上/下边距的影响。

0
首先,如果你想使用媒体查询,你应该用大括号来包裹它们,像这样:
 @media screen and (max-width: 767px) and (min-width: 320px){
 /*CSS here*/
 }

这里有一个fiddle,其中包含您需要的基本内容,您可以使用margin进行测试。


非常抱歉。我在实际代码中使用了括号中的媒体查询,但在这里粘贴时粘贴错误了。只是一个简单的问题,为什么仅使用margin-bottom会增加网页上按钮的宽度,但不会有白色换行符? - user5447339
我认为 margin-bottom 不会增加按钮的 width。它是由 paddingwidth 属性增加的,而不是由 margin 增加。你可以看到我的例子,如果你移除 margin-bottom,按钮的宽度不会改变。@user5447339,可以像我一样创建一个 fiddle,并展示你的 margin 如何增加宽度的具体问题。 - Iván Rodríguez Torres

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接