Press the list button to reveal an enlarged box

Each item on this list contains a hidden box that should be shown after it is clicked. However, the issue arises when expanding one item causes other items to expand as well.

Refer to the image for clarification: Image Link

Is there a way to only expand the specific item that was clicked?

<li>
  user name test
  <div class="content">
    <span>
      A card can be used to display content related to 
      a single subject. The content can consist of multiple 
      elements of varying types and sizes.
    </span>
  </div>
</li>
<li>
  user name test
  <div class="content">
    <span>
      Another example of the content within a card element.
    </span>
  </div>
</li>

View Demo Here: Demo Link

Answer №1

To enhance the layout, you can utilize the HTML <details> disclosure element along with CSS styling:

details {
  float:right;
  width: 50%;
    display:flex;
  flex-wrap:wrap;
}
<details>
    <summary>Details</summary>
    This showcases the usage of details disclosure.
</details>
<details>
    <summary>Details</summary>
    This demonstrates how details disclosure works.
</details>
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details

Answer №2

To display the SPAN text without affecting the layout of other elements, you can overlap it. Here's an example based on Bauke's suggestion.

CSS:

    summary{cursor:pointer}
    summary:focus{outline:none}

    details{display:inline-block}
    details > span{background:#f0f0f0;position:absolute;width:400px;}
    details > summary {list-style:none;}
    details > summary::-webkit-details-marker {display:none}

HTML:

<div style="width:400px">

    <li>
        <details closed>
            <summary>user name test A</summary>
            <span>
                A card can be used to display content related to 
                a single subject. The content can consist of multiple 
                elements of varying types and sizes.
            </span>
        </details>
    </li>
    <li>
        <details closed>
            <summary>user name test A</summary>
            <span>
                A card can be used to display content related to 
                a single subject. The content can consist of multiple 
                elements of varying types and sizes.
            </span>
        </details>
    </li>

</div>

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

I want to hide jqvmap when viewing on mobile devices

I'm currently working on my website at . I have a template that I'm using as a guide, but I want to make the map disappear on mobile view and replace it with a dropdown list. Can anyone suggest what code I should use for this? Appreciate any hel ...

having trouble with changing the button's background color via toggle

I've been experimenting with toggling the background color of a button, similar to how changing the margin works. For some reason, the margin toggles correctly but the button's color doesn't. <script> let myBtn = document.querySele ...

What are some creative ways to design the selected tab?

In my Vue parent component, I have multiple child components. There are several elements that toggle between components by updating the current data. The issue is that I am unsure how to indicate which tab is currently active. I've tried various li ...

Need to update various form fields at once with jquery?

There is a form with fields for firstname, lastname, email, country, along with edit icon and submit/cancel buttons. When the user clicks on the edit icon in the top right corner, all values will be displayed in textboxes and the country will be shown in ...

navigating directly to a particular slide within a Bootstrap carousel on a different page by clicking

Attempting to set up a bootstrap build, where clicking on certain states on one page will direct the user to a specific slide on another page. I'm struggling to grasp this concept. A friend of mine, who is a Javascript developer, provided some code f ...

how to make a div scroll after reaching a specific pixel distance

Hi there! I'm working with a DIV that has a width of 1600px. I'm wondering if there's a way to implement a feature within the DIV that fixes the first 200px and adds an automatic scroll for the rest of the content. Do you know of any CSS tr ...

When working in Flask, I am experiencing an issue where my CSS is not linking to my

I am new to coding with HTML, CSS, and Flask and I have encountered an issue where my CSS styling only partially affects my HTML file. Here is the HTML code snippet: <!DOCTYPE html> <html> <head> <meta charset="UTF-8& ...

Need help aligning a column class perfectly in bootstrap?

I'm currently learning Bootstrap 3 and I have some HTML code that looks like this: <ul class="row> <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6"></li> <li class="col-lg-3 col-md-3 col-sm-3 col-xs-6"></li> .. </ul ...

Is there a way to make placeholder text automatically adjust its size to fit within the text input element and display its complete content?

I am working on a piece of HTML code that includes a form with a table for traveler information. However, I am having trouble ensuring that the placeholder text remains fully visible at all times. To give you a visual example, here is what I currently hav ...

Ways to determine if a class is a part of the bootstrap framework

Is there a way to verify if a class like mt-3 or table-left is part of the bootstrap framework? Are there any online resources, tools, or plugins in VSCode that can assist me in determining if a class is a predefined bootstrap keyword? ...

Tips for adjusting custom spacing margins within Material UI Grid

Is there a way to adjust the spacing between Grid items in Material UI? Here's the code I currently have: <Grid container spacing={1}> <Grid item xs={6}>Node 1</Grid> <Grid item xs={6}>Node 2</Grid> ...and so ...

Conceal the scrollbar track while displaying the scrollbar thumb

Hey there! I'm looking to customize my scroll bar to have a hidden track like this. Everyone's got their own style, right? ::-webkit-scrollbar{ width: 15px; height: 40px; } ::-webkit-scrollbar-thumb{ background-color: #DBDBDB; borde ...

Javascript onclick events failing to toggle video play/pause functionality

In my website, I have background music and a background video (webm format) embedded. I am facing an issue with making play/pause buttons in the form of png images work for both the video and the music. The background music is added using the embed tag wi ...

The specified height for input[type=button] in Firefox/Safari is adjusted by subtracting the padding and border

When implementing the following CSS: input[type=button] { background-color: white; border: 1px solid black; font-size: 15px; height: 20px; padding: 7px; } along with this HTML: <input type="button" value="Foo" /> I anticipate that the t ...

Strategies for successfully passing and showcasing the result of a calculation on a fresh view or component within Angular

I have developed a basic calculator application with two main components: Calculator and Result. The Angular router is used to navigate between these components. Now, I am looking for a way to dynamically display the calculation result from the Calculator ...

Adjusting font size according to the font style selected

Can conditional font size be determined based on font family using CSS or jQuery? ...

Access and expand a bootstrap accordion with a hyperlink

Here is a concept I want to make happen: For my project, I am utilizing Bootstrap v3.4.1 and have set up two columns next to each other. My goal is to link the elements in the hotspot banner (left column) to trigger and open the corresponding Accordions ( ...

Transforming hover interactions into onclick events involves adjusting the CSS and JavaScript

Is there a way to convert this hover menu into an onclick menu? <div id='cssmenu'> <ul> <li class='has-sub'><a href='#'><span>Users</span></a> <ul> ...

Adjust Font Size inside Circular Shape using CSS/jQuery

I have been searching for different libraries that can resize text based on the size of a container. However, my container is circular and I am facing difficulty in preventing the text from overflowing beyond the border. Below you will find a Fiddle conta ...

Can we not customize a nested component using the 'styled()' function in MUI?

Looking at the code snippet below, my attempt to style an MUI Stack component within an MUI Dialog component seems to be falling short. The Stack styles are not being applied as expected: const CustomDialog = styled(Dialog)(({ theme }) => ({ ' ...