Search code examples
csshtmlstyles

How not to use body style css rule in part of html code?


I have this body style CSS rule . I wonder how I could keep the rule, but only not use it for a part of my code that starts immediately after <body>? The code that starts immediately after the <body> is around 5 hyperlinks,just one below each other .

At this moment the current CSS formats the hyperlink size and fonts which I don't want; is there a way that these hyperlinks have their own font or size or have default values (basic format) ? How can this be done ?

CSS rule:

body {
  direction: ltr;
  font-size: 62.5%;
  color: #555;
  font-family: Tahoma, Arial, Helvetica, Verdana, Sans-Serif;
  z-index: 1;
}

code after <body>:

<a href="./link1.html">link1</a>  <br />
<a href="./link2.html">link2</a>  <br />
<a href="./link3.html">link3</a>  <br />
<a href="./link4.html">link4</a>  <br />
<a href="./link5.html">link5</a>  <br />

Solution

  • Specific rules override general rules in CSS. The basic example is below:

    body {
      direction: ltr;
      font-size: 62.5%;
      color: #555;
      font-family: Tahoma, Arial, Helvetica, Verdana, Sans-Serif;
      z-index: 1;
    }
        
    a {
      font-size: 42.5%;
    }
    

    Update

    HTML:

    <div id="example">
      <a href="./link1.html">link1</a>  <br />
      <a href="./link2.html">link2</a>  <br />
      <a href="./link3.html">link3</a>  <br />
      <a href="./link4.html">link4</a>  <br />
      <a href="./link5.html">link5</a>  <br />
    </div>
    

    CSS:

    body {
      font-size: 62.5%;
      color: #555;
    }
    
    #example a {
      font-size: 42.5%;
      color: red;
    }