Customize .dropdown-content style to correspond with unique button IDs using CSS

I am currently working on a splash page that features 3 dropdown buttons, each associated with a specific color representing a geological time period. I am trying to customize the formatting of the .dropdown-content for each button to reflect its base color. However, whenever I attempt to use the id tag to modify the attributes of each button's '.dropdown-content', it ends up breaking the code. Below is the 'broken' css:

.dropbtn {
  color: black;
  padding: 16px;
  font-size: 15px;
  cursor: pointer;
}

#left.dropbtn {
  border-color: #f57a5f;
  background-color: rgba(245, 122, 95, 0.2);
}

#middle.dropbtn {
  border-color: #9DC2A6;
  background-color: rgba(157, 194, 166, 0.2);
}

#right.dropbtn {
  border-color: #47C7EA;
  background-color: rgba(71, 199, 234, 0.2);
}

/* The container <div> - needed to position the dropdown content */
.dropdown {
  position: relative;
  display: inline-block;
}

/* Dropdown Content (Hidden by Default) */
#left.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f57a5f;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

#middle.dropdown-content {
  display: none;
  position: absolute;
  background-color: #9DC2A6;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

#right.dropdown-content {
  display: none;
  position: absolute;
  background-color: #47C7EA;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  font-size: 15px;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: rgba(157, 194, 166, 0.2)}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
  display: block;
}

/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover #left.dropbtn {
  background-color: #f57a5f;
}

.dropdown:hover #middle.dropbtn {
  background-color: #9DC2A6;
}

.dropdown:hover #right.dropbtn {
  background-color: #47C7EA;
}
<div class="jumbotron">
  <div class="container">
    <div class="wrapper">
      <h2><t id="the">The</t> Wowsers</h2>
      <p>Revealing stuff & knowledge & things</p>
      <div class="row">
        <div class="dropdown">
          <button id="left" class="splashMainButton btn btn-info dropbtn">Learn</button>
            <div class="dropdown-content">
              <a href="">Teach & Learn</a>
              <a onclick="">News & Info</a>
            </div>
        </div>
        <div class="dropdown">
          <button id="middle" class="splashMainButton btn btn-info dropbtn">Data</button>
            <div class="dropdown-content">
              <a href="">Enter</a>
              <a href="">Visualize</a>
              <a href="">Retrieve</a>
              <a href="s">Browse</a>
            </div>
        </div>
        <div class="dropdown">
          <button id="right" class="splashMainButton btn btn-info dropbtn">Join & Support</button>
            <div class="dropdown-content">
              <a href="">Join!</a>
              <a onclick="">Patreon!</a>
              <a onclick="">Merch</a>
            </div>
        </div>
      </div>
      <div class="row">
      </div>
      <div class="row">
      </div>
    </div>
  </div>
</div>

Is there an issue with the CSS nomenclature? Should I be adding an id to each .dropdown-content?

Answer №1

Remember to include a space after each ID, for example:

#top .menu-items

This is important because .menu-items is a child of #top.

If you don't add a space, it indicates the element with both an ID of top and a class of menu-items.

Additionally, IDs should be unique, so there's no need for this:

#sidebar.menu-button

You can target the element using just the #sidebar selector.

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

Having trouble with images not showing up on React applications built with webpack?

Hey there! I decided not to use the create react app command and instead built everything from scratch. Below is my webpack configuration: const path = require("path"); module.exports = { mode: "development", entry: "./index.js", output: { pa ...

Saving updated numerical value on the server and receiving immediate feedback

I'm looking to implement a real-time website counter that decreases by 1 every 10 minutes. I believe this can be achieved easily using JavaScript. However, I also need a way to store the current number (not on the client side) so that visitors see upd ...

Switch out the image source and add attributions until the AJAX call is complete

<div id="fbAdsIconDiv" class="social_icon"> <img src="~/Content/images/fbAdsAddOn_1.png" onclick="toggleImage(this)" id="fbAdsAddOn" data-toggle="tooltip" title="click to enable" class="confirmBox f ...

Struggling to center items on a page with Bootstrap 5

I'm attempting to center an item on the page using Bootstrap flex boxes in HTML. However, I am having trouble with the align-items-center attribute not working. <!DOCTYPE html> <head> <link href="https://cdn.jsdelivr.net/npm/& ...

How to center an image within a div without it moving

I have set up a JSFiddle for reference: http://jsfiddle.net/AsHW6/ My task involves centering the down_arrow.png images within their respective div containers. I have successfully centered the up_arrow.png images using auto margins. These images are posit ...

Switching between light and dark mode in R Shiny tables with customizable headings

I'm currently working on a visualization project for tracking Covid-19 data, and I'm having trouble changing the text color above and below a table I've created. I've attached an image to show exactly what needs to be modified. Additio ...

Passing a selected value from the child to the parent component through state in React using hooks

I'm currently working on a Dropdown component that includes a select tag. When the user changes the value in the select, the state is updated to reflect the selected option. The StyledDropdown component is used for styling the select element. const D ...

Generate an array of HTML files from external sources and randomize their placement within multiple div containers

I am currently working on a website that features a grid made up of divs (4x4) which need to have a set of texts shuffled into them every time the page is reloaded. You can see what it looks like here. Within my index.htm file, I have the following struct ...

Removing white spaces from response HTML in JBoss 5.1 version

Does anyone know of a JBoss 5.1 plugin or utility that can automatically strip leading and trailing white spaces from HTML being sent as a response? Similarly, is there a way to do this for JSP files upon deployment? Any application-specific settings would ...

Loop through and store data in Node.JS within an array

Initially, I attempted to use a simple for loop to iterate through the data. However, this approach didn't work due to the nature of request.save being a function. After some experimentation, I decided to utilize forEach instead. Everything seemed to ...

Click on a div to switch between displaying an arrow pointing to the right and an arrow

Currently working on a design for an accordion-style layout and looking to implement toggling arrow icons when the div is clicked. I have managed to toggle the content of the div successfully, but now seeking assistance in achieving the same functionality ...

The angular.copy() function cannot be used within angular brackets {{}}

Within my controller, I am utilizing the "as vm" syntax. To duplicate one data structure into a temporary one, I am employing angular.copy(). angular.copy(vm.data, vm.tempData = []) Yet, I have a desire to transfer this code to the template view so that ...

Automatically scrolling down with Vue3 and Ionic: A seamless scrolling experience

In the process of developing a VueJS App with Ionic, there is a Chat feature involved. It is crucial for users to view the latest message first and not the oldest one, so it is necessary for the app to open with the container scrolled to the bottom. Additi ...

Trying to locate the subsequent div element following the current one

Here is an example of some HTML code: <div style="display: inline-block; position: absolute; top: 84px; bottom: auto; left: 5px; right: auto; width: auto; height: auto; max-width: none; max-height: none;" _afrc="2 1 8 1 start top><strong>CRED ...

Developing a jQuery loop

I am in the process of creating a function that will change the background color (color A), box color (color B), and text color (color A) when a user clicks on the refresh button. I have already defined an array called 'colors', but I am struggli ...

Data is not displaying correctly in the Angular Material Table

I'm currently trying to build a mat table based on an online tutorial, but I'm facing a problem where the table appears empty even though I have hard coded data. As someone new to Angular and HTML/CSS, I'm struggling to understand why the ma ...

Easily validate the contenteditable attribute of <td> element

I am currently working on a table that displays data from a MYSQL database. Whenever a user makes changes to an element in the table, I want the database to be updated using AJAX. Below is my JavaScript code for sending data in an editable row. function s ...

The slidedown feature is not functioning as initially planned

As a beginner in HTML, jQuery, and CSS, I am attempting to create a navigation bar that will trigger a jQuery slidedown effect when clicked. Unfortunately, my current code is not producing the desired outcome. Below is a snippet of what I have implemente ...

Displaying a clock using PHP

Seeking a way to display server time on my website, I have successfully implemented client-side time using JavaScript. How can I now showcase the server time? Are there any ZendFramework classes that can assist with this? Currently, I am utilizing the fo ...

I find it difficult to customize columns in grid template areas

I am having trouble adjusting the width of my header's columns to be 24vw, 24vw, 4vw, 24vw, and 24vw respectively. Despite specifying these widths, the browser is rendering all columns with equal width. Specifically, I am unable to change the width of ...