Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS code not working if I put "." in front of any element

Tags:

html

css

I am using 4.5.1 Framewok and VS 2013. My problem is my CSS code doesn't work if I write the following:

.body {
  font-family: Verdana, Arial, sans-serif;
  font-size: 14px;
  background: gainsboro;
}

But if I write like this it is working:

body {
  font-family: Verdana, Arial, sans-serif;
  font-size: 14px;
  background: gainsboro;
}

What can be the reason of this? I watched some people videos in which they are using ".body", their projects are working, but if I write this too it doesn't work. Can you help me?

like image 632
Taha Karaca Avatar asked Jul 05 '15 22:07

Taha Karaca


People also ask

Why is my CSS style not being applied?

Make sure that you add the rel attribute to the link tag When you add an external CSS file to your HTML document, you need to add the rel="stylesheet" attribute to the <link> tag to make it work. If you omit the rel attribute from the <link> tag then the style won't be applied to the page.

How do you position an element in front of another CSS?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).

How do I fix CSS errors?

Replace broken CSS files with those ones that return 200 HTTP status codes or remove them. What else should be considered to fix the problem: Try to clear your browser's cache. If the page returns 5xx errors, the problem may be on the server: it's not handling the traffic because it's too slow or misconfigured.

Can elements overlap in CSS?

We can use CSS absolute positioning to overlap elements, but there's some advantages to using CSS grid instead. Let's explore using CSS grid as an alternative to position absolute.


2 Answers

"."NAME will affect all tags with class="NAME"
"#"NAME will affect the tag with id="NAME"
"NAME" will affect all html elements of the type NAME

If you want to apply the style to the BODY you have to remove the ".", If you have tags with the class="body" you then use ".body".

like image 154
GuilhE Avatar answered Sep 20 '22 14:09

GuilhE


if in your html you are using body as a tag, then in your css you have to use "body {content.... }". However, if you are using body as a class "div class="body" then you can style the div using .body.

like image 28
Victor Luna Avatar answered Sep 24 '22 14:09

Victor Luna