Design a styled rectangular tab using CSS

Does anyone know of any cool CSS techniques for achieving the tabbed rectangle appearance depicted in the image below?

While it's clear that accomplishing this with just one div is not possible, is there a more efficient method than layering one div over another to create a border gap?

This is my current approach, but I believe there could be room for improvement:

HTML:

<div id="handle"></div>
<div id="menu"></div>

CSS (excluding colors and positioning for brevity):

#handle {
    width: 90px;
    height: 20px;
    border-left: 1px solid #666;
    border-right: 1px solid #666;
}

#menu {
    width: 600px;
    height: 100px;
    border: 1px solid #666;
    margin-top: 19px; /* Note that it sits slightly above the handle, covering the top border */
}

Please refrain from correcting the CSS provided above if errors are found. It has not been tested and is meant solely to illustrate my current methodology.

Any feedback would be greatly valued

UPDATE

Here is the HTML structure of the menu as it currently stands:

<nav id="global-nav">
    <ul>
        <li id="homNav"><a href="#" title="Home"></a></li>
        <li id="masNav"><a href="#" title="#">#</a>
            <!-- Submenu begins here -->
            <div class="handle"></div>
            <div class="subMenu">
                <!-- Content goes here -->
            </div>
            <!-- Submenu ends here -->
        </li>
        ...
    </ul>
</nav>

Below is the CSS styles for the menu so far (submenu styling omitted):

/* Navigation */
#global-nav {position:relative;width:460px;height:27px;left:15px;top:43px;}
...

/* Specific navigation button styles */
...

Answer №1

Upon thorough examination, I have determined that the most effective method for achieving this tabbed menu is by overlaying the border.

HTML:

<nav id="global-nav">
    <ul>
        <li id="homNav"><a href="#" title="Home"></a></li>
        <li id="masNav"><a href="#" title="#">#</a>
            <div class="subMenuHandle horizontal-sprite">
                <div class="bg-noise"></div>
            </div>
            <div class="subMenu horizontal-sprite">
                <div class="bg-noise"></div>
            </div>
        </li>
        <li id="shiNav"><a href="#" title="#">#</a>
            <div class="subMenuHandle horizontal-sprite">
                <div class="bg-noise"></div>
            </div>
            <div class="subMenu horizontal-sprite">
                <div class="bg-noise"></div>
            </div>
        </li>
        <li id="repNav"><a href="#" title="#">#</a>
            <div class="subMenuHandle horizontal-sprite">
                <div class="bg-noise"></div>
            </div>
            <div class="subMenu horizontal-sprite">
                <div class="bg-noise"></div>
            </div>
        </li>
        <li id="setNav"><a href="#" title="#">#</a>
            <div class="subMenuHandle horizontal-sprite">
                <div class="bg-noise"></div>
            </div>
            <div class="subMenu horizontal-sprite">
                <div class="bg-noise"></div>
            </div>
        </li>
    </ul>
</nav>

CSS (I apologize for the compression, it's just my preferred formatting style):

/* Navigation */
#global-nav {position:absolute;width:460px;height:27px;left:15px;top:43px;}

#global-nav ul {margin:0;padding:0;list-style-type:none;}
#global-nav ul li {position:relative;display:block;width:92px;height:27px;float:left;padding:0;margin-left:8px;z-index:10;background-image:url("http://beta.example.net/_images/_global/sprite.png");background-position:-173px -32px;}
#global-nav ul li:hover {background-position:-173px -59px;}
#global-nav ul li:active {background-position:-173px -86px;}
#global-nav ul li a {display:block;width:92px;height:27px;line-height:27px;text-align:center;color:#fff;font-size:12px;text-shadow:#666 0 -1px 0;}
#global-nav ul li:hover a {color:#666;text-shadow:#fff 0 1px 0;}
#global-nav ul li:active a {color:#666;text-shadow:none;}

/* Set styles for specific navigation buttons */
#homNav {width:47px !important;margin-left:0 !important;margin-right:12px;background-position:-126px -32px !important;}
#homNav a {width:47px !important;}
#homNav:hover {background-position:-126px -59px !important;}
#homNav:active {background-position:-126px -86px !important;}

/* Set hovers of sub menu buttons to active images */
#masNav:hover,
#shiNav:hover,
#repNav:hover,
#setNav:hover
{background-position:-173px -86px !important;}

/* Set the sub menu handles */
#global-nav .subMenuHandle {position:relative;display:none;width:90px;height:12px;margin-top:-1px;border-left:1px solid #666;border-right:1px solid #666;z-index:1000;background-color:#fff;background-repeat:repeat-x;}
... (remaining CSS code not shown for brevity) 

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

How can the color of the wishlist icon be modified in Reactjs when the item is available in the database?

Is there a way to change the color of the wishlist icon based on whether the item is in the database? If the item is present, its color should be brown, and if it's not present, the color should be black. Additionally, I want the ability to toggle be ...

Creating a resilient CSS: DOM for seamless printing in PDF or on physical printers

I need help with formatting a list of col-6 elements (bootstrap) inside a row element so that the content of each block remains intact in a pdf preview generated using print(). I attempted to use various css properties like page-break and break as suggeste ...

Emphasize a feature within a dynamic DIV

How can I highlight the span(class="tiny") element individually when its containing div is active or clicked? I have attempted to highlight the tiny span element without success, as only the entire div was highlighted. Here's the code snippet I' ...

Error with the jQuery scrolling plugin

Currently, the script is set up this way: jQuery(document).ready(function(){ var windheight = jQuery(window).height(); var windTop = jQuery(window).scrollTop(); var windbottom = windheight + windTop ; jQuery.fn.revealOnScroll = function(){ return this.e ...

How to Insert a Background Image into Advanced Custom Fields (ACF) using CSS

Hey there, I'm facing a bit of a challenge with this particular section. In the past, I've only included ACF PHP within HTML when the background image was directly in the HTML code. Now, however, I have two shapes specified in my CSS using pseudo ...

Position the Close Button within the CSS Cookie Consent Popup in perfect alignment

Having trouble aligning the close X button in my cookie consent popup to the center? I added a margin-top to adjust it, but I'm looking for a better solution. <div class="alert cookiealert" > By using our website you agree to our C ...

Creating tabbed content with a classless CSS design by utilizing radio buttons instead of the traditional unordered

I am attempting to transform the classless CSS and HTML provided below from a list format to using radio buttons and labels for tabbed content. My goal is to make it concise and avoid redundancy. Here is the setup of what I am aiming for: <nav> ...

Sidenav Content with all elements having opacity applied

How can I ensure that all page elements have a black background color when the mobile navigation is opened on the left screen, while ensuring that my sidebar and content image do not get overlaid by the black background? Here is my code: function openNav( ...

I'm always puzzled by why my attempts to spell a word in a foreign language with accent symbols somehow result in a strange appearance when it comes to bootstrapping

Hey guys, I'm trying to spell a word in Portuguese and instead of PROGRAMAÇÃO, it's showing up as PROGRAMAÇÃO. It seems like the accent symbols are not being displayed correctly. Any thoughts on how to fix this issue? This is happening ...

What is the reason behind a stationary lightbox sticking to the top of the webpage rather than the top of the viewport?

When you visit this page and scroll down a little before clicking on one of the art pieces, have you noticed that the "fixed" lightbox seems to be attaching itself to the top of the page instead of the viewport? I'm looking for ways to make it attach ...

Show a 1920x1170 / 183KB image as the background using CSS styling

I need help with displaying a background image that is 1920x1170 pixels and has a file size of 183KB. Here is the code I am using: .bground{ height:auto; left:0; position:fixed; top:0; width:100%; } <div class="bgrou ...

When hovering over the sidebar, it smoothly slides out. (ideally using only CSS)

I've been spending my free time working on a website, but I'm struggling to figure out how to create a navigation similar to the one featured on FontShop's site: . I want it so that when you hover over their logo (or in my case, a blank rect ...

href not functioning properly on subsequent clicks, whereas onclick remains active

I'm experiencing an issue with a button that opens a modal. When clicking the button, it's supposed to open a new page in the modal and also make an API call for processing before loading the new page. <a class="btn btn-primary" type='b ...

Designing a slider to display a collection of images

I am currently working on a slider project using HTML, javascript, and CSS. I'm facing an issue where only the first two images (li) are being displayed and it's not transitioning to the other (li) elements. Below is the HTML code snippet: <se ...

Adjusting font size, contrast, brightness, and sound levels on a website with the help of jQuery

My client has a new requirement: adding functionality to increase font size, adjust contrast/brightness, and control sound on his website. When clicking on any of the control images, a slider should appear for the user to make adjustments accordingly. Ho ...

What is the method of aligning content to the left side in a slick slider?

My slider is set up to display three elements, but I'm having trouble aligning one or two elements to the left instead of centering them. jQuery(function () { jQuery('.slider-blog').slick({ arrows: false, dots: true, ...

Difficulty Aligning Header Elements - Combining Navigation and Logo on the Same Line

I am currently facing an issue with positioning a logo and navigation links within a <header> element. When I apply the CSS property text-align:center;, the logo aligns to the center on one line while the navigation links appear on another line direc ...

Issue with bootstrap accordion not collapsing other open tabs automatically

I'm struggling to incorporate a Bootstrap accordion collapse feature into my project, specifically with the auto-collapsing functionality. In the scenario where there are 3 divs labeled A, B, and C, if A is open and I click on B, A should automaticall ...

finding the source file or code where a particular html element is being generated

In the HTML file I have, there are multiple JavaScript files added. Whenever I run the HTML file, a title tag is automatically created in my HTML file. I do not want this title tag to appear in my HTML file. How can I prevent this from happening? Or how c ...

The Input Boxes Are Too Broad

Currently, I am working on a responsive web page that features a form. However, I have noticed that all the input elements are spilling out of the form both from the left and right sides. Can someone please shed some light on why this could be happening? ...