Results 1 to 3 of 3

Thread: centering an image vertically within a <div>

  1. #1
    Join Date
    Feb 2008
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default centering an image vertically within a <div>

    from what i can tell this is quite a nuisance to achieve. i have a <div class="mainredblock"</div> tag that is 55% high and 100% wide. enclosed in this is another <div> tag that is 'restrictor' that keeps the content maxed at 1000px wide. inside this i want to insert an image that is 420px high, and make it center vertically within the 'container' div and float:right in the redbar so its flush left with the right edge of the 'restrictor' div. Right now the image floats right just fine but sticks to the top of the housing div box and will not get centered vertically. any ideas? thanks!

    HTML Code:
    <div class="mainredblock">
    <div class="restrictor">
    <div class="homepageimage">
    <a href="http://www.abc.com"><img src="globalimages/map.png" alt="" border="0"></a></div>
    </div></div>
    and the css:

    HTML Code:
    .mainredblock .homepageimage {
    float: right;
    valign:middle;
    }
    
    .restrictor {
    width: 1000px;
    margin: 0 auto;
    min-width: 1000px; width: expression (document.body.clientWidth < 1000? "1000px": "auto");
    }
    
    .mainredblock {
    font-size: 1.1em;
    width: 100%;
    height: 55%;
    margin: 0 auto;
    background-color: #FF0000;
    float: left;
    min-height: 420px; height: expression (document.body.clientHeight < 420? "420px": "auto");
    }

  2. #2
    Join Date
    Mar 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    .mainredblock .homepageimage {
    #position: relative;
    #top: 50%;
    vertical-align: middle;
    }

    try this

    i think this may help you

  3. #3
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    You could add this code in .mainredblock .hompageimage div
    Code:
    position:relative;
    top:75%;
    ...or you could manipulate the position using margin by adding margin-top:100px;in .mainredblock .hompageimage div.

    See if it helps
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •