How to set margin-top of window size?

I want to place divusing CSS right after the current window (i.e. when you start scrolling, you will see it).

Seems trivial and I tried

#content {
    margin-top: 100%;
}

Jsfiddle

But it does not work, and the field does not accept the height of the current window.

+4
source share
1 answer

Solutions:

  • You can achieve your goal using position:absolute;and FIDDLEtop:100%;
  • the second option is to add the c element to height:100%;the "push" .contentdown FIDDLE

Explanation:

, margin-top (, margin-bottom padding-top/bottom) . .

CSS:

body,html {
    background-color: lightblue;
    height:100%;
    width:100%;
    margin:0;
}

#content {
    position:absolute;
    top: 100%;
    background-color: lightgrey;
}

2:

HTML:

<div id="push"></div>
<div id="content">
    <p>... content ...</p>
</div>

CSS:

body,html {
    background-color: lightblue;
    height:100%;
    width:100%;
    margin:0;
}
#push{
    height:100%;
}

#content {
    background-color: lightgrey;
}
+5

Source: https://habr.com/ru/post/1535906/


All Articles