"CSS dropdown menu with the item in an open state by

I have a list of images with the names of the people they belong to displayed below each image in an unordered list (UL). When hovering over a person's name, a sentence related to that person should be revealed.

Here is what it looks like:


            <ul>
            <li>
                <a href="#">Name</a>
                <ul>
                    <li><a href="#"></a></li>
                    <li class="slogan1"><a href="#">some kind of sentence</a></li>
                </ul>
            </li>
            <li>
                <a href="#">Name 2</a>
                <ul>
                    <li><a href="#"></a></li>
                    <li class="slogan1"><a href="#">some kind of sentence</a></li>
                </ul>
            </li>
            </ul>

Currently, the child UL element of the first LI element only appears on hover. I want it to display initially when the page loads. I tried using :first-child but it didn't work for me.

The relevant CSS code snippet is shown below:


ul li ul{
display: none;}

ul li:hover ul{
display: block;}

ul li:hover ul li a{
background: #009EE3;
height:10px;}

ul li:hover ul li.slogan1 a{
background: #009EE3;
height:45px;
width:958px;
position:absolute;
left:0px;
padding-top:5px;
line-height:130%;}

For more information and to see the current implementation, visit Link to page

Any help, tips, or hints would be greatly appreciated. Thank you!

Answer №1

first-child was a brilliant approach; just make sure to include:

ul li:first-child ul {
    display:block;
}

JSFiddle Link

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

Is there a way for me to implement this code to achieve the functionality shown in the demo link

$('select').change(function() { var sum = 0; var sum = parseInt($('select[name="bathrooms"]').val() * 25) + parseInt($('select[name="bedrooms"]').val() * 8); $("#sum").html(sum); }); <script src="https://ajax.googleap ...

Is there a way to stop the page from scrolling once I reach the bottom of a specific div within it?

My webpage has multiple divs that share a similar structure: <div style="height:200px; overflow:auto;"> <div style="height:300px;"> <!--There is a lot of content here--> </div> </div> When the user hovers ove ...

Embedding the scrollbar within the div container

I'm having trouble placing my vertical scrollbar inside my div and adjusting its position. To streamline the code, I have extracted a portion below: .toprightcontrols { margin: 0 3% 0 0; display: flex; position: absolute; justif ...

Getting the Innertext of a Web Element Using Dynamic Path in Selenium

Currently, I have a VBA macro running in Excel 2016 that retrieves information from the internet using Chrome and Selenium WebDriver. The macro navigates through various webpages, each with slightly different content structures. This variation leads to cha ...

The Bootstrap container is extending beyond the boundaries of the page view

Since I'm not a CSS enthusiast, I opted to incorporate Bootstrap into my small project. However, I've encountered an issue where one of the containers is extending beyond the page view, and I can't seem to figure out why. <!-- STYLE ...

Disordered block elements

I am having trouble centering a div in my footer. When I try to center it, the div ends up floating on top of the footer instead. Here is the link to the codepen. footer { text-align: center; background-color: grey; position: fixed; bottom: 0; width: 100 ...

Buttons for concealment and revelation are unresponsive

I have the following code snippet for uploading an image, which is taken from a template utilizing bootstrap 2. <div class="span6"> <div class="control-group"> <label class="control-label">Imagen</label> <div cla ...

Positioning the box at the exact middle of the screen

I'm trying to center an item on the screen using material ui, but it's appearing at the top instead of the middle. How can I fix this? import * as React from 'react'; import Box, { BoxProps } from '@mui/material/Box'; functio ...

Crafting a radiant sun with ThreeJS

I am working on designing a solar system in WebGL but I am facing challenges with setting up the lighting. My main goal is to incorporate a light source within the sun that casts light in all directions, while ensuring that my planets can both cast and rec ...

The text-decoration is here to stay

Currently, I am facing an issue with the customization of a wordpress theme related to the styling of links within posts. Although I have tried to change the color and remove underlining using CSS rules, I am unsuccessful so far: a, .entry-meta a, entry-c ...

Issue with Bootstrap dropdown list not opening up

Having an issue where the Bootstrap dropdownlist is not displaying its list of contents when clicked. I attempted to add the jQuery library before the bootstrap.min.js file, as suggested in a solution on Stack Overflow, but unfortunately, it did not work ...

Modifying the Inactive Tab Color in Material UI

For my application, I have a specific requirement where the active tab needs to be styled in red and the inactive tab in blue. Here is how the styling is set up: newStyle: { backgroundColor: 'red', '&$selected': { b ...

Angular 2: Change Boolean value depending on a condition

I find myself facing a challenge with a search-bar feature. My goal is to display all the filtered names when the input value reaches a length of 2 or more characters. After successfully extracting the value.length from the input field, I encountered a ro ...

Mixing up letters using a shuffle function

Seeking assistance as a newcomer here. I have a shuffle function triggered by pressing the reset button with class="reset" on the img tag. How can I make it load shuffled from the start? So that when loading this page, the letters do not appear in alphabet ...

What is the most effective way to alter the text color using jQuery?

Whenever I want to create a text hover animation, jQuery is my go-to tool. Is there a snippet of code that can change the color or size of the text in this case? ...

What is the best way to transfer data from an HBS template (HTML) to an Axios POST request?

Just diving into nodejs and express! I want to pass the user input (an email) to axios.post request's data when the "submit" button is clicked. I've verified that hard-coded data in the axios request is functioning correctly. data_email.hbs &l ...

Issue with Bootstrap 5 dropdown menu on mobile devices when not sliding down upon clicking

Important things to know before getting started: Utilizing Django (python) Implementing Bootstrap Additionally, using html and css Steps taken (in sequence leading up to encountering an error): Copied the navbar template from the bootstrap navbar docume ...

Design a new CSS grid arrangement

Need help with achieving a responsive layout using CSS grid. The design should be as seen in the image link below for resolutions over 900px:- https://i.sstatic.net/QaFub.jpg For resolutions lower than 900px, the layout should switch to resemble this ht ...

CSS not being loaded in CodeIgniter

Am I losing my mind dealing with CSS and Codeigniter? I can't figure out if it's a permissions issue or something else... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <ht ...

Connect the checkbox input to the text input

I'm facing an issue where I need to tie a checkbox input to a text input in my form. Here's the scenario: I am extracting data from a database. The primary key data serves as the value for the checkboxes. When a checkbox is selected, it should ...