Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

only one rule/color to make all the lines the right color.

How do I do this?
You may only modify the CSS file and should only write one
rule/color to make all the lines the right color. The correct color is inside the text. You are also not allowed to use the comma combinator.

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Right colors</title>
    <link rel="stylesheet" href="web1.css">
</head>
<body>
    <h1>right colors</h1>
    <section class="news news-1">
        <h2>im gonna be red</h2>
        <p>im gonna be normal color</p>
        <h2>im gonna be red</h2>
        <p>im gonna be normal color</p>
    </section>
    <section class="news news-2">
        <h2>im gonna be blue</h2>
        <p>im gonna be normal color</p>
        <p>im gonna be blue</p>
        <p>im gonna be normal color</p>
    </section>
    <section class="news news-3">
        <h3>im gonna be purple</h3>
        <h3>im gonna be normal color</h3>
        <p>im gonna be normal color</p>
        <h3>im gonna be purple</h3>
        <h3>im gonna be normal color</h3>
    </section>
    <section class="news news-4">
        <h2>im gonna be normal color</h2>
        <p>im gonna be green</p>
        <p>im gonna be normal color</p>
        <h2>im gonna be normal color</h2>
        <h2>im gonna be green</h2>
    </section>
</body>
</html>

CSS:
.news {
    margin-bottom: 1em;
    padding-botton: 1em;
    border-bottom: 1px solid #cacaca;
}
 
Last edited by a moderator:
Solution
Hey there.

So basically you want to find a pattern in the coloured elements.

So for the first section, you'll see that every h2 element is coloured, so you'll want to select every h2 element inside the element with the news-1 class and make it red:
CSS:
.news-1 h2 {
  color: red;
}

For the second section, you're selecting every odd element:
CSS:
.news-2 *:nth-child(odd) {
  color: blue;
}

Third section, select every odd h3 element:
CSS:
.news-3 h3:nth-child(odd) {
  color: purple;
}

For the last section it's a bit more complicated. Look for a sequence in the form An+B where A and B are integers and n is every integer more than or equal to 0.
In this case, the sequence...
Hey there.

So basically you want to find a pattern in the coloured elements.

So for the first section, you'll see that every h2 element is coloured, so you'll want to select every h2 element inside the element with the news-1 class and make it red:
CSS:
.news-1 h2 {
  color: red;
}

For the second section, you're selecting every odd element:
CSS:
.news-2 *:nth-child(odd) {
  color: blue;
}

Third section, select every odd h3 element:
CSS:
.news-3 h3:nth-child(odd) {
  color: purple;
}

For the last section it's a bit more complicated. Look for a sequence in the form An+B where A and B are integers and n is every integer more than or equal to 0.
In this case, the sequence will be 4n+1:
CSS:
.news-4 *:nth-child(4n+1) {
  color: green;
}

You may want to take a look at CSS selectors and the :nth-child pseudo-class.
 
Solution

New Threads

Buy us a coffee!

Back
Top Bottom