The Problem: A user is using TinyMCE with img_assist. They insert an image, setting its alignment to 'left'. They then add a link around the img_assist tag. They submit the page, and the linked image looks fine, and works everywhere except IE (tested on IE7). In IE the link doesn't work. The html that's failing looks like this:

<a href='some-link'><span class="inline left"><img class="image img_assist_custom" width="123" height="456" title="" alt="" src="http://example.com/image.jpg"/></span></a>

At the end of img_assist.css we have these rules:

span.left {
  float: left;
  margin: 5px 5px 5px 0px;
}
span.right {
  float: right;
  margin: 5px 0px 5px 5px;
}

The problem with this is that we're trying to apply 'float: left', and 'float: right' to spans, which are inline elements, but float only makes sense for block elements. This normally doesn't matter, but it seems to be tripping IE up. My fix is to change the above css to:

span.left img {
  float: left;
  margin: 5px 5px 5px 0px;
}
span.right img {
  float: right;
  margin: 5px 0px 5px 5px;
}

This applies the float rules to the img tags, which are block elements, and makes the links work in IE.

Comments

sun’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new704 bytes

Agreed.

sun’s picture

Status: Reviewed & tested by the community » Fixed
zoo33’s picture

Status: Fixed » Active

Yes, but what about captions:

<span class="inline left"><img /><span class="caption">Caption</span></span>

Wouldn't this patch mess up how images and captions are aligned? I didn't test it (sorry) but it seems wrong. How about changing the surrounding span to a div and floating that instead?

sun’s picture

I think you are right, although I'm not 100% sure, too. However, DIVs are not an option because they span over all available width unless the width is explicitly defined via CSS.

We could try to turn this into

span.left {
  float: left;
}
span.left img {
  margin: 0 5px 5px 0;
}
span.right {
  float: right;
}
span.right img {
  margin: 0 0 5px 5px;
}
sun’s picture

Priority: Normal » Critical

Eeerrm... where's my head?!

we're trying to apply 'float: left', and 'float: right' to spans, which are inline elements, but float only makes sense for block elements.

Seems like we need something completely different to solve this.

TobiasH’s picture

Why not use

? If we float something we must give it a width. How about:
<div style="width: $image-width">
  <img />
  <span>Caption</span>
</div>

?

sun’s picture

Assigned: Unassigned » sun
Status: Active » Needs review
StatusFileSize
new3.47 KB

Let's stick to DIV containers, including the caption.

Attached patch also renames those ambigious CSS alignment classes to inline-[align].

TobiasH’s picture

I've tested your patch with Garland and it seems that it solves the bug.

A problem I see with that inline classes. Why do we give class="inline" to a float-element. I think class="inline" should be given to none-aligned images. The css code for inline could be:

.inline {
  display: inline;
}

Styling of images can take over another class instead of inline.

sun’s picture

I agree that 'inline' is somewhat misleading. However, it's valuable to have a common class name for all inline images (so all inline images can be styled equivalent easily) and AFAIK the class name is not ambigious (in Garland theme at least).

Since I'm also the maintainer of Inline module and there is already a draft to form an Inline API (a future release of Image Assist could be based on), I would not alter this class name now, since it would be renamed back to 'inline' when Inline API will be released and integrated someday.

Anyway, your point for styling of non-aligned images is not yet solved. We might implement

div.inline-none {
  display: inline;
}

However, what happens to captions for non-aligned images? How have those captions been styled in previous versions?

zoo33’s picture

I don't suppose we could have solved this with:

span.inline-left img {
  display: block;
  float: left;
  margin: 5px 5px 5px 0px;
}

That is, stick with spans but add display: block. That way we wouldn't need the style attribute on the div. Don't know if it would work in IE though.

Anyway, I'm OK with the last patch as it is. I don't think the naming confusion is such a big deal. "Inline" refers to "inline images" in this case – and I don't think it's really desirable to map class names to the style it's using anyway. After all, you're supposed to name classes so that they make sense WRT the page structure: like "content", "search" etc., not "big", "wide" etc.

sun’s picture

StatusFileSize
new3.96 KB

Reverting to SPANs, but always including alignment class and removing the width at all.

If an image is centered, the width for the caption is not limited. Additionally, the caption is centered, too. However, we could add text-align: left; to the caption. I'd like to hear your votes on that.

Removing the width from captions at all is not possible, unless we find a nifty CSS trick to limit the caption's width to the width of an left or right aligned image.

OT: The 'link to url' option is not working, $attributes['url'] isn't set. I'll file a separate issue for that.

zoo33’s picture

So... style attributes are still necessary for captions. Hm. Maybe divs aren't so bad after all. If we used divs with the width set in a style attribute then maybe the captions wouldn't need to specify it. (That 2 pixel subtraction of caption widths could be done with padding instead.)

Spans or divs... I don't know, either way is fine with me.

TobiasH’s picture

The idea with the DIVs wasn't really good. Sorry. If you put an image between P-tags you get errors trough validating your site. I've tested the patch in #11. There seem to be no disadvantages after changing.

sun’s picture

Status: Needs review » Fixed

Committed #11, thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)
tahiticlic’s picture

Hi,

I've just had the same problem with 3-x.dev version. I had to change the styles in img_assist.css to :

span.inline-left  img{
  display: block;
  float: left;
  margin: 5px 5px 5px 0px;
}
span.inline-right  img{
  display: block;
  float: right;
  margin: 5px 0px 5px 5px;
}
borsna’s picture

Version: 5.x-1.x-dev » 6.x-2.0-alpha4
Status: Closed (fixed) » Active

I had the same problem as #16,
changing "span.inline-left{" to "span.inline-left img{" worked great.

sun’s picture

Status: Active » Closed (fixed)

Reverting to fixed, as I believe that the last follow-ups need a separate discussion (which might exist already, so please search the active issues before creating a new one, thanks).