Home >Web Front-end >CSS Tutorial >Sharing about how to control the background with css
This article mainly introduces the example of css control background. Here is the method of setting background image and setting background color with css. Friends who need it can refer to it
1. Set the background color: background -color
Hexadecimal background-color:#ff0000;
English name background-color:red;
Three primary colors background-color:rgb(255,0,0)
transparent background-color:transparent;transparent
<style type="text/css"> h1{ background-color:rgb(255,0,0);} </style> </head></p> <p><body> <h1>李克强主持召开<span>国务院</span>常务会议</h1> </body>
2. Set the background image:
1. Introduce the background image: background-image
URL background- image:url("bg.jpg")
none Do not set the background image
2. Set the tiling method of the background image: background-repeat
repeat Fill the entire background with the background pattern.
repeat-x Fills the background pattern in the horizontal direction
repeat-y Fills the background pattern in the vertical direction.
no-repeat The pattern appears only once.
3. Set the position of the background image: background-position
top left Set the background pattern to appear on the top left.
top center sets the background pattern to appear in the top center.
top right Set the background pattern to appear on the top right.
center left Sets the background pattern to appear in the center left.
center center sets the background pattern to appear in the middle of IE.
center right Set the background pattern to appear in the center right.
bottom left Sets the background pattern to appear at the bottom left.
bottom sets the background pattern to appear directly below.
bottom right Set the background pattern to appear on the bottom right.
You can also accurately locate the position of the picture through coordinates (x, y) x horizontal position y vertical position, the unit is pixels (px)
4. Set the background image Whether it will scroll as the window scrolls: background-attachment
scroll sets the background image to move as the window scroll bar moves (default).
fixed The background image will not move with the movement of the window scroll bar.
Simplified format of background pattern: color background picture repeat attachment position
<style type="text/css"> body{ background-image:url(fads.png); background-repeat:no-repeat; background-position:center right; background-attachment:fixed;</p> <p>/*background:url(fads.png) no-repeat fixed center right; 简化方案*/ } </style> </head> <body> <p>48、完美的男友:不吸烟,不喝酒,不欺骗。不存在!</p> <p>49、人生就像一块破铜烂铁,把它扔进火里,敲敲打打,也能炼出一副精品!</p> <p>50、话说动物园有一只猴子,奇丑无比,人见人吐!第二天我去看了,我吐了!第三天你去了,猴子吐了!</p> <p>25、哥是文明人,所有脏话均已使用唾液消毒。 </p> <p>26、名人名言,你得先是名人了那才是名言,别人的屁都是名屁!你能比吗? </p> <p>27、您都好意思撒谎了,我哪敢好意思不信呢? </p> <p>28、为什么我眼里常含眼屎,那是我对睡眠爱的深沉。 </p> <p>29、别以为你比我年轻,你就能多蹦跶几天,棺材装的是死人不是老人! </p> <p>30、我是穷人,请勿盗墓!</p> <p> 31、有时候老天下一场雨,是因为世界需要洗一洗;有时候眼睛下雨了,是因为心需要洗一洗! </p> <p>32、站在岁月的岸边,向自己的过往打个水漂吧……</p> <p>33、2011我娶你,2012我保护你,2013爱你一生,2014爱你一世! </p> <p>34、人生就像一场旅行,在乎的不是目的地。而是沿途的"SB",以及对付"SB"时的心情! </p> <p>35、臭男人都喜欢骚女人。</p> <p> 36、系好安全带,前方也许有场爱情正等着你。 </p> <p>37、枕着打印机睡,就能打印出一整夜的梦吧? </p> <p>38、没有强大的主人,别以为你是狗就可以乱咬人!</p> <p> 39、我只顾着往后看,却没有在意前面的路有多长。 </p> <p>40、最近神马开始变驴腿了,浮云变雨水了!</p> <p> 41、昨天是历史,今天是开始,明天谁都不好使! </p> <p>42、还是10086对我好,我给他发一条对短信,他给我回3条。 </p> <p>43、靠山吃山,靠水吃水,今天抢劫,不许不给,谁要反抗,让他见鬼。 </p> <p>44、今天MM的生日,为了第一个送上祝福,凌晨我准时拿起手机发了一条信息:沙发。 </p> <p>45、知道高晓松为啥喝醉酒不?那是因为药家鑫想让他唱一首"同牢的你"。</p> <p> 46、地铁上的广告:挤吗?买辆车吧!出租车上的广告:赌吗?坐地铁吧!靠,忽悠我还是怎么着! </p> <p>47、一般般的我,一般般的亮。一般般的你,我看不上!</p> </body>
<style type="text/css"> p{ width:800px; height:600px; background-color:#ccc; background-image:url(fads.png); background-repeat:no-repeat; background-position:topright; /*background-attachment:fixed;当给一个p设置背景是使用该属性有可能无效*/</p> <p>/*background:url(fads.png)no-repeatfixedcenterright;简化方案*/ } </style> </head> <body> <p> <p>35、臭男人都喜欢骚女人。</p> <p>36、系好安全带,前方也许有场爱情正等着你。</p> <p>37、枕着打印机睡,就能打印出一整夜的梦吧?</p> <p>38、没有强大的主人,别以为你是狗就可以乱咬人!</p> <p>39、我只顾着往后看,却没有在意前面的路有多长。</p> <p>40、最近神马开始变驴腿了,浮云变雨水了!</p> <p>41、昨天是历史,今天是开始,明天谁都不好使!</p> <p>42、还是10086对我好,我给他发一条对短信,他给我回3条。</p> <p>43、靠山吃山,靠水吃水,今天抢劫,不许不给,谁要反抗,让他见鬼。</p> <p>44、今天MM的生日,为了第一个送上祝福,凌晨我准时拿起手机发了一条信息:沙发。</p> <p>45、知道高晓松为啥喝醉酒不?那是因为药家鑫想让他唱一首"同牢的你"。</p> <p>46、地铁上的广告:挤吗?买辆车吧!出租车上的广告:赌吗?坐地铁吧!靠,忽悠我还是怎么着!</p> <p>47、一般般的我,一般般的亮。一般般的你,我看不上!</p> </p> </body>
3. Exercise:
1. Use span to better control the text in local areas of the text
<span>文本内容</span> <styletype="text/css"> pspan{background:red} </style> </head> <body> <p> 35、臭男人都<span>喜欢</span>骚女人。 </p>
2. Use the display attribute to provide block conversion
<styletype="text/css"> span{ color:#0C0; width:100px; height:100px; background-color:#900; display:block;/*内联转换为区块*/ } p{ background-color:#F63; width:300px; height:50px; display:inline;/*区块转换为内联,width和height的属性就无效了*/ } </style> </head> <body> <span>使用span更好的控制文本中局部区域的文本</span> <br/> <!--使用display属性提供区块转换--inline,block,none(不占位的隐藏)内联标记设置长宽高没效果--> <span>使用display属性提供区块转换</span> <p>使用display属性提供区块转换</p> </body>
3. Add a small icon to the title (it is best to use the background to add the icon)
<styletype="text/css"> h5{ background:url(das.gif)no-repeatleftcenter; padding-left:20px; } </style> </head> <body> <h5>给我加个小图标吧</h5> </body>
Above That’s the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to use CSS to control front-end image HTTP requests
The above is the detailed content of Sharing about how to control the background with css. For more information, please follow other related articles on the PHP Chinese website!