我可以在代码中将其更改为 css

Can i change this in code into css

<div class="rotate"> <img src="image_url"/> </div>

我想将此 img src 图像设置为 css 中的背景图像。请帮助我。

我想你是在谈论如何将背景图像设置为 class 'rotate' 而不是调用 img src。

<style type="text/css"> 
.rotate
 {
 background:url(image.jpg) no-repeat center;     
 width:100px;
 height:100px;  
 }
</style>
<div class="rotate"> </div>

HTML 明智的做法是:

<div class="rotate"></div>

和css将是

.rotate {   // define a class in css
    background:url(image.jpg) no-repeat center; // asuming you dont want it repeat and centered in the middle of your div.
    width: *amount of pixels*;
    height: *amount of pixels*;
}

请注意,我想指出添加背景的图像将不起作用,因为没有定义大小,因此如果我现在查看您的代码,您将最终使用空白图像,因为未设置 div 大小。它将以 0px x 0px 的宽度和高度呈现您的 div。我为您必须设置的尺寸添加了宽度和高度。设置宽度和高度将适用于像素和 em。