Estou tentando fazer um div semitransparente cobrir a tela inteira. Eu tentei isso:
#dimScreen
{
width: 100%;
height: 100%;
background:rgba(255,255,255,0.5);
}
Mas isso não cobre a tela inteira, cobre apenas a área dentro do div.
Estou tentando fazer um div semitransparente cobrir a tela inteira. Eu tentei isso:
#dimScreen
{
width: 100%;
height: 100%;
background:rgba(255,255,255,0.5);
}
Mas isso não cobre a tela inteira, cobre apenas a área dentro do div.
Respostas:
Adicionar position:fixed. Em seguida, a capa é fixada em toda a tela, também quando você rola.
E adicione talvez também margin: 0; padding:0;para não ter algum espaço ao redor da capa.
#dimScreen
{
position:fixed;
padding:0;
margin:0;
top:0;
left:0;
width: 100%;
height: 100%;
background:rgba(255,255,255,0.5);
}
E se não deve ficar na tela fixa, use position:absolute;
CSS Tricks também tem um artigo interessante sobre propriedade de tela cheia.
Edit:
Acabei de encontrar esta resposta, então eu queria adicionar algumas coisas adicionais.
Como Daniel Allen Langdon mencionou no comentário, acrescente top:0; left:0;para ter certeza, a capa gruda no topo e à esquerda da tela.
Se alguns elementos estiverem no topo da capa (portanto, ela não cobre tudo), adicione z-index. Quanto maior o número, mais níveis ele cobre.
top: 0; left: 0;
Você precisa definir o elemento pai para 100%também
html, body {
height: 100%;
}
Demo (alteradobackgroundpara fins de demonstração)
Além disso, quando você deseja cobrir a tela inteira, parece que você deseja dim, então, neste caso, você precisa usarposition: 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 */
}
Se for esse o caso, então você não precisa html, body {height: 100%;}
position:relative. Isso não vai funcionar. Em position:fixedvez disso, sugira .
Isto irá fazer o truque!
div {
height: 100vh;
width: 100vw;
}
Use position:fixeddesta forma que seu div permanecerá em toda a área visível continuamente.
dê uma classe ao seu div overlaye crie a seguinte regra em seu CSS
.overlay{
opacity:0.8;
background-color:#ccc;
position:fixed;
width:100%;
height:100%;
top:0px;
left:0px;
z-index:1000;
}
Tente isto
#dimScreen {
width: 100%;
height: 100%;
background:rgba(255,255,255,0.5);
position: fixed;
top: 0;
left: 0;
}
Aplique um css-reset para redefinir todas as margens e preenchimentos como este
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126 Licença: nenhuma (domínio público) * /
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;
}
Você pode usar várias redefinições css conforme necessário, normal e usar em css
html
{
margin: 0px;
padding: 0px;
}
body
{
margin: 0px;
padding: 0px;
}
Defina as tags html e body heightcomo 100%e remova a margem ao redor do corpo:
html, body {
height: 100%;
margin: 0px; /* Remove the margin around the body */
}
Agora defina o positionde seu div para 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 */
}
tente definir a margem e o preenchimento como 0 no corpo.
<body style="margin: 0 0 0 0; padding: 0 0 0 0;">
position: absolute; top: 0; left: 0;