如何使用CSS对多个图像进行不同的样式设置? [英] How can I use CSS to style multiple images differently?

查看:450
本文介绍了如何使用CSS对多个图像进行不同的样式设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我正在撰写一篇长篇论文,其中散布着各种图像. 我希望第一张图片浮动:左",第二张图片浮动:右".我知道我可以像这样对图像进行样式设置:

I am basically styling a long essay with various images scattered throughout. I would like the first image to "float: left" and the second one to "float: right". I know that I can style the images like this:

img {
float: left;
}

这使每个图像具有相同的样式.如何为每个图像设置不同的样式?我试图将每个图像放在不同的div类中,以便我可以对它们进行不同的样式设置,但这是行不通的.

This makes each image have the same style. How do I style each image differently? I tried to put each image in a different div class, so that I could style them differently, but it didn't work.

我也理解,我可以为html标记中的每个图像设置样式,如下所示:

I also understand, that I could style each image in the html tag, like this:

<img src="ABCD.png" alt="Raoul Hausmann's ABCD" align="left" height="300px">

我一直在听说,最好将样式保留在与html分开的外部样式表(CSS)中.是否需要内联样式?

I keep hearing that it is best to keep style in the external style sheet (CSS), separate from the html. Is this a case where inline styling is necessary?

推荐答案

您可以为每个图像指定一个类或ID,以帮助您为每个图像定义不同的CSS,例如

You can give each image a class or id that will help you to define different css for each image like

<img src="" class="image1">
<img src="" class="image2">

您可以在css文件中定义

in css file you can define

.image1
{
width:200px;
height:200px;
}
.image2
{
width:300px;
height:300px;
}

这篇关于如何使用CSS对多个图像进行不同的样式设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆