Transforming each link into a formatted navigation bar in HTML

I added a logo to the top of my page but it ended up looking like my navigation bar. I suspect it's because of how I styled my nav bar. Even when I tried to adjust the logo's formatting using inline CSS, it didn't solve the issue.


My Custom CSS :

ul {
    list-style-type: none;
    margin: 7;
    padding: 0;
    overflow: hidden;
}

li {
    float: left;
}

h2 {
    color:#FFFFFF;
    font-family:impact;
    text-align:center;
    text-decoration:underline;
} 

a:link, a:visited {
    display: block;
    width: 314px;
    font-weight: bold;
    color: #FFFFFF;
    background-color: #21242B;
    text-align: center;
    padding: 1px;
    text-decoration: none;
    text-transform: uppercase;
}

a:hover, a:active {
    background-color: #4D5365;
}

.divstory {
    background-color:#B33951;
    width: 500px;
    height: 100px;
    border: 3px solid #73AD21;
}

My HTML Code :

<body background="webbackground.png">
<a href="index.html"><img src="DTDTMLogo.png" style="width: 180px; margin-bottom: 5px;" ></a>
<hr>
<!--Nav Bar-->
<ul>
    <li>
        <a href="index.html" style="color:white;font-size:20px">Home</a>
    </li>
    <li>
        <a href="database.html" style="color:white;font-size:20px">Database</a>
    </li>
    <li>
        <a href="map.html" style="color:white;font-size:20px">Map</a>
    </li>
    <li>
        <a href="https://www.papajohns.com/" style="color:white;font-size:20px">About Us</a>
    </li>
</ul>
<!-- Nav Bar End-->
<hr>
<img alt="When Your In The Action" src="Gamers_in_action1.jpg" style="width:1260px;height:600px;">
<hr>
<h2>Our mission</h2>
<div>
<p>
</body>

Snapshot :

https://i.sstatic.net/pTcbY.png

Answer №1

All your a elements are given the same styling because of selectors like a:link, a:visited, etc.

To solve this problem, it's necessary to make your selectors more specific.

An easy solution is to replace:

a:link, a:visited {
    display: block;
    width: 314px;
    font-weight: bold;
    color: #FFFFFF;
    background-color: #21242B;
    text-align: center;
    padding: 1px;
    text-decoration: none;
    text-transform: uppercase;
}

a:hover, a:active {
    background-color: #4D5365;
}

with:

ul a:link, ul a:visited {
    display: block;
    width: 314px;
    font-weight: bold;
    color: #FFFFFF;
    background-color: #21242B;
    text-align: center;
    padding: 1px;
    text-decoration: none;
    text-transform: uppercase;
}

ul a:hover, ul a:active {
    background-color: #4D5365;
}

However, this would still affect all a elements within a ul.

To avoid this, consider assigning a class to your menu items, like so:

<ul class="main-navigation">
    <li>
        <a href="index.html" style="color:white;font-size:20px">Home</a>
    </li>
    <li>
        <a href="database.html" style="color:white;font-size:20px">Database</a>
    </li>
    <li>
        <a href="map.html" style="color:white;font-size:20px">Map</a>
    </li>
    <li>
        <a href="https://www.papajohns.com/" style="color:white;font-size:20px">About Us</a>
    </li>
</ul>

Then, adjust your selectors as follows:

.main-navigation a:link, .main-navigation a:visited {
    display: block;
    width: 314px;
    font-weight: bold;
    color: #FFFFFF;
    background-color: #21242B;
    text-align: center;
    padding: 1px;
    text-decoration: none;
    text-transform: uppercase;
}

.main-navigation a:hover, .main-navigation a:active {
    background-color: #4D5365;
}

This guarantees that ONLY your main navigation links (or other a elements within an element with the class .main-navigation) will be affected.

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

The Bootstrap Modal will still appear even in the presence of a validation error

Recently, I created a sign-up page using HTML and Bootstrap 5. To ensure data validation on the form, I integrated Bootstrap's validation feature. However, after completing the registration process, a modal pops up as intended. The only issue is that ...

Use CSS height:auto for every element except SVG

Is there a way to scale all images on my site while excluding SVG files using native CSS? .myClass img { height: auto; } I have tried the following, but it only targets SVG files: .myClass img[src$=".svg"] {height: auto;} Using != doesn't seem ...

Learn how to create a PHP activity feed that functions like Facebook, and discover the best methods for converting JSON responses into HTML

We are currently working on a website that functions similarly to Facebook, specifically focusing on the activity feed. To load the user's activity feed, we use AJAX to send a request to a PHP file which then processes the logic and returns the values ...

Is it feasible to access the PHP code of a website?

Is it within the realm of possibility to access and view the PHP files and codes of other websites? In other words, can individuals without access to the files see my PHP codes? If this is a concern, what is the most effective way to safeguard against it ...

How can you achieve a full-width hover effect on your website?

I am working with Bootstrap 5 to create dropdown navigation, but I am facing some challenges with implementing a hover effect that covers the full visible width. I would greatly appreciate it if someone could provide me with detailed explanations on how to ...

Modifying the onclick function of an HTML select element - easy steps!

I have customized the click event on my select tag to trigger a specific action. However, when I click on the select tag, the default option list is also displayed. I want to bypass this default behavior and only execute my custom action when the select ta ...

Guide to leveraging clsx within nested components in React

I am currently using clsx within a React application and encountering an issue with how to utilize it when dealing with mappings and nested components. For instance: return ( <div> <button onClick={doSomething}>{isOpened ? <Component ...

Space left vacant following an unordered list item

Is there a way to remove unwanted space after an unordered list in IE and Firefox, specifically in the last HTML <li> item? I've tried adjusting the ul width but it didn't work. Any ideas on how to get rid of the space? Thanks. #menubar ...

The hamburger menu functions properly on the homepage but is not working on the individual about page

The burger menu was causing issues initially due to a simple spelling mistake, which I only noticed later. However, the current issue seems more complex. I am now creating separate pages for different sections of my website, such as About Me, Education, et ...

Is there a way to access the badge hidden behind the collapsible menu in bootstrap 4?

After moving from bootstrap 3 to bootstrap 4, my items no longer align properly. I've scoured the entire Internet for a solution, but I've run out of options (and patience.. haha) This is how it currently looks: https://i.sstatic.net/ra22j.png ...

Is there a way to execute a POST command in HTML without utilizing a form tag?

Currently, I have a form that gathers input from the user and redirects to a new page upon submission by clicking a button. However, I am looking for a way to automatically open this destination page when the current page loads, without the need for manual ...

The layout of webpages on Internet explorer 11 or IE 8 may appear differently than on Chrome or Mozilla

While coding a webpage using cshtml, I encountered an issue with a link pointing to a doc or pdf file in a Windows server location. In Windows Explorer, the file could be opened by clicking the link, but Chrome or Mozilla did not allow me to open the file ...

JavaScript: Can you clarify the value of this variable using five sets of double quotations?

Could you please review the code snippet below for me? <script type="text/javascript"> function recentpostslist(json) { document.write('<ul class="recommended">'); var i; var j; for (i = 0; i < json.feed.entry.length; i++) { ...

Retrieving information from a database utilizing SQL queries

Looking for a way to list the number of orders and their total value without using sub-select in SQL? SELECT u.name, COUNT(o.id) AS order_count, SUM(oi.quantity * p.price) AS total_price FROM users u INNER JOIN orders o ON o.user_id=u.id LEFT JOIN ...

Is it possible to adjust the background size using jQuery?

When attempting to set backgroundSize with jQuery using the code provided, I consistently encounter an error on the fourth line: "unexpected identifier." bigwidth = 200; bigheight = 100; $(e.target).css({backgroundImage: 'url(' + ...

Include the entire HTML script within a PHP file

Apologies in advance for this beginner question, but I need to get it right. I have created a website with all HTML files that are functioning properly. Now, for session handling, I need to convert all the HTML files to PHP code like below: <!DOCTYPE H ...

Leveraging a Django form across multiple web pages

For my most recent project, I am incorporating a straightforward contact form that directs to the URL /email/. I would like to integrate this form onto the homepage as well. In previous projects, I utilized get_context_data when dealing with a page class i ...

When files are uploaded to the server, the hyperlinks fail to function properly

I am currently facing an issue with the admin side panel dropdown links on a project I am working on. The admin panel includes both regular links and dropdown elements. While the single links are functioning properly, the dropdown is not opening to displ ...

The jQuery regular expression for validating US postal codes is not functioning correctly

After implementing the code snippet provided, I noticed that no alert message is being displayed when non-numeric values are entered into the Zipcode field. Can someone please help me troubleshoot this issue? $("input:text[name='address_1[zip]&apos ...

Issue encountered while attempting to implement custom fonts through CSS

When attempting to implement a custom font on my website using the CSS file, I am having trouble getting it to display correctly. Instead of seeing the desired font, only the default font is showing up. Can someone please review the CSS code below and le ...