Connecting a CSS file with an HTML document

Having an issue with my CSS.

For instance, here is a snippet from my CSS file

.readmore {
    font-style: italic;
    text-decoration: none;
    color: #509743;
    padding-left: 15px;
    background: url(../images/more.png) no-repeat 0 50%;
}
.readmore:hover{
    color: #c8c8c8;

}

Although the code looks fine in the CSS file, it doesn't work when called from the HTML file. But if I duplicate the CSS code directly into the HTML file, it works perfectly.

This is the HTML code that works

  <div class="col-xs-2 col-md-4" style="position:relative; top:20px; margin-left:10px;">
    <div class="thumbnail">

      <div class="caption">

      <h4>A propos de  <strong><span style="color:#509743;">L'agence</span></strong></h4>   


                <img src="images/logo_agence.gif"/><br><br>
           <p><a href="#" class="readmore">...</a></p><br><br>

        </div>
      </div>
    </div>

However, I find this approach unprofessional and aesthetically unpleasant.

             <div class="col-xs-2 col-md-4" style="position:relative; top:20px; margin-left:10px;">
    <div class="thumbnail">

      <div class="caption">

      <h4>A propos de  <strong><span style="color:#509743;">L'agence</span></strong></h4>   


                <img src="images/logo_agence.gif"/><br><br>
           <p><a href="#" style="
    font-style: italic;
    text-decoration: none;
    color: #509743;
    padding-left: 15px;
    background: url(images/more.png) no-repeat 0 50%;

hover{
    color: #c8c8c8;

}">...</a></p><br><br>

        </div>
      </div>
    </div> 

The hover effect doesn't seem to be functioning correctly.

Appreciate any help you can provide. Thank you.

Answer №1

Have you successfully connected your CSS to your HTML file? If you've used a link element, it should be placed within the <head> section of your document and have this structure:

<link href="path/to/your/stylesheet.css" rel="stylesheet" type="text/css">

Ensure that all three attributes are included. If it's not working, first verify that the path is accurate. You can check in the network tab of your browser's developer tools to confirm if the CSS file is being located (an incorrect path may result in a 404 error).

It's also important to confirm that the server is sending the file with the correct MIME type. It should read as text/css.

By the way, the use of :hover won't function because pseudo-selectors cannot be applied within inline styles.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What Could Be Causing My Webfonts to Be Inaccessible on Windows Devices and iPhones?

I recently created a simple holding page on www.tomrankinmusic.com The Webfonts I embedded in the page display correctly in the latest versions of Firefox, Safari, and Chrome on Mac OSX Lion 10.7.4 but do not show up in Chrome and IE6 on Windows XP Pro, d ...

jQuery and Bootstrap collide

Here is my jQuery code that toggles visibility of different divs based on a click event: $(function () { $(".kyle-div, .tracey-div, .frank-div, .rosie-div").hide(); $("a").bind("click", function () { $(".conor-div, . ...

Utilizing Bootstrap 4 cards in conjunction with a responsive next/image component

<div className="row align-items-center justify-content-center"> <div className="col-md-3 mt-3"> <div className="card bg-light"> <div className="card-img-top"> <N ...

Scroll the div back to the top when the form is submitted

I have set up a form in a pop-up using Bootstrap modal. The form is quite long, so after submission, the message appears at the top of the form. However, I want it to scroll to the top when the user submits the form so they can easily see the message. Is ...

What is the solution to adding values from a counter?

I am trying to create a JavaScript counter: function animateSun() { var $elie = $("#sun"); $({ degree: 0 }).animate({ degree: 360 }, { duration: 190999, easing: 'linear', step: function(val) { now = Math.round ...

What are some strategies to stop text from causing the container height of the <li> element to expand?

Link to my code on Plunker In my attempt to create a fluid layout, the sidebar of my site consists of a list of links. I am trying to make each <li> element a perfect square, but when I add text inside, it disrupts the dimensions and turns the squar ...

Get all the counter values from a Bootstrap table within a function

Suppose I have a table displaying 25 records per page with 10 rows. How can I update the counter values for Entries and Total Entries in my function when I filter by "india"? I already have the showing values but need to retrieve the Entries and Total Ent ...

Display the list items within a div only if the height is lower than a separate div

I have a scenario where I have two divs named left and right. The left div contains a list of bullets (li elements) and is floated to the left, while the right div has text and HTML content. At times, either the left or the right div may be taller than the ...

Preselecting items in PrimeNG Checkbox: A step-by-step guide

How can I ensure that the already selected item is displayed upon loading this div? The code in `rp` consists of an array of type Permission with one element, which should be automatically selected. What could be causing the issue? Here is the HTML snippe ...

Working with JavaScript Events within an Iframe

Is it possible to link an onclick event to an IFrame? I attempted using the HTML attribute, but that approach was unsuccessful. Next, I enclosed it within a div, which also did not work. Finally, I tried setting up a jQuery event handler, only to encounte ...

Having trouble unchecking a checkbox in reactjs?

Hey there, I've been using a checkbox on my website and for some reason, I can't seem to uncheck it. Any ideas why? const [checkBoxEmailPersonalized, setCheckBoxEmailPersonalized] = useState(false); const onEmailPersonalized = (event) =& ...

Is it possible to incorporate two ng-repeat directives within a single td element in a table?

The results so far Expected outcome Please advise me on how to incorporate two ng-repeats within one td. When I use a span tag afterwards, the expected result is not achieved. I have used one ng-repeat in the td and the other in a span tag, which is why t ...

Using Angular2, you can dynamically assign values to data-* attributes

In my project, I am looking to create a component that can display different icons based on input. The format required by the icon framework is as follows: <span class="icon icon-generic" data-icon="B"></span> The data-icon="B" attribute sp ...

Python Django: Implementing Proper Spacing in HTML Email Titles

We are currently working on integrating the email feature using Python Django, but we are encountering an issue with extra spaces appearing in the header of the emails as shown in these screenshots: https://i.sstatic.net/EpCca.png https://i.sstatic.net/q6 ...

jquery add to table id, not to a table within

Having trouble adding a table row to a specific table ID without it appending to other tables with different IDs nested inside. I've searched for a solution but can't seem to find one. Can someone help me figure out what I'm doing wrong? Her ...

Why is the updated index.html not loading with the root request?

I'm currently working on an Angular app and facing an issue with the index.html file not being updated when changes are made. I have noticed that even after modifying the index.html file, requests to localhost:8000 do not reflect the updates. This pro ...

What is the best way to adjust a <textarea> to fit a multi-column layout?

Here's a cool way to display text in columns: <div class="content-box" style="column-width: 8em"> <p>blah blah...</p> <p>blah blah...</p> <p>blah blah...</p> </div> However, when it comes to the ...

Experiencing trouble with implementing multiple textboxes based on option selection using javascript

My JavaScript code is supposed to display multiple textboxes based on the user's selection, but for some reason, I can only select one textbox at a time. I'm not sure what's wrong with my code. Here's the snippet of the code: <ht ...

Position a Bootstrap 3 division within a central division for ultimate centering

I have written a code snippet that looks like this- html, body, .container-table { height: calc(100% - 50px); } /*Centering a div*/ .container-table { display: table; } .vertical-center-row { display: table-cell; vertical-align: middle; } < ...

Modify the style of a webpage through JavaScript

Need help with calling a JS event based on button presses and changing CSS font styling accordingly for each button? Check out the code snippet below: body { background-image: url("back2.jpg"); background-size: 100% 100%; } ...