Using CSS for one style change?

Hi,

I’m new to HTML/CSS and going through fcc curriculum at the moment (which is great). My question is this. I have already added a CSS entry to style the

elements for my web pages as I use a common style for the majority of my text across my whole site.

If I have to style a few other

elements differently and it requires only one change (in this case, centering text instead of dressing left), should I use an inline item like this in the html document:

<p style="text-align: center"

or use an ID attribute and entry in my CSS file. In both cases it’s only one extra entry in the html code. What is best practice regards coding? My sense is, the idea is to keep as much styling as possible in the css file?

Welcome to the forum @rob88blu !

Good question. I suggest keeping all of your styles in an external stylesheet.

For styling flexibility, remember you can add more than one class to an element’s class attribute, so to center just some of the elements, you could create a .center selector for that.

Happy coding!

“More than one class to an element’s class attribute”?

Excuse my ignorance, what do you mean?

If I want to make a paragraph’s text red and bold, I could add selectors to my stylesheet like this:

.red {
  color: red;
}

.bold {
  font-weight: bold;
}

And then apply them like this:

<p class="red bold">Some important text in red goes here</p>

OK, I remember that now. In your example, you can do this right?

.red-bold {
color: red;
font-weight: bold;
}

I was going to ask if you can do the same with ID attributes, use two of them in your html statement.

you can give only one id to an element, and the id can only appear once in the document

so it seems what you are looking for are classes