画面全体を半透明の div でカバーしようとしています。私はこれを試しました:
#dimScreen
{
width: 100%;
height: 100%;
background:rgba(255,255,255,0.5);
}
ただし、それは画面全体をカバーするのではなく、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 トリックには、フルスクリーン プロパティに関する興味深い記事もあります。
編集:
この回答に出くわしたので、いくつか追加したいと思いました。コメントで述べたダニエル・アレン・ラングドン
の
ように、カバーが画面の一番上と左にくっつくことを確認してください.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%;}
この方法を使用するposition:fixed
と、divは表示可能な領域全体に継続的に残ります..
div にクラスoverlay
を指定し、CSS で次のルールを作成します
.overlay{
opacity:0.8;
background-color:#ccc;
position:fixed;
width:100%;
height:100%;
top:0px;
left:0px;
z-index:1000;
}
#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-reset を適用して、このようにすべてのマージンとパディングをリセットします
/* 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-resets を使用できます。通常、css で使用することもできます
html
{
margin: 0px;
padding: 0px;
}
body
{
margin: 0px;
padding: 0px;
}
body の margin と padding を 0 に設定してみてください。
<body style="margin: 0 0 0 0; padding: 0 0 0 0;">
html タグと body タグheight
を設定し100%
、本文の周囲のマージンを削除します。
html, body {
height: 100%;
margin: 0px; /* Remove the margin around the body */
}
position
次に、div を次のように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 */
}