Home > Blockchain >  How to space divs that are stacked on top of each other
How to space divs that are stacked on top of each other

Time:04-01

So, this is my code:

.headline {
  font-size: 61px;
  font-family: 'Gotham Pro Medium', sans-serif;
  /* font-weight: 700; */
  color: rgb(81, 83, 74);
  text-transform: uppercase;
  line-height: .9;
  -moz-transform: matrix( 0.99960015993603, 0, 0, 1.00025484199796, 0, 0);
  -webkit-transform: matrix( 0.99960015993603, 0, 0, 1.00025484199796, 0, 0);
  -ms-transform: matrix( 0.99960015993603, 0, 0, 1.00025484199796, 0, 0);
  /* position: absolute; */
  margin: auto;
  left: 61.909px;
  top: 230px;
  width: 490px;
  height: 55px;
  z-index: 11;
}
<div >WE BELIEVE</div>
<div >GREAT PEOPLE</div>
<div >DESERVE TOP</div>
<div >REWARDS.</div>
<div >Make your mark at RapidScale.</div>

In JSfiddle it looks a lot better than how it renders in my browser:

I am not sure why these produce different results, but basically I just want the lines to stack on top of each other instead of in-line. Can you please help me?

CodePudding user response:

Remove any absolute positioning. It's not needed. Nest the code in a wrapper and simplify it with flex. Specify flex-direction: column; then you can specify a gap for however much you want them spaced.

.headline {
  font-size: 61px;
  font-family: 'Gotham Pro Medium', sans-serif;
  color: rgb(81, 83, 74);
  text-transform: uppercase;
  line-height: .9;
  margin: auto;
  width: 490px;
  height: 55px;
  z-index: 11;
}

.wrapper {
  display: flex;
  flex-direction: column;
  gap: 2em;
}
<div >
  <div >WE BELIEVE</div>
  <div >GREAT PEOPLE</div>
  <div >DESERVE TOP</div>
  <div >REWARDS.</div>
  <div >Make your mark at RapidScale.</div>
</div>

CodePudding user response:

The issuer is caused by you setting position : absolute in both banner * {} and .headline {}. The presence of either causes the headlines to collapse to the same spot.

In this JSFiddle I was able to replicate the problem by adding position : absolute to div {}.

Replacing the position : absolute with position : relative for .headline {} should fix this issue, as demonstrated in this JSFiddle.

CodePudding user response:

You just need to update your .wrapper & .headline with my given css and it'll work perfectly.

.headline {
    position: relative;
    font-size: 61px;
    font-family: 'Gotham Pro Medium', sans-serif;
    color: rgb(81, 83, 74);
    text-transform: uppercase;
    line-height: .9;
    -moz-transform: matrix( 0.99960015993603,0,0,1.00025484199796,0,0);
    -webkit-transform: matrix( 0.99960015993603,0,0,1.00025484199796,0,0);
    -ms-transform: matrix( 0.99960015993603,0,0,1.00025484199796,0,0);
    left: 61.909px;
    top: 230px;
    width: 490px;
    height: 55px;
    z-index: 11;
}

.wrapper {
    position: relative;
    width: 1200px;
    height: 628px;
    overflow: hidden;
    border: solid 1px red;
    display: flex;
    flex-direction: column;
}
<div >
  <div >WE BELIEVE</div>
  <div >GREAT PEOPLE</div>
  <div >DESERVE TOP</div>
  <div >REWARDS.</div>
</div>

You can check my edit of your code here.

  • Related