search
HomeWeb Front-endCSS TutorialSharing about how to control the background with css

Sharing about how to control the background with css

Jun 20, 2018 am 11:55 AM
cssSet background color

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>
h1{ background-color:rgb(255,0,0);}
</style>

<p></p>
    <h1 id="李克强主持召开-span-国务院-span-常务会议">李克强主持召开<span>国务院</span>常务会议</h1>

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>
body{
background-image:url(fads.png);
background-repeat:no-repeat;
background-position:center right;
background-attachment:fixed;
<p>/*background:url(fads.png) no-repeat fixed center right;  简化方案*/
}
</style>


<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>
<style>
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>/*background:url(fads.png)no-repeatfixedcenterright;简化方案*/
}
</style>


<p>
</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>

3. Exercise:

1. Use span to better control the text in local areas of the text

<span>文本内容</span>
<styletype>
pspan{background:red}



<p>
35、臭男人都<span>喜欢</span>骚女人。
</p></styletype>

2. Use the display attribute to provide block conversion

<styletype>
span{
color:#0C0;
width:100px;
height:100px;
background-color:#900;
display:block;/*内联转换为区块*/
}
p{
background-color:#F63;
width:300px;
height:50px;
display:inline;/*区块转换为内联,width和height的属性就无效了*/
}



<span>使用span更好的控制文本中局部区域的文本</span>
<br>
<!--使用display属性提供区块转换--inline,block,none(不占位的隐藏)内联标记设置长宽高没效果-->
<span>使用display属性提供区块转换</span>
<p>使用display属性提供区块转换</p>
</styletype>

3. Add a small icon to the title (it is best to use the background to add the icon)

<styletype>
h5{
background:url(das.gif)no-repeatleftcenter;
padding-left:20px;
}



<h5 id="给我加个小图标吧">给我加个小图标吧</h5>
</styletype>

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!

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
How much specificity do @rules have, like @keyframes and @media?How much specificity do @rules have, like @keyframes and @media?Apr 18, 2025 am 11:34 AM

I got this question the other day. My first thought is: weird question! Specificity is about selectors, and at-rules are not selectors, so... irrelevant?

Can you nest @media and @support queries?Can you nest @media and @support queries?Apr 18, 2025 am 11:32 AM

Yes, you can, and it doesn't really matter in what order. A CSS preprocessor is not required. It works in regular CSS.

Quick Gulp Cache BustingQuick Gulp Cache BustingApr 18, 2025 am 11:23 AM

You should for sure be setting far-out cache headers on your assets like CSS and JavaScript (and images and fonts and whatever else). That tells the browser

In Search of a Stack That Monitors the Quality and Complexity of CSSIn Search of a Stack That Monitors the Quality and Complexity of CSSApr 18, 2025 am 11:22 AM

Many developers write about how to maintain a CSS codebase, yet not a lot of them write about how they measure the quality of that codebase. Sure, we have

Datalist is for suggesting values without enforcing valuesDatalist is for suggesting values without enforcing valuesApr 18, 2025 am 11:08 AM

Have you ever had a form that needed to accept a short, arbitrary bit of text? Like a name or whatever. That's exactly what is for. There are lots of

Front Conference in ZürichFront Conference in ZürichApr 18, 2025 am 11:03 AM

I'm so excited to be heading to Zürich, Switzerland for Front Conference (Love that name and URL!). I've never been to Switzerland before, so I'm excited

Building a Full-Stack Serverless Application with Cloudflare WorkersBuilding a Full-Stack Serverless Application with Cloudflare WorkersApr 18, 2025 am 10:58 AM

One of my favorite developments in software development has been the advent of serverless. As a developer who has a tendency to get bogged down in the details

Creating Dynamic Routes in a Nuxt ApplicationCreating Dynamic Routes in a Nuxt ApplicationApr 18, 2025 am 10:53 AM

In this post, we’ll be using an ecommerce store demo I built and deployed to Netlify to show how we can make dynamic routes for incoming data. It’s a fairly

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools