Write CSS to change the text colour and background of a paragraph
Description: Create a paragraph with white text on a dark blue background, with some padding.
Hint:
- Use
colorfor the text andbackground-colorfor the background. - Add
paddingso the text does not touch the edges.
CSS for text colour and background
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: white;
background-color: darkblue;
padding: 12px;
}
</style>
</head>
<body>
<p>White text on a dark blue background.</p>
</body>
</html>
Output in the browser:
Output in the browser
White text on a dark blue background.
How it works
- The selector
papplies the rule to every paragraph. colorchanges the text colour, andbackground-colorchanges the area behind it.
Read CSS Colors.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |