Browser screen size content

Asked

Viewed 146 times

0

On many portfolio sites, we can see sections (usually with images) that take up the exact space of the user’s browser, such as this site here.

I searched but did not find anywhere how to accomplish this effect of maintaining several sections of the same browser size. How can I develop something similar using CSS3 and Jquery?

1 answer

2


To ensure that a section uses the whole width of the browser can do so:

section {
    float: left;
    clear: both;
    width: 100%;
    height: 200px; // caso queira defenir a altura via CSS e não pela quantidade de conteúdo
}

Starting from the presuposto who is a direct descendant of the body or what his relative has width: 100%; also, without padding or margin.

To ensure that every Section uses full screen height you can use CSS (in modern browsers) with Viewport height:

section {
    height:100vh;
}

Or use jQuery:

$('section').css('height', $(window).height() + 'px');

And to ensure that all the space is used you need to reset the margins. At least it would be:

body {
    margin: 0px;
    padding: 0px;
}

Example: http://jsfiddle.net/09xfjswo/1/show/

(withdraw the /show/ url to view code)

  • in the example you gave, the sections are not occupying the space of the browser... I am using Chrome

  • @Is that how you want it? http://jsfiddle.net/09xfjswo/1/show/

  • Got it! The width of the sections are equivalent to that of the browser. And to put the browser height in the sections?

  • 1

    @Vinicius added to the answer. But it means it wants the height of the window size?

  • 1

    Exactly Sergio! With this code you put in the answer, can you then have an effect similar to the example of the question? Are these best practices? Is there a problem of cross-browsers?

Browser other questions tagged

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