How to remove the blank between div.sons?


Tags: html,css

Problem :

Three div.sons were put vertically with no blank between them. Here is the css code and displayed image.

<html>
<header>
<style type="text/css">
div.father {
  border: 1px solid black;
  height: 364px;
  width: 364px;

}
div.son {
  border: 1px solid black;
  height: 100px;
  width: 100px;
  padding-top:20px;
  padding-left:20px;
}
</style>

</header>
<body>
    <div class="father">
    <div class="son">box1</div> 
    <div class="son">box2</div>
    <div class="son">box3</div>
    </div>
</body>
</html>

enter image description here

There is no blank between div.sons for the vertically displayed div.son.

Now let's make all div.sons horizontally displayed.

<html>
<header>
<style type="text/css">
div.father {
  border: 1px solid black;
  height: 364px;
  width: 400px;

}
div.son {
  margin:0px;
  padding:0px;
  border: 1px solid black;
  height: 100px;
  width: 100px;
  padding-top:20px;
  padding-left:20px;
  display:inline-block;
}
</style>

</header>
<body>
    <div class="father">
    <div class="son">box1</div> 
    <div class="son">box2</div>
    <div class="son">box3</div>
    </div>
</body>
</html>

The displayed image is as the following.

enter image description here

How to remove all the blank between div.sons for the horizontally displayed image?



Solution :

One problem that arrises when you use inline-block is that whitespace in HTML becomes visual space on screen.

There are a few ways to remove that space

Like this: https://jsfiddle.net/j6rcfkmz/


    CSS Howto..

    How to change the mouse pointer?

    How to fade an image with CSS without opacity?

    How to apply css styles to a tag?

    How to set vertical align middle for a div enclose another div

    How to change background Image sizing

    How to “reset” a DOM subtree's CSS style?

    Need to show submenu to the right of it's parent item

    How can I place an element at the top of a page using CSS?

    How do I target nested elements with CSS correctly? [closed]

    CSS: How to align differently sized images in a line?

    How do I align these pictures vertically?

    Issue with CSS background image (Image not Showing)

    How can we wrap the line based on border size of windows browser?

    How to combine 2 SASS functions as they do almost the same thing just using a different calculation?

    CSS: How to position divs 2 by 2

    How to specify font-size for all bold text in the div?

    How to make a foreground image using CSS?

    How to create a two column layout

    How to get inner and outer width to a single element?

    zindex + jquery: How to make my menu appear over the jquery script?

    How to convert a CSS3 2D animatuon to a 3D Transform

    How to reorder DOM elements with CSS only?

    How to add css properties inside the PHP tag

    How to get floated divs align to the top?

    how to CSS center a div, which is the child of a form element?

    How to hide content that is not wrapped by tag using only CSS?

    Intellij IDEA 11: how can I compile .css from .less?

    how to center horizontally div and span elements using css

    How do I modify the Datatable header style in PF Dynamic Columns?

    How to position this div next to others?