Tips for creating several identifiers for a single element

I'm currently exploring how to style an element differently across my website. Specifically, I have a green background for the list in my navigation bar, but I'm also creating a list in the body that is inheriting the same formatting from the nav bar.

My query is regarding how to create an ID or CLASS to remove the styling applied in my navigation bar and apply my own custom formatting to the list in the body. I've tried searching YouTube videos and Google for a solution, but all I found were methods for styling multiple selectors simultaneously.

How can I override the CSS from my navigation bar for the list in the body?

For my CLASS, I attempted using 'ul.amazon01 { background-color: none;}' but it didn't work as expected.

Here is the HTML code for my navigation bar:

<div class="flex-container">
    <div class="box1"> 
        <ul id="nav01">
            <li class="dropdown">
                <a href="#" class="dropbtn"># Menu</a>
                    <div class="dropdown-content">
                        <a href="index.html"></a>
                        <a>#</a>
                        <a href="#</a>
                        <a href="#</a>
                        <a href="#</a>
                        <a href="#</a>
                    </div>
            </li>
        </ul>
    </div>
</div>
ul {
  list-style-type: none;
  margin: 0;
  padding: 0.25rem;
  overflow: hidden;
  font-size: 1rem;
  background-color: green;
  border: 3px solid darkgreen;
}

This is the code snippet I intend to use in the body of my page:

<ul class="amazon01">
    <li>#</li>
    <li>#</li>
    <li>#</li>
    <li>#</li>
</ul>

CSS

ul.amazon01 {
    background-color: none;
}

Answer №1

In my opinion, it is not advisable to directly style HTML tags. It is better to apply styling using classes.

For example:

.nav01 {
  ...
}

You can reuse the same class multiple times if needed. By utilizing classes, you have more control over where your styling is applied and avoid the need for overriding styles.

If you encounter situations where multiple tags have overlapping styles, you can use the following syntax:

.nav01, .amazon01 {
  // Styling that applies to both classes...
}

.nav01 {
  // Detailed styling specific to .nav01... 
}

.amazon01 {
  // Detailed styling specific to .amazon01... 
}

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

Unable to trigger $(document).ready function

So I've got this content script injected into a YouTube page as part of a Chrome extension, and it looks something like this: $(document).ready(function () { console.log("[INFO] Changes detected"); myFunc(); } When I refresh the page, t ...

What is the reason behind HTML IDs being displayed as global variables in a web browser?

Browser exposes HTML IDs as global variables. <span id="someid" class="clsname1 clsname2 clsname3"></span> If you have the above HTML snippet, you can access a global variable called someid. You can interact with it in your console like this: ...

Include image hover text without using HTML

I am looking to add a hover effect to some images using CSS and JS since I cannot directly edit the HTML file. The goal is to have centered text pop out when hovering over certain images. I know the div class of the image but unfortunately, I cannot add te ...

Tips for adjusting the height and border of Bootstrap tabs

I'm facing an issue with the modal and nav-tabs I created. There are a couple of problems that need to be addressed. Firstly, the tabs have excessive height and I've tried adjusting it using CSS height property, but it's not working as e ...

exclude a few countries from ngx-intl-tel-input

I'm facing an issue where I need to remove certain countries, like Mexico, from the list displayed in ngx-intl-tel-input. Even after trying the 'excludeCountries' option, it doesn't seem to be working for me. Below is a snippet of my ...

Resizing images next to lengthy text on mobile screens

My text and image keep behaving oddly when viewed in a smaller window or on mobile. The image resizes unpredictably based on the length of the text, as shown in my preview. I attempted to use flex wrap to contain the longer text, but it only pushed the ima ...

No content in a DIV element causing unusual height in IE7

UPDATE 1: After some experimenting, I discovered that by removing the width:100% property from the div, I am able to achieve the desired outcome of having a height of 0 when the div is empty. However, I still require the div to have a width of 100%, which ...

Is it possible to create a translucent glass floating box over HTML elements, similar to the frosted glass effect seen in iOS7?

Creating an overlapping div with a frosted glass effect typically requires using an image background (like ). I am interested in having a floating div (position:fixed) that can apply a frosted glass effect over any content below it, whether it be an image ...

Videos fail to load on iPhone but load successfully on desktop and Android web browsers

I have been attempting to insert a video into my HTML page, but it's not working properly on my iPhone (I only see a crossed out play button). The video loads fine on desktop and Android devices. This issue isn't browser-related as I encounter th ...

Is there a way to open an app using a custom scheme without triggering the "open in <appname>" warning?

Trying to launch my app from Safari using a custom scheme specified in the info.plist: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>com.appvendor.rentalapp</ ...

Incorporate a variable from an HTML form into PHP for FPDF functionality

How can I retrieve a variable from an "input" element in another HTML file? <input type="text" id="client" name="clientTest" required minlength="1" maxlength="30" size="30"> I need to pass this variable to my PHP file for FPDF. It seems like I hav ...

Refreshing only a part of the page without the need to refresh the entire page

One issue I'm facing is that I have a partial that renders correctly, but I would like to update it without affecting the rest of the page. Below is my current code snippet: rolls_controller: def check_server Roll.find(params[:id]).update(:statu ...

Creating a web design using HTML and CSS to position one element at the left top corner of the page and another element at

I am looking to position two divs in a specific way on the page: one at the top left corner (black) and the other on the right side (red). https://i.sstatic.net/tKpGo.png I have considered 5 different approaches, which I've listed below. While they a ...

Using video instead of static slides in HTML5

I am interested in adding a video background with text overlay on my website, similar to what can be seen here: Although I understand it involves CSS, I am struggling to achieve the desired effect. Here is the code snippet I have been using: video#bgvid ...

Position the spinner in the center of the user's screen

I created my own spinner: '''' #spinner-bg-loading{ position: absolute; left: 50%; top: 25%; width: 80px; height: 80px; margin: -75px 0 0 -75px; border: 16px solid #FFFFFF; border-radius: 50%; border-top: 16px solid #1 ...

Tips for creating code that will allow users to update their status on a web application, similar to Twitter

I am interested in developing a web application that can receive status updates (text) from an Android device. My plan is to use Ajax and HTML for this project. I'm looking for guidance on how to dynamically update the status on the web page without r ...

How can Play framework be used to display static HTML pages with static JavaScript and CSS files?

I'm currently exploring options for rendering or routing to static web apps stored in the Play's public folder. Here is my project structure: myapp + app + conf + modules + public | + webapp1 | + css | + ...

Linking the location of the pop-up to the currently selected text box

I am currently experimenting with setting the top and left values relative to the selected_element (which is active at the time of triggering the popup) in a manner similar to a tooltip. I attempted to use $().position() in combination with jQuery, but it ...

Guide to using two UI grids simultaneously with the directives ng-hide and ng-grid

As a newcomer to AngularJS, I am attempting to create a page with two ui-grid elements and a button labeled "other-grid". The goal is for the first grid to load initially, and when clicked again, it should be replaced by the second grid. However, I am en ...

Guide on how to organize a list into three columns using a single ul tag

Is there a way to split a ul list into 3 columns using CSS? This is how my HTML structure looks like: <ul> <li>Test</li> <li>Test</li> <li>Test</li> <li>Test</li> <li> ...