CSS定位特定图片 [英] CSS targeting specific images
问题描述
我正在寻找一种使用CSS定位特定图片的方法,如果这是可能的。
I am looking for a way to target a specific image with CSS, if this is even possible.
我正在运行一个CMS,用户可以上传图片和把他们放在他们的网页上。
I am running a CMS where the users can upload images and put them on their pages. I would like a way to target images with specific dimensions.
因此,问题是,可以使css行定位到具有特定尺寸的图片或对象?
我会想象:
img#width:400px { float :left; }
(使400像素宽的图片具有float:left)
(to make images that are 400 pixels wide have float:left)
我知道我可以给图像一个类或者一个id,但是当客户在cms里玩时,它会丢失。
I know i could give the image a class or an id, but it would be lost when the customer plays around in the cms.
推荐答案
img[width="400"]{
float:left;
}
这将使属性设置为400的任何图像float left: / p>
This will make any image that have the attribute set to 400 float left:
<img src="image.jpg" width="400" />
注意:这只有在设置了width属性时才有效。如果图片宽度为400像素,但未设置宽度属性,则无法使用。
Note: this will only work if the width attribute is set. Will not work if the image is 400px wide but does not have a width attribute set.
这篇关于CSS定位特定图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!