What is the best way to create a stylish outward curve effect for an active sidebar item using just CSS

After spending a week learning frontend designs, I attempted to replicate a design from Dribble. However, I've been struggling with recreating the active style on the sidebar due to the outward curve.

If anyone could provide guidance on achieving this effect, I would greatly appreciate it.

While I have successfully accomplished other aspects of the design, the outward curves on the active sidebar item are proving to be a challenge.

Unfortunately, I am unable to upload a picture as my reputation is below 10. Instead, I have included a link to the design:

Answer №1

The challenging aspect lies in the creation of the "inverted" corners on the right side. This can be achieved by utilizing a radial-gradient background within a :before and :after element.

A radial-gradient is typically used to create a smooth transition between two colors. However, with some manipulation, we can produce a distinct boundary line between white and blue in this scenario. To accomplish this, ensure that the pixel values for the blue and white colors are very close together.

background: radial-gradient(circle at top left, blue 10px, white 11px);

I have implemented this effect on the :hover state here, but you also have the option to add a class to your active list item and apply the styling there instead.

.menu{
  list-style-type: none;
  background: blue;
  width: 200px;
  border-radius: 20px;
  padding: 30px 0 30px 30px;
}

.menu li{
  position: relative;
  padding: 5px;
  border-radius: 10px 0 0 10px;
}

.menu li:hover{
  background: white; 
}

.menu li:hover:after,
.menu li:hover:before{
  content:'';
  position: absolute;
  width: 10px; 
  height: 10px;
  right: 0px;
}

.menu li:hover:after{
  top: -10px;
  background: radial-gradient(circle at top left, blue 10px, white 11px);
}

.menu li:hover:before{
  bottom: -10px;
  background: radial-gradient(circle at bottom left, blue 10px, white 11px);
}
Hover over menu items to see the effect
<ul class="menu">
  <li>one</li>
  <li>two</li>
  <li>three</li>
  <li>four</li>
  <li>five</li>
</ul>

Answer №2

To create a curved effect, I quickly came up with an alternative solution using a white square element named .hover-top-white in my code. By adding a quarter-circle div on top of the white square with the same background color, I was able to simulate the curve effectively. Here's the snippet of the code:

.menu {
background-color: purple;
width: 400px;
height: 100vh;
border-radius: 0 50px 50px 0;
position: relative;
}
.hover {
width: 350px;
height: 100px;
position: absolute;
right: 0;
top: 120px;
display: flex;
justify-content: flex-end;
}
.hover-top-cut {
width: 50px;
height: 50px;
background-color: purple;
border-radius: 0 0 50px;
position: absolute;
top: -50px;
right: 0;
z-index: 3;
}
.hover-top-white {
width: 50px;
height: 50px;
background-color: white;
position: absolute;
top: -50px;
right: 0;
}
.hover-mid {
width: 100%;
height: 60%;
background-color: white;
border-radius: 50px 0 0 50px;
}
.hover-bottom-cut {
width: 50px;
height: 50px;
background-color: purple;
border-radius: 0 50px 0 0;
position: absolute;
bottom: -10px;
right: 0;
z-index: 3;
}
.hover-bottom-white {
width: 50px;
height: 50px;
background-color: white;
position: absolute;
bottom: -10px;
right: 0;
}
<div class="menu">
<div class="hover">
<div class="hover-top-cut"></div>
<div class="hover-top-white"></div>
<div class="hover-mid"></div>
<div class="hover-bottom-cut"></div>
<div class="hover-bottom-white"></div>
</div>
</div>

There are various ways to align elements besides using flexbox and position absolute. However, my main focus here was on achieving the curved effect.

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

Customize Material-UI Icons styles in React app

I'm working on a React.js app with Typescript and I need to remove the default visited Material Icons coloring from an anchor tag. Here's the stylesheet I tried: const useStyles = makeStyles((theme: Theme) => createStyles( myAnchor: ...

CSS slideshow with automatic horizontal image transition that seamlessly restarts

I am facing an issue with my HTML & CSS automatic horizontal slideshow. Everything works fine, except for when the last image finishes sliding and the slideshow loops back to the first image, there is a sudden jump in the appearance of the first image. How ...

What causes the `d-none` class to toggle on and off repeatedly when the distance between two div elements is less than 10 during window resizing?

My primary objective is to display or hide the icon based on the width of the right container and the rightButtonGroupWrapper. If the difference between these widths falls below 10, the icons should be shown, otherwise hidden. However, I'm facing an i ...

The iFrame that is generated dynamically becomes null when accessed from a page that has been loaded using JQuery

One issue I am facing is with a dynamically created iframe in regular javascript. It functions perfectly fine when called from a static page using conventional methods. However, when it is being called from a page loaded by jQuery, I encounter an error s ...

Image set as the background on a website

I recently started working with Groovy and Grails, designing my own personal website. I'm looking to set an image (located in the asset folder) as the background for my index.gsp page. How can I achieve this? ...

Aligning Text to the Right Using CSS

HTML <body> <div class="menu_items"> <h1>My Heading</h1> <nav> <a>Item 1</a> <a>Item 2</a> <a>Item 3</a ...

Creating unique buttons for your PHP poll

I am designing a website for my friend and myself. The main feature of our site is a poll that asks users to choose between two options. Currently, I have set the input type as radio buttons where users can click on a circle to make their selection. Howeve ...

Tips for resolving the error "Invalid value for style prop - must be an object" in a React.js and CSS scenario

Hey there, I'm currently working with module.css in React and facing an issue when trying to include the following line: <span style="--i:1;"><img src="https://i.postimg.cc/BQcRL38F/pexels-photo-761963.jpg" alt="not f ...

Tips for minimizing the padding/space between dynamically generated div elements using html and css

Currently, I have 4 dropdown menus where I can choose various options related to health procedures: Area, specialty, group, and subgroup. Whenever I select a subgroup, it dynamically displays the procedures on the page. However, the issue I am facing is th ...

The Bootstrap 5 Accordion Content is not Showing Up

In my current project in vscode, I am using Bootstrap 5 to develop a website. Specifically, I am working on creating an accordion feature with Bootstrap 5. However, I encountered an issue where the accordion body does not show up when clicking on the acc ...

Can someone help me troubleshoot the issue with my submit button's onclick function?

I am currently working on a project where I have a content box enclosed in a div tag. Within this content box, there are paragraphs with unique IDs for individual styling rules. I have set margins, padding, and other styles accordingly. At the bottom of th ...

Ensuring correct association of values to avoid redundancies

There are 5 fields available for users to fill out on this form: Leave Code, From Date, Input Time1, To Date, and Input Time2. These variables are declared as a dates object in the .ts file, as shown below. interface Supervisor { name: string; code: s ...

An error occured upon loading FullCalendar: Uncaught TypeError - Unable to read property 'push' as it is undefined

First of all, thank you for your assistance. I've been trying to load FullCalendar (https://fullcalendar.io/) on my development environments but it doesn't seem to be working. When I check the console in Chrome, it shows me the following error m ...

Different "criteria" for CSS wildcard selectors using Selenium

There are several CSS webelements on my page with ids in the format: cell_[number]-button_[number] I am attempting to target ALL of these elements by using Selenium to locate all elements that begin with cell and include button: var elements = Util.driver ...

Prevent form submission when text fields are empty or dropdown selections are not made

I have a piece of code that is currently working with just one textbox input called 'departname'. However, I now need all input fields to be required and the dropdown menu for 'ACFTREG' (which is populated from a Sharepoint list) should ...

Adjust positioning of navigation when hovered over

Need help creating a cool navigation effect like this. Live example: https://hookandbarrelrestaurant.com/ Here is my code: https://codepen.io/Dhaval182/pen/rQPMoW ...

The buttons on the Bootstrap Carousel are unresponsive and the indicators are not displaying as they should

I am currently attempting to replicate a bootstrap carousel that includes indicators. However, in my code, I am unable to view the indicators, and the previous/next buttons are not functional. Although I came across a workaround that I could modify from th ...

Is it possible for an Android webview to access the device's geo location?

For the application I'm working on, it's necessary to access the user's geo location. We've created a HTML 5 based website and are using a webview to develop our mobile application by calling the website URL. With the latest geo tags av ...

Extension for Chrome - Personalized pop-up notification when page loads

I am looking to create a custom alert box that triggers on page load instead of the default one, which I find unattractive and possibly irritating for users. alert('hello'); My current approach involves the following code: manifesto.js "cont ...

How can the end event of a custom CSS animation be bound using jQuery or JavaScript?

We are currently managing multiple animations on the same object and need to execute different actions once each animation is complete. At present, we listen for the webkitAnimationEnd event and use a complex if/then statement to handle each animation sep ...