-3

I have a ul tag and I want to access the a tag and change its style, this code works.

ul li a{ font-weight: bold !important; }

But when I put a class to the ul and use it. It does not work

ulClass li a{ font-weight: bold !important; }
Jonas
  • 185
  • 3
  • 14

3 Answers3

1

I have tried changing the class to id and replaced the css.

From this

.ulClass li a {font-weight: bold !important;}

To this and it worked.

#ulId li a {font-weight: bold !important;}

I don't know whats the difference can someone explain to me?

Jonas
  • 185
  • 3
  • 14
  • The first one is selecting elements which classname is ulClass, the second one is selecting an element which id is ulId. Class name and ID are different attributes. – Chaska Jul 25 '18 at 08:56
  • please show me you ul html tag. Hope you have written
      @jonas
    – Sonia Jul 25 '18 at 08:57
  • Yes and what's the difference? I want to select elements with that class and change it. But using id it works @Chaska – Jonas Jul 25 '18 at 08:58
  • Yes I have
      @Sonia
    – Jonas Jul 25 '18 at 09:01
  • Suggest you refer to this: https://stackoverflow.com/questions/12889362/difference-between-id-and-class-in-css-and-when-to-use-it , and there are number of reason failed selecting the elements by class name, you better provide html code as well to get help. – Chaska Jul 25 '18 at 09:03
0

Apply below syntax and try again.here you should use . before the class name

ul.class li a { font-weight: bold !important; }

or

.class li a { font-weight: bold !important; }
VSM
  • 1,765
  • 8
  • 18
0

@Jonas So ideally it should work with class. It could be one of the two IMO :

  • some basic error in the html skeleton

  • you've got a conflicting css rule (with !important which overrides this styling)

Mind posting the code snippet ?

the_lost_one
  • 127
  • 10