HTML Academy
Cascade
CSS essentials13/17
Back to the list of tasks
  • 1. CSS rules
  • 2. Selectors
  • 3. Properties and values
  • 4. Inheritance
  • 5. Inheritable properties
  • 6. Non-inheritable properties
  • 7. Shorthand properties
  • 8. Types of values: Absolute and relative
  • 9. Tag and class selectors
  • 10. Nested selectors
  • 11. Default styles
  • 12. Cascade
  • 13. Property conflict
  • 14. Multiple classes
  • 15. Embedded styles and the style attribute
  • 16. Summary of “CSS fundamentals”
  • 17. Test: Travel gallery. Appearance
Multiple classes
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Property conflict

We’ve seen that a single element’s final styling can be derived from several CSS rules. If the same properties are assigned different values by these rules, then a conflict arises. For example:

ul { list-style: disc; }                   /* Browser styles */
.blog-navigation ul { list-style: none; }  /* Our styles */

Styles with varying list-style property values can affect one and the same list in our blog. This presents a conflict, since, after all, a property can have only one value.

The browser needs to choose the final value when declarations conflict. For the ordinary rules in these exercises, we can compare three things in order. If one comparison does not decide the result, move to the next:

  1. Compare where the declarations come from. For these ordinary declarations, our author styles take priority over the browser’s default styles.
  2. The specificity of the selectors for CSS rules with conflicting properties is compared. For example, the class selector is more specific than the tag selector.
  3. The property that is located lower in the code wins.

Remember margin: 0; for .skills dd in the last step. The property from our styles conflicted with the property that was assigned by the browser’s default styles, but our rule has a higher priority and cancelled the browser’s default assigned margins.

There was another conflict with the .skills dd rule when margin-bottom appeared there:

margin: 0;
margin-bottom: 10px;

The cascade also works within a CSS rule. Here, margin-bottom conflicts with the bottom margin set by the shorthand. The separate margin-bottom declaration wins because it comes later:

margin-left: 0;   /* From a shorthand property */
margin-top: 0;    /* From a shorthand property */
margin-right: 0;  /* From a shorthand property */
margin-bottom: 0; /* From a shorthand property */
margin-bottom: 10px;

Now let’s turn the percentages for our skills into progress bars. To do this, you will have to add additional decorative wrappers to the markup, and the <div> tag that we are already familiar with is best suited for this. The initial styles for the progress bars are already in place.

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> <h1>The website of a beginning coder</h1> </header> <main> <img class="avatar" src="img/raccoon.svg" width="80" height="80" alt="Avatar"> <nav class="blog-navigation"> <h2>Recent Posts</h2> <ul> <li><a href="day-1.html">Day One. How I forgot to feed the cat</a></li> <li><a href="day-2.html">Day Two. I want to become a coder</a></li> <li><a href="day-3.html">Day Three. My cat is upset with me</a></li> <li><a href="day-4.html">Day Four. How I almost got sick</a></li> <li><a href="day-5.html">Day Five. I am relaxing</a></li> <li><a href="day-6.html">Day Six. How I failed to understand anything</a></li> <li><a href="day-7.html">Day Seven. Muffin gave me an assignment</a></li> <li><a href="day-8.html">Day Eight. It’s getting very serious</a></li> <li><a href="day-9.html">Day Nine. Or, more precisely, night</a></li> <li><a href="day-10.html">Day Ten. Summing up</a></li> <li><a href="day-11.html">Day Eleven. Everything in moderation</a></li> <li><a href="day-12.html">Day Twelve. Everyone loves cookies</a></li> <li><a href="day-13.html">Day Thirteen. I found an article</a></li> <li><a href="day-14.html">Day Fourteen. A New Format</a></li> <li><a href="day-15.html">Day Fifteen. The Selfie Gallery</a></li> </ul> </nav> <section> <p>Greetings to everyone! Welcome to my first site. Up until just recently I had no idea what a coder does for a living, but now I have found <a href="https://htmlacademy.org/courses">interactive courses in HTML and CSS</a> and I have set myself the goal of becoming one. I was even assigned an instructor, Muffin, who won’t let me slack off and will keep track of my progress.</p> <p>My first assignment is to keep a diary and honestly write about all of my accomplishments.</p> </section> <section> <h2>Skills</h2> <dl class="skills"> <dt>HTML</dt> <!-- Enclose the contents of the dd tags below in a div tag --> <dd>60%</dd> <dt>CSS</dt> <dd>20%</dd> <dt>JS</dt> <dd>10%</dd> </dl> </section> </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: 36px; line-height: normal; } h2 { font-size: 20px; line-height: normal; } a { color: #0099ef; text-decoration: underline; } .avatar { border-radius: 50%; } .blog-navigation { margin-bottom: 30px; padding: 20px; background-color: #4470c4; border: 5px solid #2d508f; color: #ffffff; } .blog-navigation h2 { margin-top: 0; } .blog-navigation ul { list-style: none; padding-left: 0; } .blog-navigation li { margin-bottom: 5px; } .blog-navigation a { color: #ffffff; } .skills dd { margin: 0; margin-bottom: 10px; background-color: #e8e8e8; } /* Uncomment the rule below */ /* .skills-level { font-size: 12px; text-align: center; color: #ffffff; background-color: #4470c4; } */ 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. Enclose the contents of each dd tag in a <div> tag with the class skills-level.
    2. Uncomment the rule with the .skills-level selector in the styles.

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

    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.