Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my CSS style not being applied?

Tags:

html

css

I've got this html:

<p>     <span class="fancify">Parting is such sweet sorrow!</span><span> - Bill Rattleandrollspeer</span> </p> 

...and this css (added to the bottom of Site.css):

.fancify {     font-size: 1.5em;     font-weight: 800;     font-family: Consolas, "Segoe UI", Calibri, sans-serif;     font-style: italic; } 

So, I would expect the quote ("Parting is such sweet sorrow!") to be italicized, and of a different font than the name of the quotee (Bill Rattleandrollspeer), since its span tag has the class "fancify" attached to it. The class should certainly be seen, as the file in which it appears references the layout file which uses the Site.css file.

What rookie mistake am I making now?

UPDATE

I thought maybe the problem was that I had added the new class in Site.css following this section in that file:

/******************** *   Mobile Styles   * ********************/ @media only screen and (max-width: 850px) { 

...but I moved it above there, and it is still not working, and not seen via F12 | Inspect element for the label in question.

I moved the reference to Site.css below the bootstrap.css file, which does indeed change the appearance of that text, but still not italicized, and still not seen in the element inspector...

UPDATE 2

Here's how the HTML is coming down:

<p>     <span>         <label class="fancify">Parting is such sweet sorrow!</label> 

...and here's my css rule in Site.css:

p span label .fancify {         font-size: 1.5em;         font-weight: 800;         font-family: Consolas, "Segoe UI", Calibri, sans-serif;         font-style: italic;         display: inline;     } 

...but it's not being recognized. I consider this a breech of css/html protocol, and should be adjudicated by some world body. Then again, I could be making some silly mistake somewhere.

like image 205
B. Clay Shannon-B. Crow Raven Avatar asked May 13 '13 00:05

B. Clay Shannon-B. Crow Raven


People also ask

Why is CSS styling not working?

Make sure the link tag is at the right place If you put the <link> tag inside another valid header tag like <title> or <script> tag, then the CSS won't work. The external style CAN be put inside the <body> tag, although it's recommended to put it in the <head> tag to load the style before the page content.

Why isn't my CSS file applied?

remove the leading / from the path. for example, if you had a folder called Project, and inside are your html file and another folder called static, and the css is inside the static folder, the correct path would be "static/styles. css" and adding the leading / like you have it will break it and not apply the css file.

Why are my CSS changes not reflecting?

Browser Cache If you are adding/modifying in-line CSS or JavaScript and not seeing the changes reflected in the HTML source, the page is likely being cached. The solution may be to purge the WordPress object cache, which stores our page caching (Batcache) renders.


2 Answers

There could be an error earlier in the CSS file that is causing your (correct) CSS to not work.

like image 57
Andrew Koper Avatar answered Sep 22 '22 15:09

Andrew Koper


Have you tried forcing the selectors to be in the front of the class?

p span label.fancify {      font-size: 1.5em;     font-weight: 800;     font-family: Consolas, "Segoe UI", Calibri, sans-serif;     font-style: italic; } 

Usually it will add more weight to your CSS declaration. My mistake ... There should be no space between the selector and the class. The same goes for the ID. If you have for example:

<div id="first">     <p id="myParagraph">Hello <span class="bolder">World</span></p> </div> 

You would style it like this:

div#first p#myParagraph {      color : #ff0000; } 

Just to make a complete example using a class:

div#first p#myParagraph span.bolder{     font-weight:900; } 

For more information about pseudo-selectors and child selectors : http://www.w3.org/TR/CSS2/selector.html

CSS is a whole science :) Beware that some browsers can have incompatibilities and will not show you the proper results. For more information check this site: http://www.caniuse.com/

like image 37
hayonj Avatar answered Sep 23 '22 15:09

hayonj