Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a box-shadow that covers the entire page?

Tags:

html

css

the end result that I'm looking for is something like this:

http://osxdaily.com/wp-content/uploads/2011/08/icloud-background.jpg

Which was generated with this bkg title:

http://osxdaily.com/wp-content/uploads/2011/08/apple-shirt.jpg

Is it possible to apply a css3 box-shadow to get the desired output?

I tried:

box-shadow: inset 0 0 490px black;

But that only covers a small part of the screen.

Thanks

like image 838
AnApprentice Avatar asked Aug 03 '12 19:08

AnApprentice


3 Answers

Make sure whatever element you set the box shadow to has 100% width and height. This means that all ancestors must also have 100% height and width. So if you want to apply it to body, html must also have those properties.

CSS:

html, body { 
    width:100%;
    height: 100%;
}
​
body {
    box-shadow: inset 0 0 490px black;
    background: url('image.jpg');
}

JS Fiddle Example


To maintain the same shadow effect even when you scroll, apply the box shadow to a wrapper div and then apply overflow:auto.

HTML:

<html>
<body>
    <div id="wrapper"></div>
</body>
</html>

CSS:

html, body, #wrapper { 
    width:100%;
    height: 100%;
}

#wrapper {
    box-shadow: inset 0 0 490px black;
    background: url('image.jpg');
    overflow: auto;
}

​ ​JS Fiddle Example

like image 91
JSW189 Avatar answered Oct 17 '22 06:10

JSW189


If I understood correctly this is what your looking for: http://jsfiddle.net/RGWrC/

Here's the code:

html { 
    height: 100%;
}

body {
    min-height: 100%; 
    box-shadow: inset 0 0 490px black;
    background: url('whatever.jpg');
}

This extends the background to the full height of the page, still, ensuring a minimum equal to the window's height. The CSS, I think, is self-explanatory.

like image 20
João Paulo Macedo Avatar answered Oct 17 '22 06:10

João Paulo Macedo


There is another pretty easy way to do similar effect. You have to wrap your website content with div that will have boxshadow. Also the div needs to have 100% width and height, and posiation: absolute; This will give You a nice effect evan when You scroll the page.

HTML

<div class="shadow">

    <!-- ANY CONTENT GOES HERE -->
    <div>
        <h1>Content</h1>
    </div>
    <!-- ANY CONTENT GOES HERE -->

</div>

CSS

.shadow {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-box-shadow: inset 0px 0px 400px #000000;
    box-shadow: inset 0px 0px 400px #000000;
}

Example: http://jsfiddle.net/2GRGF/1/

like image 33
none20 Avatar answered Oct 17 '22 06:10

none20