Posted By

icecreamboyy on 04/28/11


Tagged

css img bg


Versions (?)

Consistant fixed background image


 / Published in: CSS
 

  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta charset="utf-8">
  6.  
  7. <title>Full Page Background Image | CSS #2</title>
  8.  
  9. <style>
  10. #bg {
  11. position:fixed;
  12. top:-50%;
  13. left:-50%;
  14. width:200%;
  15. height:200%;
  16. }
  17. #bg img {
  18. position:absolute;
  19. top:0;
  20. left:0;
  21. right:0;
  22. bottom:0;
  23. margin:auto;
  24. min-width:50%;
  25. min-height:50%;
  26. }
  27.  
  28. #page-wrap { position: relative; z-index: 2; width: 400px; margin: 50px auto; padding: 20px; background: white; -moz-box-shadow: 0 0 20px black; -webkit-box-shadow: 0 0 20px black; box-shadow: 0 0 20px black; }
  29. p { font: 15px/2 Georgia, Serif; margin: 0 0 30px 0; text-indent: 40px; }
  30. </style>
  31. </head>
  32.  
  33. <body>
  34.  
  35. <div id="page-wrap">
  36.  
  37. <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
  38. <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
  39. <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p><p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
  40.  
  41. </div>
  42.  
  43. <!-- At bottom, 'cause it's not really content -->
  44. <div id="bg">
  45. <img src="http://64.19.142.12/css-tricks.com/examples/FullPageBackgroundImage/images/bg.jpg" alt="">
  46. </div>
  47.  
  48. <!-- IGNORE: BuySellAds.com Ad Code -->
  49. <script type="text/javascript">(function(){ var bsa = document.createElement('script'); bsa.type = 'text/javascript'; bsa.async = true; bsa.src = '//s3.buysellads.com/ac/bsa.js'; (document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(bsa); })();</script>
  50.  
  51. <!-- IGNORE: Just Google Analytics -->
  52. <script type="text/javascript">var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-68528-29']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga); })();</script>
  53.  
  54. <!-- IGNORE: View Source Stuff -->
  55. <style type="text/css" style="display: none;">.header-button{ border-top:1px solid #cf942d !important; border-bottom:0 !important; background:#964418 !important; background:-webkit-gradient(linear,left top,left bottom,from(#e86e36),to(#964418)) !important; background:-moz-linear-gradient(top,#e86e36,#964418) !important; padding:3px 10px !important; -webkit-border-radius:8px !important; -moz-border-radius:8px !important; border-radius:8px !important; -webkit-box-shadow:rgba(0,0,0,1) 0 1px 0 !important; -moz-box-shadow:rgba(0,0,0,1) 0 1px 0 !important; box-shadow:rgba(0,0,0,1) 0 1px 0 !important; text-shadow:rgba(0,0,0,.4) 0 1px 0 !important; color:white !important; font-size:13px !important; font-family:Georgia,serif !important; text-decoration:none !important; vertical-align:middle !important; display:inline !important; margin:0 !important;float:none !important}.header-button:hover{ border-top:1px solid #4f220d !important; background:#4f220d !important; color:#ccc !important; text-decoration:none !important; margin:0 !important}.header-button:active{ border-top:1px solid #261105 !important; background:#261105}.header-button:visited:before,.header-button:visited:after{ content:""!important}#source-code{z-index:7000;display:none;text-align:left;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(255,255,255,0.8)}#source-code:target{display:block}#source-code pre{padding:20px;font:14px/1.6 Monaco,Courier,MonoSpace;margin:50px auto;background:rgba(0,0,0,0.8);color:white;width:80%;height:80%;overflow:auto}#source-code pre a,#source-code pre a span{text-decoration:none;color:#0cf !important}#x{position:absolute;top:30px;left:10%;margin-left:-41px}#x img{border:0}.view-source-button{position:fixed;bottom:10px;right:10px;z-index:100}.str{color:#61ff74}.kwd{color:white}.com{color:white}.typ{color:#f1915d}.lit{color:white}.pun{color:white}.pln{color:#ffef97}.tag{color:#ffab58}.atn{color:#fabb4e}.atv{color:#ffd996}.dec{color:red}</style>
  56. <div id="source-code"><a href="#" id="x"><img src="http://64.19.142.13/css-tricks.com/examples/ViewSourceButton/images/x.png" alt="close"></a></div>
  57. <a class="view-source-button header-button" href="#source-code" id="view-source">Fancy View Source</a>
  58. <script type="text/javascript" src="/prettify/prettify.js"></script><script>if(typeof jQuery=='undefined'){function getScript(url,success){var script=document.createElement('script');script.src=url;var head=document.getElementsByTagName('head')[0],done=false;script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState=='loaded'||this.readyState=='complete')){done=true;success();script.onload=script.onreadystatechange=null;head.removeChild(script)}};head.appendChild(script)};getScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js',function(){if(typeof jQuery=='undefined'){}else{fancyCode()}})}else{fancyCode()}function fancyCode(){$("<pre />",{"html":'&lt;!DOCTYPE html>\n&lt;html>\n'+$("html").html().replace(/[<>]/g,function(m){return{'<':'&lt;','>':'&gt;'}[m]}).replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,'<a href="$1">$1</a>')+'\n&lt;/html>',"class":"prettyprint"}).appendTo("#source-code");prettyPrint()}</script>
  59.  
  60.  
  61. </body>
  62.  
  63. </html>

Report this snippet  

You need to login to post a comment.