How to stretch the background image in css

醉折花枝作酒筹
Release: 2023-01-07 11:45:44
Original
16257 people have browsed it

在css中,可以使用background-size属性让背景图拉伸,只需要给元素设置“background-size:100% 100%;”样式即可。该属性可以以父元素的百分比来设置背景图像的宽度和高度。

How to stretch the background image in css

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

background-size 属性规定背景图像的尺寸。

语法

background-size: length|percentage|cover|contain;
Copy after login

How to stretch the background image in css

实例:

<!DOCTYPE html>
<html>
<head>
<style> 
div
{
background:url(/i/bg_flower.gif);
background-size:35% 100%;
-moz-background-size:35% 100%; /* 老版本的 Firefox */
background-repeat:no-repeat;
}
</style>
</head>
<body>

<div>
<p>这是一个段落。</p>
<p>这是一个段落。</p>
<p>这是一个段落。</p>
<p>这是一个段落。</p>
<p>这是一个段落。</p>
<p>这是一个段落。</p>
<p>这是一个段落。</p>
<p>这是一个段落。</p>
<p>这是一个段落。</p>
</div>

</body>
</html>
Copy after login

效果

How to stretch the background image in css

推荐学习:css视频教程

The above is the detailed content of How to stretch the background image in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template