I'm having a problem not being able to float images when I'm using the caption class:

This does not float:

<p><img class="caption" src="/files/u6/Andreu_roubaix.jpg" alt="Andreu at Roubaix" title="Andreu at Roubaix" width="330" height="500" style="margin: 10px; float: left;" /></p>

This does:

<p><img src="/files/u6/Andreu_roubaix.jpg" alt="Andreu at Roubaix" title="Andreu at Roubaix" width="330" height="500" style="margin: 10px; float: left;" /></p>

css is:

.caption {}

.image-caption
{
margin-top: 5px;
margin-right: 0pt;
margin-bottom: 10px;
margin-left: 5px;
background-color: #f9f9f9;
font-weight: bold;
font-size: 80%;
color: #4a4b4d;
}

.image-caption-container
{
margin-top: 10px;
margin-right: 10px;
margin-bottom: 0pt;
margin-left: 10px;
}

So it doesn't look like it's the css.

Thanks

Comments

awolfey’s picture

Here's a perfect example:

http://www.velocitynation.com/node/2204

You can see everything is floating correctly, then js puts the caption in and the float is gone.

danepowell’s picture

Version: 5.x-1.1 » 6.x-2.2

I am also experiencing this. This is extremely annoying... why would I want to caption an image if it's just going to sit and be ugly in the middle of the page?

davidwhthomas’s picture

Perhaps you could try floating the .image-caption-container rather than the image itself.

.image-caption-container{
  float:left;
}

I tested that with Firebug on the sample link provided and it works fine.

Otherwise, try using the input format version of image caption.

DT

awolfey’s picture

Yes, that would work on its own as either left or right float, but not with tinyMCE, which allows the users to apply left or right float on their own.

eclauset’s picture

I'm having the same problem -- there needs to be a way for the float to be translated from image itself to the image-caption-container
There's already a provision for this if the Only local images are allowed. tag contains an align attribute

awolfey’s picture

Image_caption looks for the align attribute, but tinymce is aligning images with float, which it puts in an inline style. Image_caption removes all inline style settings except for the align attribute. Therefore, no float

Here's my solution.

I just switched style for align in the image_caption js:

/*$Id: image_caption.js,v 1.1 2008/02/23 06:24:07 davidwhthomas Exp $*/
$(document).ready(function(){
  $("img.caption").each(function(i) {
    var imgwidth = $(this).width();
    var imgheight = $(this).height();
    var captiontext = $(this).attr('title');
    var imgstyle = $(this).attr('style'); 
    $(this).attr({align:""});
    $(this).wrap("<div class=\"image-caption-container\" style=\"" + imgstyle + "\"></div>");
    $(this).parent().width(imgwidth);
    $(this).parent().append("<div class=\"image-caption\">" + captiontext + "</div>");
  });
});
awolfey’s picture

I should add that my solution will probably break alignment using the align attribute because that needs to be applied to #image-caption-container div, and I took it out of that.

Anonymous’s picture

awolfey’s picture

No, this is not related to missing css.

ngmaloney’s picture

Version: 6.x-2.2 » 6.x-2.1

awolfey - I had the exact same problem you experienced. To resolve the "alignment" conflict I slightly modified the JS you provided and so far it seems to work. Further testing is still needed.

The following replaces the image_caption.js found within the module.

$(document).ready(function(){
  $("img.caption").each(function(i) {
    var imgwidth = $(this).width();
    var imgheight = $(this).height();
    var captiontext = $(this).attr('title');
    var style = $(this).attr('style');
    var alignment = $(this).attr('align');
    //Clear image styles to prevent conflicts with parent div
    $(this).attr('style','');
    $(this).wrap("<div class=\"image-caption-container\" style=\"" + style + "; text-align: " + alignment + "\"></div>");
    $(this).parent().width(imgwidth);
    $(this).parent().append("<div class=\"image-caption\">" + captiontext + "</div>");
  });
});
danepowell’s picture

Status: Active » Reviewed & tested by the community

I have applied the fix in #10 to my site and it seems to be working great. Could this get rolled into the next release?

Kasha’s picture

hahahahahah!

quit your whining, I don't see you on a list of 100 top donors, sistah.

as for the issue at hand, the above solution does not work for me.

Kasha’s picture

upon clearing my cache I'm happy to report that its working perfectly.

danepowell’s picture

Version: 6.x-2.1 » 6.x-2.3

Please let us know if there's any more work that needs to be done on this. Otherwise it sounds like it can be rolled into the next release.

(Does this project have/need an active maintainer?)

gregarios’s picture

This may be a duplicate of this issue, actually:
http://drupal.org/node/461798

danepowell’s picture

Component: Miscellaneous » Code
Category: support » bug

@gregarios - I think these issues may be similar, but they're not duplicates. That issue seems to be related to Image Caption stripping classes, this one is related to stripping inline styles.

danepowell’s picture

Is this going to get addressed by a maintainer at all? We seem to have a fully working patch, and I'd love to get this out of my issue queue at long last (we're going on 10 months here!)

WeRockYourWeb.com’s picture

Works great, thanks for the patch. Would also like to see this get committed.

danepowell’s picture

bump... perhaps it's time to start the "abandoned project" process

davidwhthomas’s picture

Status: Reviewed & tested by the community » Fixed

Patch applied in release 6.x-2.4 http://drupal.org/node/672928
Note: as I'm a busy developer, I depend on the community to review and test patches.
Hence, only issues marked 'tested and reviewed by the community" will be considered, thanks.
DT

GlobalRaj’s picture

Version: 6.x-2.3 » 6.x-2.4
Priority: Normal » Critical

The release of 6.x-2.4 threw off the image alignment in old posts but I found the right fix.

On my site, I have given novice people the ability to add captions. I just tell them to add the following while inserting an image into any post

- width
- height
- align (was handling the float in the previous release)
- class="caption"
- title

Basically, in the previous release, the image alignment was handling the float of the image-container but the latest release replaced that with "text-align" which doesn't work as well. The following works fine for me and my old posts are also not affected.

Change Line 11 in the image_caption.js to

$(this).wrap("<div class=\"image-caption-container\" style=\"" + style + "; float: " + alignment + "\"></div>");"

Easy fix!

Working example can be found at the following

http://usaca.org/content/20100107/usa-under-19-warms-down-in-2nd-match

http://usaca.org/content/20091219/university-of-minnesota-offers-cricket...

If any one is wondering how I use the borders and such, I use the following in the style.css file of my site theme

.caption {}
.image-caption-container
{
	padding: 1px;
	border-style:solid; border-width:1px;
	margin: 0em 0em .5em 1em;
	background-color: rgb(0, 0, 0);
	clear: both;
}
.image-caption
{
	padding-left: 5px;
	text-align: left;
	font-family: Arial,verdana;
	font-size: 11px;
	font-weight: normal;
	color: rgb(255, 255, 255);
}

Cheers!

P.S. Am not an expert. Just trying to learn Drupal and it's awesome!!!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

danepowell’s picture

Spammers on d.o? That's a new one to me. How do we report users and get posts deleted?
Problem solved