Steps for generating a sophisticated shadow effect using CSS

Currently in the process of revamping a poorly designed website by replacing images with CSS whenever possible, along with other updates. I have encountered a challenging graphic (there are three of these, one for each active tab):

https://i.sstatic.net/1nBlV.png

Take note of how the shadow wraps around the edges of the tab handle and remains above the other two tab handles. I've attempted various methods to achieve this shadow effect using CSS, but so far, I haven't made any progress. Any suggestions?

Answer №1

One issue at hand is not just the active tab overlapping the others with shadows, which can easily be achieved using simple z-index and box-shadow tricks.

The desired effect of rounded corners requires more advanced techniques and cannot be directly accomplished with border-radius. The method I prefer involves using gradients, inspired by Lea Verou's negative border radius with gradients, as it complements shadows seamlessly.

$(function() {
  $('.nav a').click(function(e) {
    e.preventDefault()
    $('.nav li').removeClass('active')
    var h = $(this).attr('href')
    $(this).parent().addClass('active')
    $('.tab-pane').removeClass('active')
    $(h).addClass('active')
  })
})
html {
  background: #ddd;
  margin: 20px 10px auto;
  font-family: Sans-serif;
}
.nav {
  /* Using flex for easy adjustment to any number of tabs */
  display: flex;
  padding: 0;
  margin: 0 0 -10px;
}
.nav li {
  flex: 1 0 auto;
  list-style: none outside none;
  position: relative;
  border-radius: 10px 10px 0 0;
}
.nav .active {
  z-index: 2;
  background: #fff;
}
.nav a {
  display: block;
  padding: 10px 40px 20px;
  text-decoration: none;
  text-align: center;
  color: #777;
  background: #f5f5f5;
  border: 1px solid #aaa;
  border-radius: 10px 10px 0 0;
}
.nav .active a {
  background: #fff;
  border-bottom: 0;
  color: #111;
  padding: 10px 40px 11px;
  box-shadow: -3px -1px 2px rgba(0, 0, 0, .05), 3px -1px 2px rgba(0, 0, 0, .05);
}
.nav .active:first-child {
  border-left: 1px solid #aaa;
}
.nav .active:first-child a {
  border-left: 0;
}
.nav .active:last-child {
  border-right: 1px solid #aaa;
}
.nav .active:last-child a {
  border-right: 0;
}
.nav .active:not(:first-child) a:before,
.nav .active:not(:last-child) a:after {
  /* Rounded out corners are generated elements */
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  bottom: 9px;
}
.nav .active:not(:first-child) a:before {
  /* Implementing the left rounded out tab here. */
  background: radial-gradient(circle at 0 0, transparent 8px, #aaa 9px, #fff 10px);
  left: -9px;
}
.nav .active:not(:last-child) a:after {
  /* Implementing the right rounded out tab here. */
  background: radial-gradient(circle at 100% 0, transparent 8px, #aaa 9px, #fff 10px);
  right: -9px;
}
.tab-content {
  border: 1px solid #aaa;
  border-radius: 10px;
  box-shadow: 2px 1px 10px rgba(0, 0, 0, .2), 0 6px 30px rgba(0, 0, 0, .08);
  background: #fff;
  color: #111;
  padding: 20px;
  position: relative;
  z-index: 1;
}
.tab-pane {
  display: none;
}
.tab-pane.active {
  display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<ul class="nav">
  <li class="active"><a href="#home">Home</a></li>
  <li><a href="#profile">Profile</a></li>
  <li><a href="#settings">Settings</a></li>
</ul>

<div class="tab-content">
  <div class="tab-pane active" id="home">1</div>
  <div class="tab-pane" id="profile">2</div>
  <div class="tab-pane" id="settings">3</div>
</div>

JavaScript was solely utilized to manage tab changes, enhancing the visualization of each tab positioning style differences.

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

Guide on creating HTML content within a ToolTip function for a table row

I'm working on implementing a tooltip feature that will appear when hovering over a row with extensive HTML content. This feature is intended to be used alongside Foundation framework. However, I am encountering issues getting the tooltip to work prop ...

Develop your website layout with Flexbox (Bootstrap 4.2), using stacked grid designs similar to the float: left method

For my Wordpress theme, I am utilizing Bootstrap 4.2 to design a basic grid layout for a list of blog posts. In my design, I have a Card that is double the height of others and I am attempting to 'float' two single-height cards beside it. Previ ...

100% width is applied to the table cell within the div element

Below is the code I am working with: <div style='display: table'> <div style='height:200px; width:100%; text-align: center; display: table-cell; vertical-align: middle'>No result found</div> </div> I'm ...

Is there a way to create a universal script that works for all modal windows?

I have a dozen images on the page, each opening a modal when clicked. Currently, I've created a separate script for each modal. How can I consolidate these scripts into one for all modals? <!-- 1 Modal--> <div class="gallery_product col-lg-3 ...

What is the best way to assign group headings to my Codeigniter view results?

One of the challenges I'm facing in my view is organizing a list like this: <? foreach($services as $service): ?> <tr> <td><?= $service->name; ?></td> <td><?= $service->format; ?></td> < ...

Is it possible for me to utilize window.top within the .js file?

Within my GWT code, I am transferring a variable to a JSP file. The process looks like this: <html> <head> <script type="text/javascript"> alert("Inside the JSP file"); var criticalPath = window.top.criticalPath; ...

What is the best way to center CSS content such as boxes and text?

As a beginner in CSS tutorials, I am seeking guidance on how to center the entire content in the browser. Below is the CSS code that needs attention. Additionally, there is a screenshot of the current output included for reference. body { background:#E9 ...

Utilize Flexbox to create a layout with 3 divs, organized into two columns where one column

I am attempting to transform <div></div> <div></div> <div></div> Three consecutive divs into the following format. Div 1 is red, div 2 is green, and div 3 is blue. I have achieved this using floats, like so: .div1 { ...

What is the most strategic way to conceal this overlay element?

Currently, the website I'm developing features a series of navigation elements at the top such as "Products" and "Company." Upon hovering over the Products link, an overlay displays a list of products with clickable links. Positioned at the top of the ...

The embedded CartoDB image header is set to have a style of "display:none"

I'm currently working on a CartoDB map showcasing my readers' summer fishing photos. Each row in the table has an image url, which I've placed at the top of the infowindow display list. I've enabled it and set the image window type to ...

Rendering High-quality Images in Internet Explorer Browser

Currently, I am working on optimizing my website for high resolution monitors, particularly the new iPad. The site is already formatted to my liking, with images having increased resolutions while still fitting into specific DIVs. For instance, an image wi ...

Troubleshooting the fluid container problem in Bootstrap 3

I am currently working on a website using Bootstrap 3 framework. I have a specific section where I need to have two fluid containers placed side by side, each with different background colors. One of these containers should also include a background image ...

Transforming color images into black and white using JavaScript

     I have implemented this code to convert colored images to grayscale. function applyGrayscaleEffect() {         var imageData = contextSrc.getImageData(0, 0, width, height);         var data = imageData.data;         var p1 = 0.99;   ...

Having trouble accessing the menu in the dropdown div when clicking back?

I am working on creating a menu that drops down from the top of the page using JQuery. I have everything set up with the code below: <div id="menu"> <div id="menucontentwrapper"> <div id="menucontent"></div> </di ...

Incorporating React into an already existing webpage and accessing URL parameters within a .js file

Following the official guidelines: To include React in a website, visit https://reactjs.org/docs/add-react-to-a-website.html I have created a file named test.html with the following content: <!DOCTYPE html> <html> <head> < ...

Using PHP and mysqli to upload binary data to a database through a form

I'm facing an issue while attempting to upload an image into a database as a blob using PHP with the mysqli extension. When I try to insert just the image name using a query, everything works perfectly fine, and a new row with the name is successfully ...

Tips for stopping automatic scrolling (universal solution)

Issue or Inquiry I am seeking a way to disable actual scrolling on an element while still utilizing a scrollbar for convenience (avoiding the need for manual JavaScript implementations instead of relying on browser functions). If anyone has an improved s ...

Links are unable to function properly outside of the carousel slideshow in Chrome

www.encyclopediasindhiana.org/index2.php I successfully implemented a slideshow using mycarousel with the help of PHP. However, I am facing an issue where the hyperlinks on the left side of the carousel are not working if the image is as large as the heig ...

Tips for incorporating a custom CSS design into a jQueryUI tooltip

I am struggling to apply my custom CSS class on top of the jQueryUI tooltip. Although the tooltip is displaying correctly, my styles are not being applied. Here is the code I'm using: $(document).ready(function () { $("#roles").tooltip({ content: ...

Header should elegantly glide up and down as the user scrolls through the page

I've implemented a top div on my page that houses contact details and social media links. I've managed to hide it during scrolling and make it reappear when reaching the top of the page. However, I'm hoping to smoothen this transition with a ...