在CSS中,img标签的class属性是一种有用的工具。class属性可用于定位和修改图像样式,以及与CSS中其他元素进行交互。 例如,下面的代码将为图像定义一个名为“flower”的类: .flo...
在CSS中,img标签的class属性是一种有用的工具。class属性可用于定位和修改图像样式,以及与CSS中其他元素进行交互。
例如,下面的代码将为图像定义一个名为“flower”的类:
.flower {
border: 2px solid green;
width: 200px;
height: 200px;
}
<img src="flower.jpg" class="flower">
<img src="rose.jpg" class="flower">
<img src="daisy.jpg" class="flower">
<p>
<img src="flower.jpg" class="left">
My favorite flower is a tulip. But I also like daisies!
<img src="daisy.jpg" class="right">
</p>
<br>
<style>
.left { float: left; margin-right: 10px; }
.right { float: right; margin-left: 10px; }
</style>