Home > Enterprise >  Is there a way to use the same ID multiple times using CSS?
Is there a way to use the same ID multiple times using CSS?

Time:03-06

I'm kind of new to this, and I couldn't find any other places online that show how to do this. I apologize if this is a stupid question, so if it is, instead of downvoting or removing my thread, please link a tutorial on it.

<p id = "formatOne">My text here</p>
<!--insert bunch of other stuff in between-->

<!--Reuse formatOne so I don't have to copy-paste the entire CSS formatting again for each use
(similar to functions in most programming languages, write once, call whenever-->

<p id = "formatOne">Different text here</p> <!--like this, but this is obviously wrong since ID must be unique-->

Is there a way to make CSS ID's that are callable like functions?

CodePudding user response:

id should be unique per HTML element. If you want to apply same style to different HTML elements, you can create class and apply the same class to multiple HTML elements.

.formatOne {
  color:blue;
}
<p >My text here</p>
<p >Different text here</p> 

CodePudding user response:

This is not possible with ids. If you want same multiple uses in css then only class allow you to do so.

<body>
<div >
    <h1> First </h1>
    <p> Second line Statement </p>
</div>
<style>
.asd {color : red;
  font-size: 20px}
</style>
</body> 
  • Related