Oscar Oscar - 1 year ago 60
CSS Question

Do you know why there is some white space between div yellow and gray?

Im a beginner in css, and Im trying to build something where I have the div with the yellow background a little bit in front of the red div and then I want the gray div next to the yellow div.

Im trying to achieve this with the code below, and it is already almost doing what Im looking for, the only thing that is happening that I dont want is that the gray div have a little white space between the yellow div, but Im not understanding why. And while Im resizing the browser the yellow div moves down and is no longer above the red div. Do you know why?



<div class="container" style="background-color:#e02; color:#fff;">
<div class="content">

<div class="container" style="background-color:#fff";>
<div class="content ">
<ul class="links">
<div class="text" style="background-color: #DDD;">
Go to this links and



*, *:before, *:after{
margin: 0;
padding: 0;

.container{float:left; width:100%}
.content{width:50%; margin:0 25%; padding: 40px 0}

width: 100%;
display: inline-block;

.links a{
padding: 30px;
float: left;
font-size: 16px;
font-weight: 600;
background: yellow;
margin-top: -10%;
border:1px solid #aaa;



Answer Source

An immediate fix to your problem can be done by changing .links

     width: 100%;
     display: block;

And adding

.text {
     clear: both;

Fiddle: https://jsfiddle.net/3jjv5zqe/

Why its happening is an inherited behaviour with the style inline-block.

See: Why is there an unexplainable gap between these inline-block div elements?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download