0

Ok, here goes.

So I have 3 that are to represent 3 blocks of content next to each other.

I want them to scale to the browser whilst keeping their aspect ratio.

This is what I have so far:

.dash__node__container {
  padding: 1rem;
  width: 100%;
  padding-bottom: 75%;
  position: absolute;
 } 

.dash__node {
  width: 32.75%;
  height: 50px;
  display: inline-block;
  border: 1px solid #D8D8D8;
  position: relative;
}

And Html:

<div class="dash__node__container">
      <div class="dash__node"></div>
      <div class="dash__node"></div>
      <div class="dash__node"></div>
    </div>

This code isn't holding the aspect ratio and the third block jumps down to the next line.

EDIT: http://codepen.io/anon/pen/ogRyoO

Diginate
  • 17
  • 8

5 Answers5

0

I think you can add float:left; to dash__node class, and remove position:relative;

0

Remove the inline-block and add float:left

Erick
  • 823
  • 16
  • 37
0

That is because you use display: inline-block. Use float: left;

gorgi93
  • 2,457
  • 8
  • 30
  • 53
0

Use float: left; to keep the divs from breaking apart and use the padding-bottom trick instead of height to keep an aspect ratio.

* {
  box-sizing: border-box;
}

.dash__node__container {
  padding: 1rem;
  width: 100%;
  padding-bottom: 75%;
  position: absolute;
 } 

.dash__node {
  float: left;
  width: 32.75%;
  padding-bottom: 10%;
  border: 1px solid #D8D8D8;
  position: relative;
}
Tyler Sloan
  • 246
  • 1
  • 2
  • 9
0

You could use float:left but another alternative is to have font-size:0 in your wrapper. This eliminates the space between your blocks. Obviously you'll then need to apply a font size to your child nodes. More info here.

The third block element falls below at smaller screen sizes because you have padding on your wrapper. Applying box-sizing:border-box;to all your divs will sort this. More on that here.

Here's a fiddle with the above applied: https://jsfiddle.net/nf7wsmk4/

Matthew Allen
  • 791
  • 9
  • 19
  • There was time when I also use `font-size:0` to achieve desire effect. but there are some drawbacks of using. may be some senior people can show some light why not to use `font-size:0` – Kheema Pandey Apr 07 '15 at 16:11
  • In the link I added it mentions that this will have issues on Android devices if they are pre-Jellybean OR if you're sizing your fonts using ems. – Matthew Allen Apr 07 '15 at 16:13