Position div across the screen

Asked

Viewed 114 times

1

I’m creating a home and want to position a div (with a background image) across the visible screen when the page loads. I did it this way:

.home-entrada{
    position: absolute;
    bottom: 0;
    top: 0;
    width: 100%;
}

It works perfectly, but the problem is that there is still content to be shown below, and this content is superimposed on this div, since it has position Absolute. I’ve thought about creating a relative and putting Absolute inside, but how would I leave the relative top: 0 and bottom: 0?

Image with the height:100%; and position: relative;. OBS: body and html com height: 100% also. The site is all bugged up so I’m reforming it yet...

  • perhaps it lacks: height:100%, withdraw the bottom:0 and put left:0

  • I have tried height: 100%; continue overwriting. NOTE: the content below is in a div position: relative;

  • try it z-index:9999999;

  • It’s not that, I want the content to go down, and not to disappear behind the div haha. Also, there’s a Nav at the top too, there’s no way....

1 answer

1


if you define a height: 100% to the html and body, you can define a height: 100% for your div.home-entrada without having to define a position: absolute.

html, body {
  position: relative;
  width: 100%;
  height: 100%;
  margin: 0px;
  padding: 0px;
}

#capa {
  width: 100%;
  height: 100%;
}

#capa {
  position: relative;
  background-color: royalblue;
  margin-bottom: 5px;
  box-shadow: 0px 0px 5px black;
}

#icon {
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 196px;
  width: 196px;
}

#icon rect, #icon path {
  fill: white;
}
<div id="capa">
  <svg id="icon" version="1.1" x="0px" y="0px" width="438.53px" height="438.529px" viewBox="0 0 438.53 438.529" style="enable-background:new 0 0 438.53 438.529;" xml:space="preserve">
      <rect x="42.532" y="191.573" width="353.458" height="72.803"/>
      <path d="
               M42.529,284.648v18.843c0,16.173,5.474,29.93,16.418,41.251c10.944,11.32,24.128,16.987,39.543,16.987h151.039v76.8    
               l74.227-76.8h16.282c15.414,0,28.603-5.66,39.547-16.987C390.529,333.421,396,319.664,396,303.491v-18.843H42.529z
               "/>
      <rect x="42.532" y="97.927" width="353.458" height="72.802"/>
      <path d="
               M395.991,57.956c0-15.988-5.469-29.643-16.413-40.968S355.448,0,340.031,0H98.493C83.078,0,69.894,5.662,58.95,16.988    
               S42.532,41.971,42.532,57.956v19.126h353.458V57.956z
               "/>
  </svg>
</div>
<div id="lipsum">
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. In rutrum nisl blandit condimentum porta. Nulla facilisi. Proin finibus vitae diam et blandit. Curabitur ut suscipit ante, at sollicitudin neque. Etiam dignissim auctor lectus non luctus. Donec tempor mauris lorem, a porttitor elit cursus in. Suspendisse aliquet faucibus quam, vel vulputate velit. Ut sit amet molestie urna. Donec laoreet dolor at ullamcorper consectetur. Vivamus consectetur tortor eu elit lacinia sagittis.
  </p>
  <p>
    Ut interdum, turpis nec eleifend varius, nibh neque suscipit massa, nec ornare elit sem ac augue. Mauris id urna fringilla, aliquet urna quis, varius justo. Phasellus vulputate tellus sed lorem sodales iaculis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus porta, nunc molestie congue viverra, velit lectus vulputate diam, id fringilla dui mauris molestie leo. Sed sed placerat ante. Ut tincidunt odio et urna pretium eleifend. Phasellus tempor sagittis eros eu pellentesque. Sed mollis dapibus est. Vestibulum mattis turpis neque, eget ullamcorper nibh dictum sit amet. Integer quis arcu molestie, suscipit purus ut, vulputate ex. Praesent eu pretium urna, non blandit est.
  </p>
  <p>
    Vivamus suscipit maximus sollicitudin. In congue aliquam sem, non rhoncus orci commodo scelerisque. Sed ac velit auctor, porta libero id, convallis ante. Maecenas non mollis nisl. Vestibulum tristique magna a dolor elementum ultricies. Cras tellus tellus, finibus vel semper a, sagittis efficitur metus. Vestibulum pretium, leo sit amet volutpat feugiat, est turpis tincidunt tortor, eget mollis quam nulla eget ante. Donec et imperdiet ipsum. Fusce sed quam sit amet lorem tincidunt bibendum eget eget sem. Suspendisse leo augue, suscipit eu posuere non, imperdiet sit amet erat. In sit amet convallis velit. Donec dui leo, fringilla non dignissim id, vestibulum nec tellus.
  </p>
  <p>
    Vivamus bibendum metus ut erat tincidunt pulvinar. Proin lectus libero, bibendum iaculis dolor sed, sagittis iaculis elit. Nulla sit amet commodo lorem. Sed eget vehicula orci, non pulvinar magna. Nam malesuada ullamcorper nunc, eu tincidunt augue gravida non. Vestibulum quis diam ipsum. Ut sem eros, auctor ac libero at, viverra aliquam nisl. Mauris ultrices leo vitae dolor euismod malesuada. Sed eget tellus enim. Vivamus sodales commodo dapibus. Aliquam massa diam, placerat eget gravida sit amet, lacinia quis turpis. Donec a accumsan massa. Curabitur fringilla risus vel viverra feugiat. Nunc nunc ex, congue et fringilla nec, euismod eget nulla. Aenean tempus vehicula eros, at feugiat lorem viverra sed.
  </p>
  <p>
    Nam finibus purus tellus, sit amet dictum turpis consectetur sit amet. Ut rhoncus odio quis mollis sagittis. Cras venenatis ante a quam interdum malesuada. Aenean facilisis auctor arcu ut congue. Etiam lacinia, diam vel blandit bibendum, lorem mi suscipit dui, a dignissim ex mauris a sapien. Curabitur ut varius quam, a sodales risus. Nunc iaculis dui non lorem ullamcorper pellentesque. Phasellus nec blandit ligula. Quisque pellentesque lobortis est. Nam feugiat efficitur turpis, aliquam congue quam viverra nec. Nulla ornare at metus vitae commodo.
  </p>
</div>

  • But I never got it, but it’s because I didn’t put the height 100% in body and html.

  • I did just like that, but it didn’t work:

  • @Insanity what error is giving, or what is happening following @Tobymosque’s solution?

  • It just doesn’t get 100% height; I put picture in problem...

  • 1

    @Insanity remembering that the height: 100% is in relation to parentElement, the above technique works because the html and the body has height: 100% and the div.capa is directly within the body.

  • 1

    It worked, had a div called all inside a include (from Navegation) haha, and I hadn’t seen it. It’s an old site I did, now I’m doing maintenance. It has a lot to be organized yet haha... Thanks!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.