How do I use CSS to set the background color of my text? CSS Set background color code

Source: Internet
Author: User
Tags set background
CSS settings text background color code you know what? Here is a detailed CSS implementation of the background color of a complete example, so that you can more easily understand the meaning of these properties is what it is, now let's look at it together





First, let's take a look at this code:



Background-color: Property sets the background color of the element (the value has three kinds: color_name: (English color name) \hex_name: #000000 (hexadecimal character color) \rgb_name:255.0.0 (not used))



Take a look at an example of a text background:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>topic.alibabacloud.com</title>
</head>
<style type="text/css">
body{background-color:red}
</style>
<body>
<p>Here is topic.alibabacloud.com. Many excellent programming tutorials are waiting for you to learn</p>
</body>
</html>
The effect of setting this should be obvious. Let's look at the effect displayed in Google Browser:
Looking at the picture, we can see clearly that the displayed part of the web page has turned red. This is because I set the background style of CSS in the body, so that the main part of the whole body is red. Isn't it obvious.
Let's take a look at how to set the text background effect: (this also includes code)
</head>
<style type="text/css">
p{background-color:red}
</style>
<body>
<p>Here is topic.alibabacloud.com, many excellent programming tutorials are waiting for you to learn < / P > < p > here is topic.alibabacloud.com, many excellent programming tutorials are waiting for you to learn < / P > < p > here is PHP Chinese
Many excellent programming courses are waiting for you to learn</p>
</body>
The style we added to the body now gives the P label. What happens in this way? Let's see the effect together:
Because the P tag is a block level element, our display effect is to occupy a whole line in a paragraph. Let's try the elements of labels in other lines to see the situation. The same code, different labels, let's see:
<body>
<span>Here is topic.alibabacloud.com. Many excellent programming tutorials are waiting for you to learn < / span > < p > here is topic.alibabacloud.com. Many excellent programming tutorials are waiting for you to learn</p>
</body>
This is to change the first p tag to span tag. Let's compare:
I've changed the CSS style of span to blue, which is the effect we see now. One is the in line label, which is where the text goes to the background, and the other is the block level element. No matter whether you go to a line or not, the background is displayed in a line. (if you want to see more knowledge about CSS styles, go to the topic.alibabacloud.comcss learning manual)
Now let's talk about the code of the background picture
Background image: URL (image address) sets the background image for the element
Background repeat: sets whether or how to repeat the background image (repeat, repeat-x (repeat horizontally), repeat-y (tile vertically), no repeat)
Background position: set the starting position of the background image (top, bottom, left, right, center,% \ PX)
I have written my own understanding of these attributes. You should know how to use it when you look at the introduction, but we still need to demonstrate it to you. Let's demonstrate it together:
<style type="text/css">
P{backgroud-image:url; backgroud-repeat:no-repeat; backgroud-position:top}<! -- the URL of the image address; backgroud-repeat:no-repeat; does not tile. Background position: top, start from above background image -- >
</style>
<body>
<p>Here is topic.alibabacloud.com. Many excellent programming tutorials are waiting for you to learn</p>
</body>
Because there is no picture, there will be no effect. You can set it yourself. The normal values are all in it.
OK, that's the article about setting the background color of the text in CSS style. You can ask questions below.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.