CSS attributes apply to tags outside its parameter

I can get it wrong, but; I use <ol>and <li>to create the chart. For some reason, the CSS that I applied to the tag <ol>applies to the tag <li>, but not all, some of the <li>CSS attributes apply as well as its takings attributes from both. Can someone explain why and fix it?

https://jsfiddle.net/fdo47tjv/

div.alb1 {
  background-color: rgba(255, 255, 255, 0.6);
  width: 20%;
  margin-left: 5%;
  margin-top: 15%;
  margin-bottom: 0px;
  margin-right: 0px;
  border-right: 40px solid black;
}
div.alb1 ol {
  text-decoration: underline;
  font-weight: bold;
  font-size: 25px;
  font-family: 'Roboto', sans-serif;
  margin: 10px;
}
div.alb1 ol li {
  margin: 5px;
  text-decoration: none;
  font-family: 'Roboto', sans-serif;
  font-size: 15px;
}
<body background="./resources/DSC_0146.jpg">

  <div class="alb1">
    <ol>Take Care
      <li>Over My Dead Body</li>
    </ol>
  </div>

</body>
Run codeHide result

After several attempts, I mixed up and changed the css and html so that “Take Care” would be moved to the paragraph tag outside of OL, and I changed it so that the paragraph tag had OL attributes above and it works fine, but it seems unsatisfactory, I cut the corner?

+4
3

OL li, , , li ol, , , , Show inherited, . , , . , ;-) . : http://www.w3.org/TR/html4/struct/lists.html, , , , butthurt. enter image description here

0

, , li ol.

Fix

CSS- li

li {

 font-weight: normal;
 margin: 0; }

, .

0

The style is applied because it <li>is part <ol> you can use <span>in the tag <ol>, and then apply the style to it<span>

-3
source

Source: https://habr.com/ru/post/1615931/


All Articles