Aligning images right without floating

daysrunaway picture daysrunaway · Jul 10, 2011 · Viewed 9.1k times · Source

I'm using the WordPress NextGEN Gallery to position fixed-width images inside a fluid-width <aside>. I'd like the images to align to the right of the <aside> container, but if I try to float them right, the order becomes reversed. I can't simply reverse the order of the images in WordPress either, as the number of columns of images varies with the browser window.

Is there a way to align these images to the right without floating them? I've tried setting text-align:right on every image and its container, but nothing's worked.

PHP/HTML:

<!-- Thumbnails -->
    <?php foreach ( $images as $image ) : ?>

    <div id="ngg-image-<?php echo $image->pid ?>" class="ngg-gallery-thumbnail-box" <?php echo $image->style ?> >
        <div class="ngg-gallery-thumbnail" >
            <a href="<?php echo $image->imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> >
                <?php if ( !$image->hidden ) { ?>
                <img title="<?php echo $image->alttext ?>" alt="<?php echo $image->alttext ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> />
                <?php } ?>
            </a>
        </div>
    </div>

CSS: (Mostly inherited from NextGen Gallery)

.ngg-galleryoverview {
    overflow: hidden;
    clear:both; 
    display:block !important;
    float:right;
    text-align:right;
    margin-top:18px;
    width:100%;
}

.ngg-galleryoverview .desc {
/* required for description */
   margin:0px 10px 10px 0px;
   padding:5px;
}

.ngg-gallery-thumbnail-box {
    display:inline;
}

.ngg-gallery-thumbnail {
    display:inline;
    text-align: center;
}

.ngg-gallery-thumbnail img {
    display:inline;
}

.ngg-gallery-thumbnail img {
    background-color:#FFFFFF;
    border:1px solid #A9A9A9;
    display:block;  
    margin:4px 0px 4px 5px;
    padding:4px;
    position:relative;
    float:left;
}

Answer

Jason Gennaro picture Jason Gennaro · Jul 10, 2011

Not sure if you can do this in your code, but if you wrap the img in a p and set text-align on the p, it all works out.

<p><img src="" /></p>

p{text-align:right;}

http://jsfiddle.net/jasongennaro/x3Lx4/