css html ul li -标签页

6tdlim6h  于 2022-12-01  发布在  其他
关注(0)|答案(7)|浏览(242)

我在这里挠头,因为我认为这是如此简单的事情。
我使用ul/li元素创建了一个选项卡。
假设我有以下内容:

  • 页签1
  • 页签2
  • 选项卡3
  • 页签4

选项卡水平显示如下:
标签1标签2标签3
页签4
有一个固定的宽度,所以它水平溢出。
我希望将选项卡数量最少的行放在顶部,如下所示:
页签4
标签1标签2标签3
我如何才能做到这一点?
提前感谢

fgw7neuy

fgw7neuy1#

非常感谢各位的回答。但是可能我的问题不清楚。另外,我是www.example.com的新手stack-overflow.com,所以请对我放松点:)
无论如何,我昨晚使用jQuery解决了这个问题,删除了当前的选项卡并重新创建了它们--但是这次在每个ul/行中添加了固定数量的列表项/选项卡。如果每个选项卡的数量超过了固定数量,则为它们创建一个新的ul元素。每个UL元素将像一个新行一样
下面是我的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();
}
cfh9epnr

cfh9epnr2#

我可能没有很清楚地理解你的问题,但你似乎试图将最后一个tab li元素与其他li元素分开:
这可以通过以下方式实现:

.tabs ul li:last-child {
  display: block;
}

并使最后一个li成为第一个li,使用jQuery,如下所示:

$(function(){

   $('.tabs ul').prepend($('.tabs ul').find('li:last'));

});
nx7onnlm

nx7onnlm3#

我不认为你可以,因为你没有使用任何“行”。它只是简单的文本被推到下一行。
如果你的标签来自数据库,你可以用PHP来处理它们,用数组来排序,但是你仍然需要另一种方式来显示它们。表格可能是一个很好的选择(在这种情况下)。

busg9geu

busg9geu4#

你可以这样写:

HTML格式

<ul>
    <li>test4</li>
    <li>test1</li>
    <li>test2</li>       
    <li>test3</li>
</ul>

CSS格式

li + li{
    float:left;
}

检查此http://jsfiddle.net/mxgNT/

jtoj6r0c

jtoj6r0c5#

我不知道要使用哪种类型的语言来实现这一点,但这里有一个jQuery解决方案:

实时示例:http://jsfiddle.net/gzZ6C/1/
jQuery查询器

$(function(){
    $('ul').prepend($('ul').find('li:last'));
    $('ul').find('li:not(:first)').css('float','left');
});

UPDATE:添加了浮动样式

zi8p0yeb

zi8p0yeb6#

乍听起来可能有点令人困惑。但并不太难。
CSS:

ul {position:relative;}
ul li {padding:3px 10px;height:20px}
ul li:last-child{position:absolute}
ul li:not(:last-child) {float:left;color:green;margin-top:20px; /*height of li*/}
​

现场演示:
http://jsfiddle.net/f6GEp/

ymzxtsji

ymzxtsji7#

不看标签的css风格很难判断。但是考虑使用一些框架中的标签界面,比如bootstrap标签,foundation标签或者jQuery ui标签。如果你想要一个高级的响应标签解决方案,可以看看zozo标签,里面有很多例子。
http://zozoui.com/tabs
欢呼声
Fari设计

相关问题