Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made three boxes on my screen with the help of division tags with width 19%, 38%, 40% all of them add up to 97%. I want all of them to be side by side so I used display: inline-block and all of them act perfectly as I wish to like here: Edit fiddle - JSFiddle[^]

But the moment I add something in these division tags the boc moves down for no reason.


If I add something in right box : Edit fiddle - JSFiddle[^]

This happens the moment I add something do these boxes.

What I have tried:

<div class="wrapper-details-page">
    <div class="wrapper-details-page-left">  </div>
    <div class="wrapper-details-page-middle">  </div>
    <div class="wrapper-details-page-right">  </div>
</div>
CSS
.wrapper-details-page-left {
  border: 1px solid black;
  min-height: 600px;
  width: 19%;
  display: inline-block;
  margin: 0 0 0 0;
  padding: 0 0 0 0;
}

*{
  background-color: skyblue;
}

.wrapper-details-page-middle {
  border: 1px solid black;
  min-height: 600px;
  width: 38%;
  margin: 0 0 0 0;
  padding: 0 0 0 0;
  display: inline-block;
  background-color: pink;
}

.wrapper-details-page-right {
  border: 1px solid black;
  min-height: 600px;
  width: 40%;
  margin: 0 0 0 0;
  padding: 0 0 0 0;
  display: inline-block;
}
Posted
Updated 18-May-18 6:56am
v2

1 solution

Add vertical-align:top to your inline-block elements.
CSS
html,
body {
    background-color: skyblue;
}

.wrapper-details-page > div {
    border: 1px solid black;
    min-height: 600px;
    display: inline-block;
    vertical-align: top;
    margin: 0;
    padding: 0;
}

.wrapper-details-page-left {
    width: 19%;
}

.wrapper-details-page-middle {
    width: 38%;
    background-color: pink;
}

.wrapper-details-page-right {
    width: 40%;
}
Updated demo[^]

For modern browsers, you might want to consider using Flexbox for the layout:
CSS
@supports (display:flex){
    .wrapper-details-page {
        display: flex;
    }
    .wrapper-details-page > div:last-child {
        flex-grow: 1;
    }
}
Demo with Flexbox[^]
Progressively Enhancing CSS Layout: From Floats To Flexbox To Grid — Smashing Magazine[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900