Help - Search - Members - Calendar
Full Version: Image Alignment & Captioning - CSS - How To
Movable Type Community Forum > Additional Resources > Tips and Tricks
billray
I am trying to align and caption images similar to the way that is done on AdRants, i.e., wrapping text and captioned images. I am having difficulty getting it to work properly, so any help would be appreciated.

I apologize for the length of the code stubs, but having searched this forum, hopefully it will help someone else. Adrants code is perfect, it just doesn't work for my layout because of my requirement for the .content class.

The syntax used by AdRants is as follows:
CODE
<DIV class=imageleft>
    <IMG src="accliamscreen23.jpg">
    <DIV>Here's the Caption</DIV>
</DIV>

This yields a left aligned image with the caption underneath the image.

Here are the relevant CSS definitions:

.content - has all of the 'blog stuff' associated with MT in a center column in a three column layout. I have to use .content and not #content, but that's a different story... So, this is my code.

CODE
.content {
/* this is the blog itself */
    top:138px;
    POSITION: relative;
    MARGIN: 0px 190px 20px 190px;
    PADDING-RIGHT: 10px;
    PADDING-BOTTOM: 10px;
    PADDING-TOP: 10px;
    PADDING-LEFT: 10px;
    BORDER-RIGHT: black 1px solid;
    BORDER-TOP: black 1px solid;
    BORDER-LEFT: black 1px solid;
    BORDER-BOTTOM: black 1px solid;
    Z-INDEX: 2;
    WIDTH: auto;
    min-width: 120px;
    left: 11px;
}


This is the code 'as is' from adRants. For brevity, I've just included the 'lefts', not the rights:

CODE
DIV.imageleft {
    CLEAR: both
    }

DIV.imageleft {
    FLOAT: left;
    MARGIN: 7px 15px 10px 0px
}

DIV.imageleft A {
    BORDER-BOTTOM-STYLE: none! important
}

DIV.imageleft DIV {
    PADDING-RIGHT: 0px;
    PADDING-LEFT: 0px;
    PADDING-BOTTOM: 5px;
    FONT: 10px/12px verdana;    
COLOR: #666; PADDING-TOP: 5px;
    BORDER-BOTTOM: #666 1px solid;
    text-align: left
}

P.imageleft {
    CLEAR: both
}

P.imageleft IMG {
    PADDING-RIGHT: 15px;
    PADDING-LEFT: 0px;
    FLOAT: left;
    PADDING-BOTTOM: 10px;
    PADDING-TOP: 7px;
    POSITION: relative
}

IMG {
    BORDER-TOP-WIDTH: 0px;
    BORDER-LEFT-WIDTH: 0px;
    BORDER-BOTTOM: 0px;
    BORDER-RIGHT-WIDTH: 0px
}
kadyellebee
And what's not working for you? A quick first glance at the code and css and they look okay. A link to your site would be helpful. smile.gif

Kristine
billray
I've posted a copy of my test page here. All of the CSS is embedded so you see what's going on.

You can see the image I'm trying to get to work towards the bottom of the page. I initially thought that I had a layering problem, but there also something going on with the length of the caption underscore and margin.

I've tried switching the DIV.imageleft to content.imageleft, and while closer, it still doesn't work. I'm not that fluent in CSS, particularly when you have to start sub classing. I think the problem is in the DIV.imageleft DIV portion, but I'm not sure.

Thank you for any help/guidance you can provide.
kadyellebee
I'm still not sure what you are seeing that's the problem. You have a lot of code going on together, and some validation of both the html and css may help you out. Each browser renders this differently, but here's what I'm seeing:

* The image is hiding under the colored layer.
* The image and caption are expanding below the yellow container.

The first issue can be fixed by removing the position:relative; in the .content section.

The second issue can be fixed by adding
CODE
<div style="clear:both;"></div>
right before the closing div of that .content section. But it seems like there may be a better way. Will you be using this in a blog layout where there will be a posted line below the content? If so, you can add clear:both; to the .posted stylesheet definition, and that would make it finish the yellow container before starting the posted line.

If these ideas don't help, asking on a CSS forum or web designer list would probably be more likely to know how to help.

Kristine
billray
Thanx for the help.

I tried removing the position: relative; definition out of .content. Naturally the space between the #banner and the center content is gone now, but the image does show through. (Now the layout is more like Glish.com than BlueRobot's, which mine is modelled after.)

I still can't get the caption to show through though. Now, you asked:

QUOTE
Will you be using this in a blog layout where there will be a posted line below the content? If so, you can add clear:both; to the .posted stylesheet definition, and that would make it finish the yellow container before starting the posted line.


I will be using it in a blog layout as well as elsewhere. I'm hoping that I can make the layout and style-sheet very generic - I know that I want to be able to include captioned images in a non-MT environment. I'd love to be able to 'hard-wire' the style/layout only to the css and not any specific MT tags.

Thanx for the help Kristine, (can you recommend any good css forums - in case I've burned you out?)
LisaJill
Here are two great sites:

CSSCSS Forums

and

DevShed

The first (CSS Forums) is specific and they're brilliant. Devshed guys are brilliant too but field a lot more varied questions; I'd try at the CSS Forums first. =)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.