使用 CSS 实现背景图片的响应式效果
cssweb developmentfront end technology更新于 2025/7/1 8:12:17
您可以尝试运行以下代码,使用 CSS 实现背景图片的响应式效果 −
示例
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content="width = device-width, initial-scale = 1.0">
<style>
div {
width: 100%;
height: 300px;
border: 2px dashed blue;
background-image: url('https://www.cainiaomax.com/python/images/python-data-science.jpg');
background-repeat: no-repeat;
background-size: contain;
}
</style>
</head>
<body>
<p>To check the effect, you need to resize the browser.</p>
<div></div>
</body>
</html>
相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

