html - 新行上的组件将保持其 margin-left,导致 css 中的丑陋结果

标签 html css less atom-editor

我正在调试 Atom 编辑器,一位用户报告说,如果窗口太小,按钮会奇怪地堆叠。

请注意,在 Atom 中,人们可以编写插件,并且每个插件的标记都不同。

<div class="btn-toolbar">
    <div class="btn-group">
        <button class="btn">One</button>
        <button class="btn">Two</button>
        <button class="btn">Three</button>
    </div>
    <div class="btn-group">
        <button class="btn">Four</button>
        <button class="btn">Five</button>
    </div>
    <button class="btn">Six</button>
    <button class="btn">Seven</button>
</div>

Example

我已经为该元素的所有直接子元素添加了 margin-bottom,解决了部分问题。请参阅下面的 .less

@import 'ui-variables';

.btn-toolbar > * {
    // @component-padding is 10px, for the people who don't know less.
    margin-bottom: @component-padding/2;     
}

enter image description here

但是,如您所见,第二行仍有一些不应该出现的空格。它是 .btn-group 的左边距(按钮也有这个,但只有 .btn-group 元素在图像中显示为行为不当)。

有什么办法可以消除这个边距吗?我用谷歌搜索选择任何换行符,但我发现的只是 ::first-line 伪类。这显然在这里没有用。

最佳答案

您是否尝试过nth-of-type 伪类?

要定位第二个 .btn-group,您可以使用如下内容:

div.btn-group:nth-of-type(2) {
    margin-left: 0;
}

因为你不能使用 nth-of-type 你的情况的最佳解决方案是删除 margin-left 并只使用 margin-right .btn-group

关于html - 新行上的组件将保持其 margin-left,导致 css 中的丑陋结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24581849/

相关文章:

css - Dojo - 在 domConstruct.create() 中提供多个类名

css - 客户端 LESS 没有使用我写的样式

javascript - 如何在.net MVC 中动态事件导航菜单?

c# - 使用 C# 编辑 HTML

asp.net - 输入复选框描述单击不适用于 Mozilla 和 Internet Explorer 10

javascript - 使砌体画廊在表格单元格 div 内工作?

Javascript 固定页脚覆盖焦点

node.js - 使用 Node 和 makefile 使用 LESS 编译 Bootstrap

html - 如何为 div 添加外圆 Angular ?

html - 在 Quiz Angular 5 中处理多个单选按钮