Home  >  Article  >  Web Front-end  >  How to stretch the background image in css

How to stretch the background image in css

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-26 15:29:5416208browse

在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;

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>

效果

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!

Statement:
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