Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用外部样式表操作图像的最佳方法是什么?没有得到以下代码的响应:
<div id="poster"><img src="squatchposter.jpg" alt="Squatch Poster"></div> #poster { background-image:url('squatchposter.jpg'); width: 400px; height: 500px; background-position: center; }
<img src="squatchposter.jpg" cssclass="poster "> #poster { width: 400px; height: 500px; background-position: center; }
您正在操纵 div 而不是图像本身。给图像标签一个 id 属性,然后在样式表中引用该 id。