Development Tip

div가 컨테이너 내의 영역 대신 전체 페이지를 덮도록 허용

yourdevel 2020. 10. 13. 19:29
반응형

div가 컨테이너 내의 영역 대신 전체 페이지를 덮도록 허용


반투명 div가 전체 화면을 덮도록 만들려고합니다. 나는 이것을 시도했다 :

#dimScreen
{
    width: 100%;
    height: 100%;
    background:rgba(255,255,255,0.5);
}

그러나 그것은 전체 화면을 포함하지 않고 div 내의 영역 만 포함합니다.


추가 position:fixed. 그런 다음 스크롤 할 때도 전체 화면에 표지가 고정됩니다.
그리고 margin: 0; padding:0;덮개 주위에 약간의 공간이 없도록 추가 할 수도 있습니다 .

#dimScreen
{
    position:fixed;
    padding:0;
    margin:0;

    top:0;
    left:0;

    width: 100%;
    height: 100%;
    background:rgba(255,255,255,0.5);
}

고정 된 화면에 달라 붙지 않으면 position:absolute;

CSS Tricks 에는 전체 화면 속성에 대한 흥미로운 기사도 있습니다.

편집 :
방금이 답변을 보았으므로 몇 가지 추가하고 싶었습니다. 댓글에서 언급 한 Daniel Allen Langdon
처럼 커버는 화면의 맨 위와 왼쪽에 붙어 있습니다.top:0; left:0;

일부 요소가 표지의 맨 위에있는 경우 (모든 항목을 포함하지는 않음) z-index. 숫자가 높을수록 더 많은 레벨을 포함합니다.


부모 요소도 다음과 100%같이 설정해야합니다.

html, body {
    height: 100%;
}

데모 (background데모 용으로변경됨)


또한 전체 화면을 가리고 싶을 때하고 싶을 것 같기 dim때문에이 경우에는position: fixed;

#dimScreen {
    width: 100%;
    height: 100%;
    background:rgba(255,255,255,0.5); 
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100; /* Just to keep it at the very top */
}

그렇다면 필요하지 않은 것보다 html, body {height: 100%;}

데모 2


이것은 트릭을 할 것입니다!

div {
  height: 100vh;
  width: 100vw;
}

사용 position:fixed하여 사업부는 지속적으로 전체 볼 수있는 영역에 걸쳐 유지됩니다 이런 식으로 ..

div에 클래스를 제공 overlay하고 CSS에 다음 규칙을 만듭니다.

.overlay{
    opacity:0.8;
    background-color:#ccc;
    position:fixed;
    width:100%;
    height:100%;
    top:0px;
    left:0px;
    z-index:1000;
}

데모 : http://www.jsfiddle.net/TtL7R/1/


#dimScreen{
 position:fixed;
 top:0px;
 left:0px;
 width:100%;
 height:100%;
}

이 시도

#dimScreen {
    width: 100%;
    height: 100%;
    background:rgba(255,255,255,0.5);
    position: fixed;
    top: 0;
    left: 0;
}

CSS 재설정을 적용하여 이와 같은 모든 여백과 패딩을 재설정하십시오.

/* http://meyerweb.com/eric/tools/css/reset/ 

v2.0 | 20110126 라이선스 : 없음 (퍼블릭 도메인) * /

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

필요에 따라 다양한 CSS를 사용할 수 있습니다.

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

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

html 및 body 태그 height를로 설정하고 본문 100%주변의 여백을 제거합니다.

html, body {
    height: 100%;
    margin: 0px; /* Remove the margin around the body */
}

이제 positiondiv를 fixed다음 과 같이 설정하십시오 .

#dimScreen
{
    width: 100%;
    height: 100%;
    background:rgba(255,255,255,0.5);

    position: fixed;
    top: 0px;
    left: 0px;

    z-index: 1000; /* Now the div will be on top */
}

데모 : http://jsfiddle.net/F3LHW/


본문에 여백과 패딩을 0으로 설정하여 시도하십시오.

<body style="margin: 0 0 0 0; padding: 0 0 0 0;">

참고 URL : https://stackoverflow.com/questions/18588835/allow-a-div-to-cover-the-whole-page-instead-of-the-area-within-the-container

반응형