Applying CSS background styles to HTML elements for a visually cohesive grouping with rounded edges

Searching for a method to group HTML elements together with a background. The challenge lies in the rounded corners as shown in the image. Is there a way to successfully accomplish this task?

Answer №1

This solution is very close to completion, with just a few small adjustments needed.

Link to FIDDLE

Essentially, I utilize pseudo elements before each list item by utilizing nth-child to categorize them based on color.

Additionally, I assign a lower z-index for each category.

There could be potential for enhancement by experimenting with the clip property.

Markup

<ul>
    <li></li><li></li><li class="last"></li>
    <li></li><li></li><li></li><li></li><li></li><li class="last"></li>
    <li></li><li></li><li></li><li class="last"></li>
</ul>

CSS

ul
{
    list-style:none;
    width: 350px;
}
li:before
{
    content: '';
    border-radius: 10px;
    display: inline-block;
    position: absolute;
    top: -10px;
    left: -10px;
    height:70px;
    width: 80px;
    z-index:-1;
}

li:nth-child(-n+3):before
{
    background: brown;
    z-index: -2;
}

li:nth-child(n+4):nth-child(-n+9):before
{
    background: green;
    z-index: -3;
}
li:nth-child(n+10):nth-child(-n+13):before
{
    background: pink;
    z-index: -4;
}
li
{
    width: 50px;height: 50px;
    background: black;
    border-radius: 10px;
    margin: 5px 5px 10px 5px;
    display: inline-block;
    position:relative;
}
.last:before
{
    z-index: -1!important;
    width: 70px;
}
.last + li:before
{
    border-radius: 10px 10px 10px 0;
}
/* clip the last item in each row */
li:nth-child(5n):before
{
    width: 70px;
}

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

Ensuring that the text in the Bootstrap navbar is responsive for all screen

Yesterday, I inquired about how to modify my navbar menu to switch from horizontal to vertically arranged depending on layout. However, I've noticed that the responsiveness is not consistent when adjusting the window size. Is there a way to ensure my ...

Attempting to achieve CSS shadows on both the right and left sides of the element

I am struggling to apply a CSS box shadow to a DIV element. Specifically, I want the shadow to appear only on the left and right sides of the element. I have tried using the following code: box-shadow: 0 0 10px #000; However, despite my efforts, the shad ...

Obtaining hyperlinks to encircle the sound button

Code 1: If you notice, after clicking on the image, the audio button appears and plays without any surrounding links. How can I enable the links around the audio button in Code 1? https://jsfiddle.net/7ux1s23j/29/ https://i.sstatic.net/75wlN.png < ...

Tips for choosing the injected HTML's List Element (li) while ensuring it remains concealed

How do I hide the list item with iconsrc="/_layouts/15/images/delitem.gif" image when this div is injected by a first party and I am a third party trying to conceal it? $("<style> what should be inserted here ???? { display: none; } </style>") ...

Halt the Bootstrap carousel while entering text in a textarea

Is it possible to achieve this? I think so. I have created a carousel with a form inside. The form includes a textarea and a submit button. Currently, the slider does not slide if the mouse pointer is inside it, which is good. However, if the pointer is o ...

utilizing a returned list from a controller in an ajax request

When using an ajax call to store data in a database and the controller returns a list of commentObjects, how can this list be accessed in a JSP file? function StoreCommentAndRefreshCommentList(e) { var commentData = document.getElementById(ActualComme ...

Having a challenge with aligning a form in a view, as neither bootstrap nor plain CSS seem to be helping with centering it correctly

What techniques can I use to center this form properly in both bootstrap and plain CSS? So far, I have been able to center some parts of it, but when I try to center others, they shrink and create a mess. When I use bootstrap to center the elements, they b ...

CSS selector that targets an element exclusively when it contains solely another element, devoid of any additional text

Is there a CSS selector that can target an element, like <p>, with only a specified child element, such as <a>, within it and nothing else? For instance: <p><a>Some text</a></p>. I want to avoid selecting elements like & ...

Struggling to Align NAV buttons to the Right in React Framework

My current Mobile Header view can be seen here: https://i.stack.imgur.com/CcspN.png I am looking to achieve a layout similar to this, https://i.stack.imgur.com/pH15p.png. So far, I have only been able to accomplish this by setting specific left margins, ...

DNN's utilization of the HTML5 Object (deprecated Codebase and Codetype)

Forgive me if this is a silly question, but I have a client who doesn't want their Dot Net Nuke skin created in a .ascx format. I've run into a problem. In Dot Net Nuke, you could simply use: <object id = "Name" codebase = "Name" codetype = ...

A surprise awaits in IE with the unusual appearance of a div display

body { background: #9cdcf9 url(/images/left_cloud.png) bottom left no-repeat; font-family:\"Trebuchet MS\"; padding:0; margin:0; border:0; } #cloud-container { width: 100%; background: url(/images/right_cloud.png) bott ...

Steps to dynamically adjust an element's width in CSS depending on the presence of a separate element

I have a text input box appearing on the left side with a button positioned next to it on the right. For certain pages, I want to display a checkbox next to the input box and move the button below it. Is there a way to achieve this using CSS flexbox or a ...

Issues with Bootstrap Toggle Button functionality

I encountered a navbar error while working on my Django Project. After adding a few script tags, the navbar started to move down but did not return back to its original position. It worked fine before. By commenting out some script tags, it began to work a ...

What is the best way to extract a specific year and month from a date in a datatable using

My dataset includes performance scores of employees across various construction sites. For instance, on 2020-03-15, ALI TAHIRI was at the IHJAMN site. I need to filter this dataset by year and month. If I input 2020 for the year and 03 for the month, the d ...

How to use CSS and Jquery to show a child element right after its parent element

I'm attempting to develop tabbed navigation using my current HTML structure. My goal is to display book titles as tabs and book details BELOW the tabs. Check out this example: or view this: http://jsfiddle.net/syahrasi/Us8uc/ I cannot change the HTM ...

Avoid importing the React CSS style file at all costs

Currently, I am working on a project and facing a minor issue related to importing the style.css file. I am aware that the syntax should be import "./style.css", however, upon implementation, I encountered a Terminal Output error. The output generated by ...

Problem with Labels Overlapping and Blocking Text Fields

My issue is that when I interact with the text field, the label "Type your New Task here" moves up and gets covered by what looks like a white overlay. How can I fix this so that the label stays visible at all times? Prior to engagement: https://i.stack.i ...

How to conceal certain sections of HTML using jQuery

Currently, I am in the process of creating a "news" page for a website. My goal is to only show the first 15 lines of each news article when the page is loaded, creating a neat appearance for visitors. After the 15th line, I include a "read more" link tha ...

Utilize React to float the Material UI SwipeableDrawer component to the right side of the screen

I'm currently working on a project that involves using material UI alongside React/Redux. There has been a recent change in the Figma file where the SwipeableDrawer component is now positioned on the right side of the screen instead of the left. I&apo ...

Create a Django website feature that enables a button to direct users to another application

I'm working on creating a customized button that will redirect users to another app when clicked. Interestingly, this code snippet is functional: <a href="{% url 'ridesharing:ride-list' %}" target="blank">Find a ride</a> How ...