Results 1 to 3 of 3

Thread: Centering a floating div

  1. #1
    Join Date
    Jan 2006

    Centering a floating div

    This is not a fixed width layout. I have one or two CSS techniques applied to these images-- a shadow for all of them which requires floating, and there is also a caption for some of them.


    I need to be able to center the last picture "with" the shadow in this layout, but am wondering how to do this. I managed to do it with two images (as you can see at the very top) using 2 divs within another div, but one image is really killing me with floating items.

    .img-shadow {
    background: url(http://matt.mw/gmsaa/img_shadow/shadowAlpha.png) no-repeat bottom right;
    margin: 10px;
    .img-shadow img {
    display: block;
    background-color: #fafafa;
    border: 1px solid #a9a9a9;
    margin: -6px 6px 6px -6px;
    padding: 4px;
    <div class="img-shadow"><img src="http://matt.mw/gmsaa/articles/passing_in_review/passing_in_review_images-012.jpg" /></div>

    So without taking away this float & shadow, how do I place this image in the exact center when this layout is not fixed?
    Obviously text-align:center has no effect on floating items. Seems different positioning methods like "absolute" ruin my shadow.

    Please help me out! Thanks.

  2. #2
    Join Date
    Jan 2006
    I guess I can't edit my post.....

    Link update: http://matt.mw/passing_in_review3.html

  3. #3
    Join Date
    Aug 2004
    San Diego, CA

    You can use negative and "auto" margins

    The following inclodes a bunch of color styling as well as the margin styling for centering, but itshould illustrate the point. The z-index puts the shadowed div behind the other one.
    HTML Code:
    .fshadow {                      /* properties on form shadow */
         width: 400px;
         height: 520px;
         position: absolute;
         left: 50%;
         margin-left: -190px;
         top: 50px;
         background-color: #cdcdcd;
    .fbox {                        /* properties on form container */
         width: 400px;
         height: 520px;
         position: absolute;
         left: 50%;
         margin-left: -200px;
         top: 40px;
         border-top: 2px solid #910000;
         border-left: 2px solid #910000;
         border-right: 2px solid #6E0000;
         border-bottom: 2px solid #6E0000;
         color: #000000;
         background-color: #FFFFFF;
         font-weight: bold;
         text-align: center;
    <div class='cbox black p34' style='width:1270px; margin:30px 0; text-align:center'>
         <div class='fshadow' style='width:900px; height:145px; margin-left:-440px; top:150px; z-index:120;'>
         <div class='fbox' style='width:900px; height:145px; margin-left:-450px; top:140px; z-index:125;'>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Recent Articles