Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 1.21 KB  |  hits: 42  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to position text over an image in css
  2. <div class="image">
  3.     <img src="sample.png"/>
  4.     <div class="text">
  5.        <h2>Some text</h2>
  6.     </div>
  7. </div>
  8.        
  9. <style>
  10. .image {
  11.    position: relative;
  12. }
  13.  
  14. h2 {
  15.    position: absolute;
  16.    top: 200px;
  17.    left: 0;
  18.    width: 100%;
  19.    margin: 0 auto;
  20.    width: 300px;
  21.    height: 50px;
  22. }
  23. </style>
  24.        
  25. <style>
  26. #image_container{
  27.     width: 1000px;
  28.     height: 700px;
  29.     background-image:url('switch.png');
  30. }
  31. </style>
  32. <a href="prints.php">Print</a>
  33. <?php ob_start(); ?>
  34. <div id="image_container"></div>
  35. <?php
  36. $_SESSION['sess'] = ob_get_contents();
  37. ob_flush();
  38. ?>
  39.        
  40. <?php require_once('html2pdf/html2pdf.class.php'); ?>
  41. <?php
  42. $html2pdf = new HTML2PDF('L', 'A4', 'en');
  43. $html2pdf->writeHTML($_SESSION['sess']);
  44. $html2pdf->Output('random.pdf');
  45. ?>
  46.        
  47. <div id="container">
  48.     <img id="image" src="http://www.noao.edu/image_gallery/images/d4/androa.jpg"/>
  49.     <p id="text">
  50.         Hello World!
  51.     </p>
  52. </div>
  53.        
  54. #container
  55. {
  56.     height:400px;
  57.     width:400px;
  58.     position:relative;
  59. }
  60.  
  61. #image
  62. {    
  63.     position:absolute;
  64.     left:0;
  65.     top:0;
  66. }
  67. #text
  68. {
  69.     z-index:100;
  70.     position:absolute;    
  71.     color:white;
  72.     font-size:24px;
  73.     font-weight:bold;
  74.     left:150px;
  75.     top:350px;
  76. }