The anchor tag is not displaying CSS styling as expected

The links on my page are not displaying the styling from the CSS file I added.

HTML:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Title</title>
        <link rel="stylesheet" type="text/css" href="formatter.css">
    </head>
    <body>
        <h1>Welcome</h1>
        <hr/>
        <div class="anch" style="text-align: center">
            <a href="admin_login.jsp" style="" >Admin</a>
            <a href="user_login.jsp">User</a>
        </div>
    </body>
</html>

formatter.css:

body{
    font-family: Verdana, Arial, sans-serif;
    color: #555;
    background-color: silver;
}
h1{
    text-align: center;
}
.anch a:link, a:visited{
    text-decoration: none;
    display: inline-block;
    color: black;
    background-color: white;
}
.anch a:hover, a:focus, a:active{
    text-decoration: none;
    display: inline-block;
    color: white;
    background-color: black;
}

After running the above files, the body and h1 styles show up correctly, but the anchor styles do not apply. They remain default (blue and underlined). View an image of the issue here:

https://i.sstatic.net/zqHUF.jpg

Answer №1

Provide styling instructions for a. Then apply different styles for hover, active, and other states.

.anch a{

    text-decoration: none;
    display: inline-block;
    color: black;
    background-color: white;

}
.anch a:link, a:visited{
    text-decoration: none;
    display: inline-block;
    color: black;
    background-color: white;
}
.anch a:hover, a:focus, a:active{
    text-decoration: none;
    display: inline-block;
    color: white;
    background-color: black;
}

Answer №2

Remember, CSS pseudo classes are defined with a colon :, not with a dot ..

a:link, a:visited {
 text-decoration: none;
 display: inline-block;
 color: black;
 background-color: white;
}

a:hover, a:focus, a:active {
 text-decoration: none;
 display: inline-block;
 color: white;
 background-color: black;
}

If you want to learn more about this topic, check out this resource.

Answer №3

Consider creating a distinct class for anchor tags that can be utilized whenever necessary.

<a href="somelink" class="customAnchorClass">SomeThing</a>

Apply the following CSS:

.customAnchorClass{
    text-decoration: none;
    display: inline-block;
    color: white;
    background-color: black;
} 

Answer №4

In the snippet below, note that instead of using a dot in CSS with a tag, a colon is utilized. Additionally, an example for styling the anchor with a CSS class is provided.

body{
    font-family: Verdana, Arial, sans-serif;
    color: #555;
    background-color: silver;
}
h1{
    text-align: center;
}
.anch a:link, a:visited{
    text-decoration: none;
    display: inline-block;
    color: black;
    background-color: white;
}
.anch a:hover, a:focus, a:active{
    text-decoration: none;
    display: inline-block;
    color: white;
    background-color: black;
}
/* This is the css code for anchor styling */

.anchor{    text-decoration: none;
    display: inline-block;
    color: black;
    background-color: white;}
/* When mouse hover the anchor class */
.anchor:hover{
    text-decoration: none;
    display: inline-block;
    color: white;
    background-color: black;
}
<div class="anch" style="text-align: center">
<a href="admin_login.jsp" style="<!--You can use style here too -->" >Admin</a>
<a href="user_login.jsp">User</a>
</div>
</br> <!-- This br is for line space -->
</br> <!-- This br is for line space -->
</br> <!-- This br is for line space -->
<b> You can style your anchor tags with css class too. Here is the example</b>
</br> <!-- This br is for line space -->
</br> <!-- This br is for line space -->
</br> <!-- This br is for line space -->
<center>
<a href="admin_login.jsp" class="anchor">Admin</a>
<a href="user_login.jsp" class="anchor">User</a>
</center>

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

Arrange a pair of div containers side by side on the webpage without the need to alter the existing

Is there a way to align these two div side by side? <div class="main_one"> <div class="number_one">Title A</div> </div> <div class="main_two"> <div class="number_two">Title B</div> </div> <div class=" ...

What is the best way to ensure a grid element has a column designated for each of its children?

Imagine this HTML structure: /* Desired styling: */ .container { display: grid; grid-template-columns: 250px 250px 250px /* this is the part to automate */ grid-template-rows: 50px; } .child { width: 100%; height: 100%; background: ...

Console not displaying any logs following the occurrence of an onClick event

One interesting feature I have on my website is an HTML div that functions as a star rating system. Currently, I am experimenting with some JavaScript code to test its functionality. My goal is for the console to log 'hello' whenever I click on ...

Tips for crafting HTML emails that avoid users inadvertently selecting extra spaces while copying and pasting

There is an email that I send out with a specific string that needs to be copied and pasted only once. The issue arises when users copy the string from Outlook as they tend to unintentionally include an extra space at the end of it. Although I understand ...

Using jQuery to fetch LDAP data and return it in JSON format

I am encountering an issue with a returned JSON value. When the LDAP result is valid, the JSON return is also OK but when the result is invalid, the JSON becomes invalid as well. I am using UWamp and I am new to this. Thank you all. PHP code : <?php ...

The pagination feature for Swiper is experiencing issues across both desktop and mobile platforms

I am having an issue with the pagination display in the text. I would like it to appear below the text as a standalone item for better visibility. Another problem arises when viewing the page on mobile devices - the hamburger menu displays behind the slid ...

I am looking to automatically add a line of HTML text to the notifications list without requiring the user to manually refresh the page

Having trouble articulating the correct term or language I need, making it difficult to search. Q: How can I push a line of text from the server side to the user? I am developing an MVC 4 application using asp.net and c# in .net4. One page will feature a ...

Tips for ensuring that each flexbox element fills up a single line

My goal is to have each child element fill up one line by itself. See this screenshot for reference: https://i.stack.imgur.com/F40Xm.png Below is the code I am currently using: main { display: flex; justify-content: space-around; align-items: ...

What could be causing the background rainbow animation to malfunction?

.colorful { background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab); animation: change 10s ease-in-out infinite; } @keyframes change-color { 0% { background-position: 0 50%; } 50% { background-position: 100% 50%; } 10 ...

Display the JSON data in a table when the button is clicked

My goal is to display JSON data retrieved from a web service in a table format only after a button click. Although I have successfully fetched the data, I want it to be visible in a table only upon clicking the button. The current code displays table row n ...

How to effectively eliminate the border of a single cell within a Bootstrap Table

Is there a way to remove the border of a single cell in a bootstrap table without affecting the others? I attempted using an id on that specific cell and adding the following CSS code: #borderless-cell { border: 0; } Unfortunately, this solution doesn&ap ...

Responsive design with three collapsible panels that are arranged horizontally

Is there a way to create collapsible horizontal panels in Bootstrap that are responsive, similar to the example shown below? I would greatly appreciate it if someone can demonstrate how this can be achieved. https://i.sstatic.net/ign56.jpg Thank you so ...

Ensure that Bootstrap4 cards are fully stretched to a width of 100%

Does anyone know how to make Card2 and Card3 in Bootstrap4 stretch to 100% width? Card1 defines the total height, but Card2 and Card3 are not taking up the full remaining width. Card1 is already stretched, but Card2 and Card3 are inside a flex column and a ...

What is the best way to incorporate a horizontal scroll bar that remains fixed at the bottom of the screen?

Within my main container, I have a div that has a height fitting perfectly into the main container but a width wider than the main container with an overflow for the horizontal scroll bar. The challenge that I am facing is: 1. Instead of requiring the use ...

Swapping out for <br />

I am currently working on a feature that allows users to enter text into a textarea and send it as the body of an email. The challenge I am facing is automatically adding new lines when users press enter in the textarea. The mailing functionality works, b ...

Ways to adjust the number of columns in a div using Bootstrap for varying screen sizes of larger devices

https://i.sstatic.net/1nHlm.pngI am new to coding and exploring html, css, and bootstrap. Is it possible to assign varying numbers of columns to a div based on different resolution ranges for larger devices? Specifically looking at the "lg" range which co ...

Using JavaScript to convert the text within a div into negative HTML code

I am working with this specific div: <div class="signs" id="signs" onclick="toggle()">&#43;</div> It currently displays the positive sign. I have set up a JavaScript function that is triggered when the div is ...

JavaScript enables the deletion of a class

In HTML 2, I am able to show different statements based on the scenario. These statements are styled using the Bootstrap alert class. The goal is to ensure that when new data is sent, any old communication disappears without causing overload on the page. ...

Refresh choices for the user interface selection menu

I've successfully mastered the art of redefining options for Webix ui.richselect/ui.combo. The technique involves: richselect.getList().clearAll(); richselect.getList().parse(options_data) Now, I'm facing a challenge with changing options fo ...

"Utilizing a range input element with a set value on the slider

I have implemented the input type range property on my webpage and have applied some CSS styling to it. However, I feel like there is room for improvement. .Slider { -webkit-appearance: none; width: 75%; height: 15px; border-radius: 5px; backg ...