perfecting the styling of a tab management system

For reference, please check out the following link: http://jsfiddle.net/XEbKy/3/

In my design, I have organized two layers of tabs. The top layer consists of two tabs while the bottom layer has three tabs. My goal is to have all these tabs neatly enclosed within a single rectangular space. Specifically, I want each of the top tabs to occupy 1/2 of the horizontal space and each of the bottom tabs to take up 1/3 of the horizontal space.

#top-menu
{
    width:20em;
}

I intend for the overall width to remain constant, with each top tab utilizing 50% of that width:

.menu-tab
{
    width:50%;
    background-color:lime; 
}

Similarly, each bottom tab should take up 33% of the width:

.view-tab
{
    width:33.33333%;
    background-color:red;
}

Despite applying these styles, the layout does not turn out as expected. I am unsure about what I am missing or how to correct it. Any guidance on achieving the desired outcome would be appreciated.

You can view the updated fiddle based on Diodeus' suggestion here: http://jsfiddle.net/CASM6/1/

Answer №1

It is recommended to create menus using lists instead of DIVs. Lists are more semantically correct for a group of similar items. Here is an example:

<div id='top' class="menu">
   <ul>
       <li>Top 1</li>
       <li>Top 2</li>
    </ul>   
</div>
<div id='bottom' class="menu">
    <ul>
        <li>Bottom 1</li>
        <li>Bottom 2</li>
        <li>Bottom 3</li>
    </ul>  
</div>

css:

.menu ul, .menu li {
    list-style-type:none;
    margin:0;
    padding:0;
}   

.menu li {
     display:block;
     float:left;

}  

#top li {  
    background-color:lime;  
    width:50%;  
}

#bottom li { 
    background-color:red;
    width:33.33%;
} 

Answer №2

To ensure proper formatting, you must include the CSS properties display:block (which allows the use of width. <span> typically does not support width declarations) and float:left (to prevent stacking like regular display:block elements).

Check out this example on JSFiddle for clarification: http://jsfiddle.net/vBa7m/

.menu-tab
{
    width:50%;
    background-color:lime;
    display: block;
    float: left;

}
.view-tab
{
    width:33.33333%;
    background-color:red;
    display: block;
    float: left;

}

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

Rotate each row of the table in sequence with a pause between each flip

I have a table with 3 columns and 10 rows. I would like to flip each row one by one, where each row contains data on both the front and back sides. The flipping animation should be similar to the example provided in this link, but the flipping should sta ...

Leveraging the power of Material-UI and React, modify the appearance of the "carrot" icon within the

Currently implementing MUI's textfield based on the information found at this link: https://mui.com/components/text-fields/. While there are numerous resources available for changing the font of the input text, I have not come across any documentation ...

Transition one background image into another using background positioning

Snippet of code: https://jsfiddle.net/foy4m43j/ HTML: <div id="background"></div> CSS: #background { background-image: url("http://i.imgur.com/hH9IWA0.png"); background-position: 0 0; background-repeat: repea ...

I am experiencing an issue where the tooltip does not appear when I click the icon. What adjustments can be made to the code to ensure that the tooltip

I have created a feature to copy abbreviation definitions when the clipboard icon is clicked. A tooltip displaying 'Copied' should appear after clicking the icon, but for some reason, it's not visible. Here's the code: $(document).re ...

Adding space between Bootstrap columns to align them one below the other on small devices

https://i.sstatic.net/turhY.png Within this illustration, there are two columns - one with the class col-sm-3 and the other with col-sm-8, situated in a single row. Upon resizing the window (as shown in the screenshot provided), the two columns appear ...

Adjust the column count in mat-grid-list upon the initial loading of the component

My goal is to implement a mat-grid-list of images with a dynamic number of columns based on the screen size. Everything works perfectly except for one small glitch – when the grid first loads, it defaults to 3 columns regardless of the screen size until ...

bootstrap3 container alignment

I encountered a challenge while attempting to right-align multiple Bootstrap 3 containers in a straightforward manner. Despite my efforts, achieving this proved to be more complex than expected. In essence, I faced an issue where aligning the text box with ...

Tips for displaying the webpage background above a specific div by utilizing a differently shaped div

I designed a webpage with a background image. At the top, I placed a div element (let's call it div_1) set to 50% width which creates a horizontal black bar with 60% opacity. Directly above that, towards the left at 50%, I want another div element (di ...

Personalizing CSS for a large user base

My website allows users to choose themes, customize background, text, and more. I am seeking the best method to save all of these changes. Is it preferable to use a database read or a file read for this purpose? Any recommendations are greatly appreciate ...

The carousel caption in Bootstrap 5 vanishes when viewing the website on a smaller device

Currently, I'm dealing with an issue using bootstrap carousel code. The carousel text displays properly on desktop screens but disappears when viewed on smaller sized screens. It appears that the text is being hidden behind the image. Various attempts ...

Tips for transforming a menu into a dropdown menu

Is there a way to convert the current menu into a Dropdown menu? Currently, the menu is not collapsing and it keeps opening. Any suggestions on how to achieve this? Here is an example for reference: https://i.stack.imgur.com/2X8jT.png ar ...

Is it possible to create a list item animation using only one div element?

I'm currently working on achieving a dynamic animation effect for list items similar to the one demonstrated in Pasquale D'Silva's design example: https://medium.com/design-ux/926eb80d64e3#1f47 In this animation, the list item disappears wh ...

Tips for styling a datatable scrollbar with CSS

My preference is to utilize the datatable API when creating tables. $('#datatable-example').dataTable({ "scrollX": true, "info" : false, "fnDrawCallback" : function(oSettings) { $('td').removeClass('sor ...

What is the best way to delete HTML classes that were generated by a function?

Currently, I'm immersed in the Etch A Sketch project as part of my journey through The Odin Project. Using DOM manipulation, I successfully created a grid and displayed it on the screen. Now, my aim is to allow users to resize the grid by removing the ...

CSS positional sequencing dilemma

I am having trouble with the layout in this particular scenario: . In the #boxOne div, I have a link followed by a div (#formloc) containing an input and another link. Even though the first link ("Appliquer une localisation") is placed before the #formlo ...

The unequal division of space between two flexed child divs is caused by varying image sizes

In my parent container, I have set the display property to flex. Inside, there are two divs with both having flex:1 set. However, the first child div contains an image and takes up twice as much space as the second div. If the screen is 1000px in height, ...

I am having difficulty retrieving all the cssRules for certain pages

Attempting to retrieve all CSS rules using JavaScript has yielded varying results. For instance, on StackOverflow, the code used is: console.log( document.styleSheets[1].href,'rules', document.styleSheets[1].cssRules,'Should be css rules, ...

Achieve inline or floating displays seamlessly without the need for media queries to prevent breaking

Whenever I attempt to apply float left or display inline, it causes issues. The form currently has a max-width of 1000px. I was hoping that the first and last names would automatically align side by side if there is enough space. Perhaps setting a min-widt ...

Is there a way to shift this modal to the right?

I am facing an issue with aligning a button modal to the right side. I attempted using bootstrap classes like : float:right, mt:20 Unfortunately, these did not have the desired effect. Below is my code snippet: <b-modal ref="my-modal" hide-fo ...

What could be causing the distance between the image and the navigation bar?

Hey there, I'm struggling with a pesky little gap that's sneaking in between an image and my navigation bar. I've exhausted all my usual tricks like setting inline-blocks on the ul and li levels, and trying to align everything left with text ...