0

How to apply css to element having same class name.i want apply css to both how can I do this?
I try many times but don't get it right way.

<div class="a">...</div>
<span class="a">..</span>

I am writing my css inside HTML itself inside <script> tag

2
  • Your question is not specific enough to give you an answer for this. Do you want to make both elements with the a class to have the same styles or different or what do you need? You should extend your question with more details. Commented Feb 23, 2017 at 9:49
  • i will sir thank u i am new in SO that's why it is happening :) @Kovah Commented Feb 23, 2017 at 9:50

3 Answers 3

3

try this in your css file

.a{

// css that u want to apply
}
Sign up to request clarification or add additional context in comments.

4 Comments

let me try kishan i will let you know :)
if u put css file in same html then write above code inside <script> tag
@kishanoza the <script> tag???????? That's for Javascript (hence the name) - <style> is for CSS
@kishanoza that comment was deleted quickly! :D np, mistakes happen :)
0

When targeting classes in CSS you must do it as follows:

.a {
  color: red
}
<a class="a" href="#">This is a link</a>
<div class="a">This is a div</div>
<span class="a">This is a span</span>

This will target all elements with this class a, as shown.

Comments

0
div.a {
    color: red;
}

span.a {
    color: blue;
}

by this you can apply different css to elements having same class.

To apply same CSS to all elements try this.

.a {
    color: red;
}

1 Comment

copy of another's answer :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.