Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html ul li - tabs

I'm scratching my head here for something I thought could be so simple.

I have a tabs created using ul/li elements.

Suppose I have the following:

  • Tab1
  • Tab2
  • Tab3
  • Tab4

The tabs gets displayed horizontally like:

Tab1 Tab2 Tab 3

Tab4

There is a fixed width, so it overflows horizontally.

What I would like to have is the row with lowest number of tabs to be at the top like this:

Tab4

Tab1 Tab2 Tab3

How can I accomplish this?

Many thanks in advance

like image 963
Faizul Hussain Avatar asked May 22 '12 10:05

Faizul Hussain


People also ask

What is HTML Li and UL tag?

Definition and Usage The <li> tag defines a list item. The <li> tag is used inside ordered lists(<ol>), unordered lists (<ul>), and in menu lists (<menu>). In <ul> and <menu>, the list items will usually be displayed with bullet points. In <ol>, the list items will usually be displayed with numbers or letters.

How do I insert a tab in HTML?

The tab character can be inserted by holding the Alt and pressing 0 and 9 together.

How do I make an active tab in HTML?

Approach: In the body tag create some tabs under the div tag with a Custom-Data-Attribute that holds the id of the content. Create another div tag to store the content of the tab with a specific id. Specify data attributes for each content tag to display only one tab content at a time.

What is use of Li tag in HTML?

The <li> HTML element is used to represent an item in a list. It must be contained in a parent element: an ordered list ( <ol> ), an unordered list ( <ul> ), or a menu ( <menu> ). In menus and unordered lists, list items are usually displayed using bullet points.


1 Answers

Many thanks for all the responses guys. But maybe my question wasn't clear. Also I'm new to stack-overflow.com so please take it easy on me :)

Anyway, what I did last night to solve this issue was using jQuery, remove the current tabs and re-create them - but this time add a fixed number of list-item/tabs per ul/row. If there are more than the fixed number per tab, then create a new ul element for them. Each UL element will be like a new row

Here's my javascript/jQuery

// contains tab headers and contents
var tabsContainer = $('.tabs');
// this is a UL element containing the tab headers
var currentUlElement = $('.tabNavigation');
// this are the LI elemets which are the actual tabs
var currentLiElements = currentUlElement.children('li');

// we can only have 6 tabs plus the '+' tab (total 7) in a row.
// if there's mroe than that we need to sort the overflow
if (currentLiElements.length > 7) {

    // remove all current tab headers
    currentUlElement.remove();

    // create new tab headers container
    var newUlElementRow = $('<ul />');
    // make the list items appear like tabs
    newUlElementRow.addClass('tabNavigation');
    // add the new tabs header container to the front of the main tab/content container control
    tabsContainer.prepend(newUlElementRow);

    for (var index = 0; index < currentLiElements.length; index++) {

        // if one row of tabs is complete
        if (index == 6) {
            // create a new tab headers container
            newUlElementRow = $('<ul />');
            // make the list items appear like tabs
            newUlElementRow.addClass('tabNavigation');
            // add the new tabs header container to the front of the main tab/content container control
            tabsContainer.prepend(newUlElementRow);
        }

        // add the tab/list item to the new tab headers container
        newUlElementRow.append(currentLiElements.get(index));
    }

    // re-enable the tab click actions
    trackNetPeople.SetupTabs();
}
like image 125
Faizul Hussain Avatar answered Oct 06 '22 07:10

Faizul Hussain