使用 CSS width 属性实现响应式图片
cssweb developmentfront end technology更新于 2024/8/25 23:08:17
将响应式图片的 width 属性设置为 100%。您可以尝试运行以下代码,使图片实现响应式效果
示例
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content="width=device-width, initial-scale = 1.0">
<style>
img {
width: 100%;
height: auto;
}
</style>
</head>
<body>
<p>To check the effect, you need to resize the browser.</p>
<img src = "https://www.cainiaomax.com/python/images/python-data-science.jpg"
alt = "Python Data Science" width = "400" height = "300">
</body>
</html>
相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

