Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force inline-block elements to wrap?

I have an inline-block div.

.element {
display: inline-block;
}

I use jquery to repeatedly append it to the DOM.

  var element = $("<div class='element'>");
  $(body).append(element).append(element).append(element).append(element);

However the appended divs do not wrap. It is as if I had the following mark-up (no newlines)

<div class="element"></div><div class="element"></div><div class="element"></div><div class="element"></div>

Appending whitespace inbetween the elements does not fix problem:

  $(body).append(element).append(" ");

How can I force these elements to wrap? (I do not want to use floats).

like image 244
user1031947 Avatar asked Jan 23 '13 19:01

user1031947


People also ask

Can inline elements wrap block level elements?

Inline elements cannot contain block level elements.

How do you make inline blocks not wrap?

We apply the white-space: nowrap; property to class “a” which keeps the line of text in the same line even if the screen size is small. Syntax: white-space: nowrap; Next, we apply white-space: normal; which is the default for “white-space”.

Can I give padding on inline?

When it comes to margins and padding, browsers treat inline elements differently. 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.

Does transform work on inline elements?

CSS transform doesn't work on inline elements.


1 Answers

If they are simply div elements set to inline-block they should wrap like so: http://jsfiddle.net/72cYy/

Check and be sure their container/parent element does not have a white-space:nowrap. That would cause them to not wrap.

like image 104
kyle.stearns Avatar answered Oct 14 '22 22:10

kyle.stearns