It should work fine. try more lighter color #666.

Answer from Nahar on Stack Overflow
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
CSS Class to not working - HTML-CSS - The freeCodeCamp Forum
October 23, 2018 - I am try (and learning) how to define a class in CSS and call it from HTML - but no luck, Here’s the code(s): <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> ASDASDADADSA …
🌐
freeCodeCamp
forum.freecodecamp.org › html-css
HTML class not available in CSS - HTML-CSS - The freeCodeCamp Forum
May 23, 2024 - Hi, I’m learning HTML and CSS. My problem here is that he latest HTML classes I made can’t be found in CSS. All other classes work just fine. The classes that I can’t find in CSS are “center-column” ; “links-wrapper” and “right-column”. The HTML-code is as follows: ...
🌐
Quora
quora.com › Why-is-a-CSS-class-not-applying-style-HTML-CSS-Django-and-development
Why is a CSS class not applying style (HTML, CSS, Django, and development)? - Quora
Answer (1 of 2): CSS class not applying style The selector might not be choosing the detail you believe you studied it is. E.g. you need to alternate the font of paragraph text, so that you goal all of the kids of a div. But the bit you’re searching at is sincerely in a span, now no longer a p....
🌐
SitePoint
sitepoint.com › html & css
Ids and classes not working! - HTML & CSS - SitePoint Forums | Web Development & Design Community
February 25, 2012 - I can’t see anything immediately wrong to cause that problem, but I do know I’ve suffered from the same problem myself, more than once, and every time it’s been because I’ve made a daft typo with the stylesheet name or file path. Are you quite sure your stylesheet is called gpstyle.css and that it’s in the same directory as your HTML file?
🌐
Reddit
reddit.com › r/html › css class isnt applying to html tags
r/HTML on Reddit: CSS class isnt applying to HTML tags
November 23, 2018 -

For whatever reason, the class I created in a separate CSS file is not being applied to tags with that class attribute. I know its being read in right, as other elements work just fine. But classes dont. Anyone know whats going on?

HTML file

<!DOCTYPE html>
<html>
    <head>
        <title>Taco Bell Sauce Museum</title>
        <link rel="stylesheet" type="text/css" href="assign4_Style_Sheet.css">
    </head>

    <body>
        <header>
            <h1><img src="tacobell.png" alt="Logo" height="110px" width="110px"><br>Sauce Museum</h1>
        </header>
        <div id="main0">
            <div id="main">
                <div>
                    <div>
                        <div class="leftFloat">
                            <img src="CryingPepe.png" alt="NoPic" height="25%" width="25%">
                        </div>
                        <p>
                            Hot Sause
                        </p>
                    </div>
                </div>
            </div>   
        </div>
    </body>
</html>

CSS file

body {
    background-color: #3A167E;
}
#main {
    text-align: center;
    margin: auto;
    width: 70%;
}

header {
    text-align: center;
    font-family: Tahoma;
    color: white;
    font-size: 18pt;
}

#main0 {
    width: 100%;
    background-color: #ffffff;
    position:absolute;
    left:0;
    right:0;
}

h2 {
    text-align: center;
    font-family: 'Segoe UI';
    color: purple;
    font-size: 16pt;
}

p {
    font-family: 'Trebuchet MS';
    font-size: 14pt;
}

.leftFloat {
    float: left; 
    margin-left: auto;
}

.rightFloat{
    float:right;
    margin-right: auto;
}

I know its probably some stupid rookie mistake but I've been banging my head against this for an hour now.

Find elsewhere
Top answer
1 of 4
2

This class won't work. You pointed to the link with class header_nav. But you don't have it.

a.header_nav {
  font-family: arial;
  display: block;
  color:white;
  text-align: center;
  padding: 14 px 16 px;
  text-decoration: none;
}

It should be (link inside the class .header_nav)

.header_nav a {
  font-family: arial;
  display: block;
  color:white;
  text-align: center;
  padding: 14 px 16 px;
  text-decoration: none;
}

UPDATE:

I've included the snippet. Is it what you want?

body{
  background-color: #f1f6fe;
}

.header_nav{
  list-style-type: none;
  margin: 0;
  padding: 25px;
  overflow: hidden;
  background-color:#78aefa;
  width: 250 px;
}

li.header_nav{
  float: right;
  padding-right: 20px;
}

.header_nav a {
  font-family: arial;
  display: block;
  color:white;
  text-align: center;
  padding: 14 px 16 px;
  text-decoration: none;
}
<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Xander Feliers - Portfolio</title>
        <meta name="description" content="Portfolio - Xander Feliers">
        <link rel="stylesheet" href="css/screen.css">
    </head>
    <body>
      <div>
        <nav>
            <ul class="header_nav">
                <li class="header_nav"><a href="contact.html">Contact</a></li>
                <li class="header_nav"><a href="projects.html">Projects</a></li>
                <li class="header_nav"><a href="about.html">About</a></li>
                <li class="header_nav"><a href="index.html">Home</a></li>
            </ul>
        </nav>
      </div>
  </body>
</html>

UPDATE 2 Order in the CSS is really mater. If you want to enforce your style you can use !important after the style. (Although I saw the articles where it's considered as bad practice.)

.header_nav a {
  font-family: arial;
  display: block;
  color:white!important;
  text-align: center;
  padding: 14 px 16 px;
  text-decoration: none!important;
 }
2 of 4
0

I'm not sure what you are expecting, but it appears your class declarations are a little backwards. It should be class then element so,

.header_nav li { your styles }
.header_nav a { your styles }
🌐
Reddit
reddit.com › r/css › classes not working in my script
r/css on Reddit: Classes not working in my script
October 1, 2017 -

I'm trying to call a class but when I load my website it doesn't change anything.

This is the html script:

<!doctype html>

<html>

    <head>
	    <title> Practice Website </title>
	    <link href="main.css" rel="stylesheet" type="text/css" />
    </head>

    <h2> Practice website. </h2>
    <p class="yes"> It is nothing special. I am just trying to improve my skills as a web developer. </p>
    <p> If you would like to visit another site, please click on one of the links below: </p>
    <ul>
	    <li class="one"><a href="http://www.google.com"> Google </a></li>
	    <li class="two"><a href="http://www.reddit.com"> Reddit </a></li>
	    <li class="three"><a href="http://www.youtube.com"> Youtube </a></li>
    </ul>

</html>

And this is the css script:

body {
background:white;
color:grey;
padding:10px 250px;
font-family:arial;
}

.yes {
color:red;
}

I'm trying to make just the one paragraph red using the "yes" class but when I view my website it doesn't go red. Anyone know why?

🌐
Sololearn
sololearn.com › en › Discuss › 3030260 › css-class-doesn-t-work-in-my-code-how-can-i-fix-it
CSS Class doesn't work in my code, how can i fix it? | Sololearn: Learn to code for FREE!
Hi, can someone explain, why the class is not working? Everytime I try to use the .class it won't work in sololearn. https://code.sololearn.com/WcmNmwpIkILR/?ref=app · cssclass · 10th May 2022, 6:15 AM · Florian Ommert · 3 Answers · Answer · + 4 · In html, use = instead of : 10th May 2022, 6:19 AM ·
Top answer
1 of 2
1

CSS doesn't differentiate between inline, in-page or linked styles. If results between those methods differ, the reason is either erroneous including of the external file or the load order of your CSS, neither of which could be judged from the info in your question.

Furthermore, there are several problems and things to improve with the code in your question:

  • As @FrédéricHamidi commented, you're not using the content property as you should - it's only valid use is within :before and :after pseudo-elements.
  • Your img element doesn't have a src attribute, and possibly should have an alt attribute as well (since this isn't part of the question, I won't go into great detail, but a good description can be found on the MDN page.
  • Since you're using a CSS file to store your page styles, you shouldn't rely on inline styles whatsoever. Instead, add the respective attributes to those elements and address them via CSS selectors. This will give you long-time maintainability, good task management (HTML files structure content, CSS files handle display) and won't look like your first HTML page.
  • There is very little chance you actually need the float property on an absolute positioned element.

That being said, since you're apparently trying to set a background image, here is the code you would need for that:

<style>
    .wrapper {
      position: absolute;
      right: 0;
    }
    .MyClass123 {
      background-image: url("img/ic_datos_activo_48px.png");
      max-width: 100%;
      max-height: 30px;
    }
</style>

<div class="wrapper">
    <div class="MyClass123"></div>
</div>

If instead you need the image to be a part of the document flow, use the img element for that purpose. If you need to change those with CSS (this would mostly be the case if you did some JS manipulation), a clean way to do it would be to creature multiple image elements and hide them as needed:

<style>
    .image2, .image3 {
      display: none;
    }
</style>

<div>
    <img class="image1" src="img1.jpg" alt="Image 1" />
    <img class="image2" src="img2.jpg" alt="Image 2" />
    <img class="image3" src="img3.jpg" alt="Image 3" />
</div>

If you need to set the src to a previously unknown value entirely, you would be better off solving this via JS anyway, as CSS is for design purposes, not for content manipulation (with a handful of exceptions, yours not being one of them). For completeness' sake, here's a jQuery one-liner on how to tackle the problem:

$('.MyClass123').attr('src', 'new_url.jpg');
2 of 2
0

Change the code to:

.MyClass123 {
   max-width: 100%;
   max-height: 30px;
   float: left;
   position:absolute; 
   right:0
}

<div>
    <img class="MyClass123" alt="Image" src="img/ic_datos_activo_48px.png"/>
</div>
🌐
Unbounce
community.unbounce.com › landing-page-review-37 › custom-css-class-not-working-5935
Custom CSS Class not working | Community
October 25, 2019 - Hey guys, I have been using the custom class quite a lot for my last landing page project. It worked perfectly fine. Now, I am trying to use the same functionality on another page and the custom css does not display when I use my custom class. When I insert the unbounce ID of the element instead, ...
🌐
PythonAnywhere
pythonanywhere.com › forums › topic › 12695
Some CSS classes not working! : Forums : PythonAnywhere
The CSS files are the same, and the majority of the CSS is working on the site, but certain CSS classes do not seem to be loading if I check Dev Tools. The site: http://resilientstudio.pythonanywhere.com/GR/ Eg: .Title --- centered titles are not centered on the online app (eg: http://resilientstudio.pythonanywhere.com/GR/shutdown/) .underline --- I had a class to underline and make links black (to override bootstrap), I had to manually write this into the HTML to work because I could not get the CSS to populate, even with an important tag!
🌐
CSS-Tricks
css-tricks.com › forums › topic › why-is-my-class-not-being-applied
Why is my class not being applied? - CSS-Tricks
May 6, 2016 - I want to give some buttons an orange background color with white font. I added a css class to accomplish that, and tried to apply it using all the