Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Select Images with style="float:left" possible?

Similar to selecting img[title="test"] can I somehow select images that have a style property of float set to left?

I want to set left and bottom margins for them which don't apply to right floating images.

Thank you.

like image 455
Francisc Avatar asked Sep 14 '10 23:09

Francisc


People also ask

In what direction does float will work IMG float right?

The elements after the floating element will flow around it. The elements before the floating element will not be affected. If the image floated to the right, the texts flow around it, to the left and if the image floated to the left, the text flows around it, to the right.

What does float left do?

The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow (in contrast to absolute positioning).

What is float inherit in CSS?

left : floats the element to the left of its container. right : floats the element to the right of its container. inherit : the element inherits the float direction of its parent.


2 Answers

Peter W solution needs to be fixed like this: (changed ~= to *= )

img[style*="float:left"] {
  margin: 5px 15px 0px 0px;
}

img[style*="float:right"] {
  margin: 5px 0px 0px 15px;
}

The only issue is that it makes an exact match, so float:right will match, while float: right wont (notice the extra space).

I tested successfully in Chrome and IE9, but in IE emulation mode will not work ...

like image 102
Omiod Avatar answered Oct 01 '22 19:10

Omiod


Just to expand on this a bit, this is what I've been using for all of my images. It catches floats as well as images that are aligned.

img[align="left"],
img[style*="float: left"],
img[style*="float:left"]{
    margin: 5px 15px 0px 0px;
}
img[align="right"],
img[style*="float: right"],
img[style*="float:right"]{
    margin: 5px 0px 0px 15px;
}
like image 36
Cloudkiller Avatar answered Oct 01 '22 19:10

Cloudkiller