Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Haml with the inline-block spacing gaps

So I read the solutions regarding making the spacing go away when using inline-block as opposed to floats: display: inline-block extra margin and http://css-tricks.com/fighting-the-space-between-inline-block-elements/.

So if you're using haml and want to put the closing tag on the same line as the next opening tag, is there is a solution besides switching to ERB?

(and no, I don't want to mess with a css property of the parent container and have to override that in all the child elements).

This breaks (has spacing between the anchors).

So is it true that in spite of the recommendations to do such layouts using inline-block as opposed to floats, it seems that floats are still the way to go, especially when using 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>

Workaround (css-tricks one):

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

or

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

another one:

<ul>
  <li>one</li><!--
  --><li>two</li><!--
  --><li>three</li>
</ul>
like image 442
justingordon Avatar asked Jan 30 '13 20:01

justingordon


People also ask

How do you put a space between inline elements?

You can add space to the left and right on an inline element, but you cannot add height to the top or bottom padding or margin of an inline element. Inline elements can actually appear within block elements, as shown below. I've added white padding on the left and right side of each inline element.

Does margin working with inline block?

The block-direction margin on inline elements is ignored entirely. The padding on inline elements doesn't affect the height of the line of text.

What is the difference between inline and inline block?

The display: inline-block Value Compared to display: inline , the major difference is that display: inline-block allows to set a width and height on the element. Also, with display: inline-block , the top and bottom margins/paddings are respected, but with display: inline they are not.

How do you put a space between two blocks in CSS?

Margins - Outer Spacing It's used to add spacing between an element and another. For example, in the previous example, I added margin-bottom: 1rem to add vertical spacing between the two stacked elements.


1 Answers

I found the answer: http://haml.info/docs/yardoc/file.REFERENCE.html#whitespace_removal__and_

(this is a super useful article on the topic: http://designshack.net/articles/css/whats-the-deal-with-display-inline-block/)

Here's a codepen to experiment: http://cdpn.io/Bjblr

enter image description here

enter image description here

enter image description here

And this worked: enter image description here

enter image description here

Here's the html if the anchor text is on the same line (same result, but harder to read source html:

enter image description here

enter image description here

like image 144
justingordon Avatar answered Sep 28 '22 04:09

justingordon