css-float - 使用具有行内 block 间距的 Haml

标签 css-float haml css

所以我阅读了有关在使用内联 block 而不是 float 时消除间距的解决方案:display: inline-block extra marginhttp://css-tricks.com/fighting-the-space-between-inline-block-elements/ .

因此,如果您使用的是 haml 并希望将结束标记与下一个开始标记放在同一行,那么除了切换到 ERB 之外还有其他解决方案吗?

(不,我不想弄乱父容器的 css 属性而不得不在所有子元素中覆盖它)。

这会中断( anchor 之间有间距)。

尽管建议使用内联 block 而不是 float 进行此类布局,但 float 似乎仍然是可行的方法,尤其是在使用 haml 时,这是真的吗?

CSS

nav a {
  display: inline-block;
  padding: 5px;
  background: red;
}

HTML

<nav>
  <a href="#">One</a>
  <a href="#">Two</a>
  <a href="#">Three</a>
</nav>

解决方法(css 技巧之一):

<ul>
  <li>
   one</li><li>
   two</li><li>
   three</li>
</ul>

<ul>
  <li>one</li
  ><li>two</li
  ><li>three</li>
</ul>

另一个:

<ul>
  <li>one</li><!--
  --><li>two</li><!--
  --><li>three</li>
</ul>

最佳答案

我找到了答案:http://haml.info/docs/yardoc/file.REFERENCE.html#whitespace_removal__and_

(这是一篇关于该主题的 super 有用的文章:http://designshack.net/articles/css/whats-the-deal-with-display-inline-block/)

这是一个用于实验的代码笔:http://cdpn.io/Bjblr

enter image description here

enter image description here

enter image description here

这奏效了: enter image description here

enter image description here

如果 anchor 文本在同一行,则为 html(结果相同,但源 html 更难阅读:

enter image description here

enter image description here

关于css-float - 使用具有行内 block 间距的 Haml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14612980/

相关文章:

css - 用具有自动边距的 div 填充 div (CSS)

html - css 中的边距是清除图像下空间的正确方法吗?

ruby-on-rails - 带有 HAML 的条件标签

css - 我如何更改元素样式高度

html - 标签的问题设置对齐

html - CSS float 清除问题

CSS:一个 div 中的多个内容?

Javascript HAML 引擎

javascript - 将 id 放置在 haml 线的中间

css - 在 Windows 8 应用程序中拖动内容超过滚动限制时如何禁用反弹?