Similar to selecting img[title="test"]
can I somehow select images that have a style property of float
set to left
?
与选择img [title =“test”]类似,我能以某种方式选择float属性设置为左边的图像吗?
I want to set left and bottom margins for them which don't apply to right floating images.
我想为它们设置左边距和下边距,这些边距不适用于右浮动图像。
Thank you.
谢谢。
4 个解决方案
#1
28
Peter W solution needs to be fixed like this: (changed ~=
to *=
)
Peter W解决方案需要像这样修复:(更改〜= 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).
唯一的问题是它完全匹配,所以float:right匹配,而float:右不会(注意额外的空间)。
I tested successfully in Chrome and IE9, but in IE emulation mode will not work ...
我在Chrome和IE9中测试成功,但在IE仿真模式下无效...
#2
18
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;
}
#3
3
Not possible without JS. You can put a class on the images or their parents and make a rule, though.
没有JS就不可能。但是,您可以在图像或其父母上放置一个课程并制定规则。
#4
2
Use this:
用这个:
img[style~="float:left"] {
margin: 5px 15px 0px 0px;
}
img[style~="float:right"] {
margin: 5px 0px 0px 15px;
}
You can read all about CSS2 Selectors at one of these sites:
您可以在以下网站之一阅读CSS2选择器的所有内容:
- CSS2 attr selector examples at quirksmode
- quirksmode上的CSS2 attr选择器示例
- CSS2 attr selector reference from w3.org
- 来自w3.org的CSS2 attr选择器参考
#1
28
Peter W solution needs to be fixed like this: (changed ~=
to *=
)
Peter W解决方案需要像这样修复:(更改〜= 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).
唯一的问题是它完全匹配,所以float:right匹配,而float:右不会(注意额外的空间)。
I tested successfully in Chrome and IE9, but in IE emulation mode will not work ...
我在Chrome和IE9中测试成功,但在IE仿真模式下无效...
#2
18
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;
}
#3
3
Not possible without JS. You can put a class on the images or their parents and make a rule, though.
没有JS就不可能。但是,您可以在图像或其父母上放置一个课程并制定规则。
#4
2
Use this:
用这个:
img[style~="float:left"] {
margin: 5px 15px 0px 0px;
}
img[style~="float:right"] {
margin: 5px 0px 0px 15px;
}
You can read all about CSS2 Selectors at one of these sites:
您可以在以下网站之一阅读CSS2选择器的所有内容:
- CSS2 attr selector examples at quirksmode
- quirksmode上的CSS2 attr选择器示例
- CSS2 attr selector reference from w3.org
- 来自w3.org的CSS2 attr选择器参考