How do I select more than one element from my HTML that belongs in the same class?
I want to select the h3 element aswell as the paragraph element from the same single class.
I tried doing it like this, but it seems to just make every paragraph on the page get selected
.skill-row {
width : 50%;
margin : 100px auto 100px auto;
text-align : center;
}
.skill-row h3,p {
text-align : left;
}
<div class="skill-row">
<img class="" src="./images/computer.png" alt="Picture of a computer">
<h3>Lorem & Ipsum</h3>
<p>
Lorem ipsum dolor sit amet, quis in duis, iaculis id felis.
Consectetuer vestibulum, nunc urna lectus, erat ligula.
Hendrerit nam, lectus ante, ut lorem eros.
</p>
</div>
Now as you can see from the snippet, this works out great,
BUT! The other paragraph tags on my page get selected aswell and get set to float to the left.
Could someone explain what is happening or what I am doing wrong?
I Just want to select the h3 and p elements from the skill-row class and set there text-align to the left
3
Answers
Try this:
typing only "p" after comma makes that css downloading all paragraphs from your app
If you want to select specific elements that are inside of other element, you can write something like this :
It will select all headings and paragraphs that are inside element with class
.skill-row
If you want to choose only those elements that are direct children of
.skill-row
, you can use :If you write something like :
you can see that you are just choosing every paragraph element, that is on your page
If you want one liners you can try " .skill-row > * ". This will select all direct children (in your case the img too) of a parent that has the skill-row class.
You can also try adding classes/IDs to the elements in question and just line them up when writing the selectors.