HTML Academy
The vertical-align property, vertical text alignment
Typography10/20
Back to the list of tasks
  • 1. The font-size property
  • 2. Relative font size
  • 3. The line-height property
  • 4. Relative line height
  • 5. The font-family property
  • 6. The font-weight property
  • 7. The text-align property, horizontal text alignment
  • 8. The text-align property does more than just align text
  • 9. The vertical-align property, vertical text alignment
  • 10. Use of the background in typography
  • 11. The color property, text color
  • 12. Using margins to format the text
  • 13. The white-space property, space management
  • 14. Assignment of styles to preformatted text
  • 15. The text-decoration property, underlining as well as other effects
  • 16. The font-style property, italics
  • 17. The text-transform property, character case
  • 18. Shave space off the footer
  • 19. Summary of “Typography”
  • 20. Test: Designing an article
The color property, text color
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Use of the background in typography

Another important property of text is its color. It is controlled by the color property. You will learn more details about this property and its values in the next assignment. In this assignment we will learn how to use the background of the block to enhance the typography as well as what are the best combinations of background and text colors.

The color is most frequently specified in CSS using the hexadecimal format with a hashtag at the beginning:

#000000 — Black;
#ffffff — White;
#ff0000 — Red, etc..

The background image for the block can be set using the background-image property, and the background color can be set using the background-color property:

div {
  background-image: url("path_to_image_file.png")
  background-color: #cccccc;
}

The background image and the background color of the block should always strongly contrast with the text color. The greater the contrast, the easier it will be to read the text under different lighting conditions and on different devices. Therefore, we set a background image for a block, we must additionally set a suitable background color. In this case, the text can still be read while the image is still loading or if it fails to load at all:

/*
  An ideal level of contrast:
  the text color is white, the background color is black
*/

p {
  background-color: #000000;
  color: #ffffff;
}

/*
  A bad level of contrast:
  the text and background colors are both gray
*/

span {
  background-color: #cccccc;
  color: #ddddddd;
}

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>The website of a beginning coder</title> <link rel="stylesheet" href="style.css"> </head> <body> <header> <p class="page-title">Blog</p> <nav class="blog-navigation"> <a href="index.html">Return to home</a> </nav> </header> <main> <article> <h1>Day Two. I want to become a coder</h1> <p>Today I spent the whole evening on the Internet. I read about the advantages of working as a coder. I often spent my free time watching cat videos, of course. But then I remembered something:</p> <ul> <li>You are helping a useful cause</li> <li>You can work remotely</li> <li>Interesting people</li> <li>Good salary</li> </ul> <p>My desire to learn has dramatically increased.</p> </article> <aside> Your ad could go here </aside> </main> <footer> Website footer </footer> </body> </html>
CSS
body { padding: 0 30px; font-size: 16px; line-height: 26px; font-family: "Arial", sans-serif; color: #222222; background: #ffffff url("img/bg-page.png") no-repeat top center; } h1 { font-size: 24px; line-height: normal; } h2 { font-size: 20px; line-height: normal; } a { color: #0099ef; text-decoration: underline; } .page-title { font-weight: bold; font-size: 36px; line-height: 42px; font-family: "Verdana", sans-serif; text-align: center; } .avatar-container { text-align: center; } .avatar { border-radius: 50%; } .blog-navigation { margin-bottom: 30px; padding: 20px; color: #ffffff; background-color: #4470c4; border: 5px solid #2d508f; } .blog-navigation h2 { margin-top: 0; } .blog-navigation ul { padding-left: 0; list-style: none; } .blog-navigation li { margin-bottom: 5px; } .blog-navigation a { color: #ffffff; } .skills dd { margin: 0; margin-bottom: 10px; background-color: #e8e8e8; } .skills-level { font-size: 12px; text-align: center; color: #ffffff; background-color: #4470c4; } .skills-level-ok { background-color: #47bb52; } footer { margin-top: 30px; }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0
    1. Add a partnership class to the <aside> block,
    2. then assign a background color for the text by assigning background-color the value #4a87fa in the rule for .partnership.
    3. Then specify a background image by assigning background-image the address url("img/bg-partnership.svg"),
    4. then set the text color by assigning color the value #ffffff.

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.