user3137875
user3137875

Reputation:

Having a hard time with a blank space between divs

A client of mine asked me to take his code and make it responsive; He used to display his news in 2 column divs (left-side / right-side) and for responsiveness sake's I had to get rid of those 2 columns and put all of the news next to each others, but I'm getting a blank space between rows (2nd news width's is pushing 3rd new away)

This is what the html looks like

<main>
<article class="news">blabla</article>
<article class="news">blabla</article>
<article class="news">blabla</article>
<article class="news">blabla</article>
</main>

And this is the css

.news {
width: 335px;
background: #F0EEFF;
display: inline-block;
padding:.3em 0;
padding-left: 0.3em;
vertical-align: top;

}

See it for yourself

.noticia {
	width: 335px;
	background: #F0EEFF;
	display: inline-block;
	padding:.3em 0;
	padding-left: 0.3em;
  vertical-align: top;
}


.noticia>img, .noticia .video, .noticia iframe {
	width: 335px;
	max-width: 99%;
}
		<main> <!-- modulo de notas -->
			<article class="noticia">
				<h6 class="categoria">Internacional</h6>
				<h2>El ministro de economía español visitará este miércoles el pais</h2>
				<img src="images/noticia4.png">
				<div class="bajada">bajada bajada bajada bajadabajada bajadabajada bajada</div>
				<div class="texto-noticia"><p>Será luego de 5 años de ausencia, se reunirá con otros ministros en la casa Rosada</p></div>
				<div>	
				<img src="images/AUDIO.png">
				</div>
				<div class="comentarios">Dejar un comentario - Leer más...<a href="http://www.facebook.com"><img src="images/face.png"></a>   <a href="http://www.twitter.com"><img src="images/twitter.png"></a></div>
				<hr>
			</article>
			<article class="noticia">
				<h6 class="categoria">Internacional</h6>
				<h2>El ministro de economía español visitará este miércoles el pais</h2>
				<img src="images/noticia4.png">
				<div class="texto-noticia"><p>Será luego de 5 años de ausencia, se Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
				tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
				quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
				consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
				cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
				proident, sunt in culpa qui officia deserunt mollit anim id est laborum.reunirá con otros ministros en la casa Rosada</p></div>
				<div class="comentarios">Dejar un comentario - Leer más...<a href="http://www.facebook.com"><img src="images/face.png"></a>   <a href="http://www.twitter.com"><img src="images/twitter.png"></a></div>
				<hr>
				<aside class="banner">
				<img src="images/banner1.png"></img>
				</aside>
			</article>
			<article class="noticia">
				<h6 class="categoria">Internacional</h6>
				<h2>El ministro de economía español visitará este miércoles el pais</h2>
				<img src="images/noticia4.png">
				<div class="texto-noticia"><p>Será luego de 5 años de ausencia, se reunirá con otros ministros en la casa Rosada</p></div>
				<div class="comentarios">Dejar un comentario - Leer más...<a href="http://www.facebook.com"><img src="images/face.png"></a>   <a href="http://www.twitter.com"><img src="images/twitter.png"></a></div>
				<hr>
				<aside class="banner">
					<object width="100%" height="104.53125">
          			<param name="src" value="http://www.supropiositio.com/04-2015/3df40c4be1bd964ca95f9250b5a5f504.swf">
         			 <embed src="http://www.supropiositio.com/04-2015/3df40c4be1bd964ca95f9250b5a5f504.swf" pluginspage="http://www.adobe.com/shockwave/download/" width="100%" height="104.53125">
      				</object>
				</aside>
			</article>
			<article class="noticia">
				<h6 class="categoria">Internacional</h6>
				<h2>El ministro de economía español visitará este miércoles el pais</h2>
				<img src="images/noticia4.png">
				<div class="video"><iframe src="https://www.youtube.com/embed/qGsTlYLbwy4" frameborder="0" allowfullscreen></iframe>
        	</div>
				<div class="texto-noticia"><p>Será luego de 5 años de ausencia, se reunirá con otros ministros en la casa Rosada</p></div>
				<div class="comentarios">Dejar un comentario - Leer más...<a href="http://www.facebook.com"><img src="images/face.png"></a>   <a href="http://www.twitter.com"><img src="images/twitter.png"></a></div>
				<hr>
				<aside class="banner">
				<img src="images/banner1.png"></img>
				</aside>
			</article>
		</main>

Thanks!

Upvotes: 1

Views: 68

Answers (2)

ThemesCreator
ThemesCreator

Reputation: 1759

This is the normal way divs works. The next div start where the last end. In your case, the 3rd div will start always at the bottom of the second div, so its position depends on the length of the last div.

The most aproximate solution with only CSS is the CSS3 columns properties:

main {
   -webkit-column-count: 2;
   -moz-column-count: 2;
   column-count: 2;
   -webkit-column-width: 335px;
   -moz-column-width: 335px;
   column-width: 335px;
}
.noticia {
    background: #F0EEFF;
    padding:.3em 0;
}

But this will order the elements top-to-bottom, and not left-to-right like the user usually expect.

So, if the items order has to be left-to-right you need to use a javascript solution like Masonry.

Upvotes: 1

Peyman Mohamadpour
Peyman Mohamadpour

Reputation: 17944

There are 4 ways to remove that white space gap, when using display: inline-block:

<main>
    <article class="news">blabla</article><article class="news">blabla</article><article class="news">blabla</article>
</main>

<main>
    <article class="news">blabla</article><article class="news">
    blabla</article><article class="news">
    blabla</article>
</main>

<main>
    <article class="news">blabla</article
    ><article class="news">blabla</article
    ><article class="news">blabla</article>
</main>

<main>
    <article class="news">blabla</article><!--
    --><article class="news">blabla</article><!--
    --><article class="news">blabla</article>
</main>

Upvotes: 0

Related Questions