05-10-fixed-background-attachment.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Profile page with fixed background</title>
  6. <style>
  7. /**
  8. * 1. "Artificial" height applied to body, just to trigger a scrollable are.
  9. * and see the effects.
  10. */
  11. body {
  12. padding: 0;
  13. margin: 0;
  14. font-family: "Helvetica Neue", Arial, sans-serif;
  15. height: 4000px; /* [1] */
  16. }
  17. /**
  18. * 1. Note that the positioning of the background now is in relation to the
  19. * viewport, so we can't position it in the vertical middle of the header.
  20. */
  21. .profile-box {
  22. position: relative;
  23. height: 600px;
  24. background-image: url(img/big-cat.jpg);
  25. background-position: 50% 0; /* [1] */
  26. background-repeat: no-repeat;
  27. background-attachment: fixed;
  28. box-shadow: inset 0 -.5em .5em rgba(0, 0, 0, 0.3);
  29. border-bottom: 1px solid #666;
  30. }
  31. .profile-photo {
  32. width: 160px;
  33. min-height: 200px;
  34. position: absolute;
  35. bottom: -60px;
  36. left: 5%;
  37. padding: .5em;
  38. -webkit-border-radius: .5em;
  39. border-radius: .5em;
  40. background-color: #fff;
  41. box-shadow: .25em .25em .5em rgba(0, 0, 0, 0.3);
  42. }
  43. .profile-photo img {
  44. display: block;
  45. max-width: 100%;
  46. height: auto;
  47. }
  48. .username {
  49. font-size: 20px;
  50. color: #666;
  51. margin: .35em 0 0;
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <header class="profile-box" role="banner">
  57. <div class="profile-photo">
  58. <img src="img/profile.jpg" alt="Charles the Cat">
  59. <h1 class="username">@CharlesTheCat</h1>
  60. </div>
  61. </header>
  62. </body>
  63. </html>