I have list of images. I want to put a line break after the second image using CSS. I have used a CSS trick listed below but it doesn't work for the inline-block elements. It only works for display inline elements
Code that working for inline Elements.
HTML
<div>
<a href="#">Dummy Link</a>
<a href="#">Dummy Link</a>
<a href="#">Dummy Link</a>
<a href="#">Dummy Link</a>
</div>
<div>
<img src="http://placehold.it/50X50" />
<img src="http://placehold.it/50X50" />
<img src="http://placehold.it/50X50" />
<img src="http://placehold.it/50X50" />
</div>
CSS
a:nth-of-type(2):after
{
white-space: pre;content:'\A';
}
img:nth-of-type(2):after
{
white-space: pre;content:'\A';
}
If I am using img element which is display:inine-block by default. The above CSS does not working for it.
Check below fiddle for example
http://jsfiddle.net/murli2308/dD52z/1/
Please let me know if there any way of doing it
Note - I cannot change the HTML structure as it is coming through database.
A line-break can be added in HTML, using only CSS, by employing the pseudo-class ::after or ::before . In the stylesheet, we use these pseudo-classes, with the HTML class or id, before or after the place where we want to insert a line-break. In myClass::after : Set the content property to "\a" (the new-line character).
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.
The <br> tag inserts a single line break. The <br> tag is useful for writing addresses or poems.
You cannot use :after pseudo elements with <img>
tag. This is because pseudo elements work only with double tags. For achieving the desired result you can give <br>
tag after each <img>
and style the <br>
instead.
<div>
<a href="#">Dummy Link</a>
<a href="#">Dummy Link</a>
<a href="#">Dummy Link</a>
<a href="#">Dummy Link</a>
</div>
<div>
<img src="http://placehold.it/50X50" />
<br>
<img src="http://placehold.it/50X50" />
<br>
<img src="http://placehold.it/50X50" />
<br>
<img src="http://placehold.it/50X50" />
<br>
</div>
And in the css you can style the <br>
tag like this:
a:nth-of-type(2):after
{
white-space: pre;content:'\A';
}
br{
display: none;
}
br:nth-of-type(2){
display:block;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With