• home
  • forum
  • my
  • kt
  • download
  • Flex Your Images

    Author: 2009-03-03 09:33:51 From:

    Step 1: Set Up The HTML

    First, let's create a very simple html file.

    view plaincopy to clipboardprint?
    1. <div id="container">  
    2.     <div id="image">  
    3.     </div>  
    4.     <p>  
    5.         Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vestibulum ullamcorper   
    6.         magna quis velit. Nam vitae dui et massa convallis vulputate. Aliquam ante magna,   
    7.         fermentum nec, scelerisque eget, semper quis, ipsum. Fusce consectetuer enim quis   
    8.         lorem. Morbi elit turpis, consequat ac, lacinia nec, dignissim ac, velit. Proin   
    9.         mauris orci, rutrum a, suscipit eu, sagittis et, nisi. Quisque at mi ac magna fermentum   
    10.         elementum.   
    11.     </p>  
    12. </div>  

    Step 2: Add The CSS

    view plaincopy to clipboardprint?
    1. #container   
    2. {   
    3.     width: 50%;   
    4.     marginauto;   
    5.     padding: 1em;   
    6.     background#3d332a;   
    7.     color#b8ada2;     
    8. }   
    9.   
    10. #image  
    11. {   
    12.     height300px;   
    13.     backgroundurl(Girl.jpg) no-repeat center;   
    14. }  

    In order for our container div to be flexible, I've set the width to be 50% of the browser window. Next, I've set the margins to auto in order to center the contents. The padding, background, and color are simply aesthetic styling.

    The div tag with an id of "image" is where we'll add the background image. The key here is that I'm not setting a specific width to the image - only the height. When you add the image as a background, you'll want to make sure that you "center" it (no-repeat center). This, in effect, will force the main focus of your image to be displayed at all times. *Note - Make sure that you use an image that has the main focal point in the middle.

    You're Done

    View your work in a browser and try increasing and decreasing the browser window. There are a few things to keep in mind when using this method.

    • Make sure that you use images that are as wide as they'll ever need to be.
    • The center of your image should be the focal point.
    • Center the background image.
    • Consider making the maximum width of your container div equal to the full width of the image.
    • Additionally, consider adding a minimum width to make sure that your image doesn't shrink too much.
    Final Product

    discuss this topic to forum

    relation tutorial

    No information

    Category

      htaccess (0)
      Advanced (4)
      Backgrounds (1)
      Buttons (4)
      Colors (9)
      Forms (15)
      Frames (6)
      Getting Started (52)
      HTML4 (2)
      Image Maps (5)
      Images (17)
      References (7)
      Tables (9)

    New

    Hot