Jquery 选项卡帮助

发布于 2024-09-05 01:20:44 字数 1401 浏览 1 评论 0原文

所以我试图在菜单中创建一个选项卡,但无法使每个选项卡的整个宽度为 219px。它只允许我将 li 设为 219,但我想将 li 设为 219px。我似乎无法弄清楚。还有一种方法可以制作下一个按钮,或者最好的方法是转到每个选项卡并以某种方式直接放入下一个选项卡?

任何帮助将不胜感激

Css

.servicesNavigation li {
    float: left;
    list-style: none;
    width: 219px;
}

ul.servicesNavigation li a {
    padding: 3px 5px;
    background-color: #ccc;
    color: #000;
    text-decoration: none;
    width: 219px;
}

ul.servicesNavigation li a.selected, ul.tabNavigation li a:hover {
    background-color: #333;
    color: #fff;
    padding-top: 7px;
}

ul.servicesNavigation li a:focus {
    outline: 0;
}

HTML

<ul class="servicesNavigation">
<li><a href="#Web">Web</a></li>
<li><a href="#Print">Print</a></li>
<li><a href="#DynamicContent">Dynamic Content</a></li>
<li><a href="#Hosting">Hosting</a></li>
</ul>       

Jquery

var tabContainers = $('div.servicesInfo > div');
tabContainers.hide().filter(':first').show();

$('div.servicesInfo ul.servicesNavigation a').click(function () {
    tabContainers.hide();
    tabContainers.filter(this.hash).show();
    $('div.servicesInfo ul.servicesNavigation a').removeClass('selected');
    $(this).addClass('selected');
    return false;
}).filter(':first').click();

So I am trying to make a tabs in a menu but cant make the whole width of each of the tabs 219px. it only allows me to make the li 219 but I wanna make the li a 219px. I cant seem to figure it out. Also is there a way to make a next button or would the best way to go to each tab and literally put in the next tab in a type of way?

any help would be greatly appreciated

Css

.servicesNavigation li {
    float: left;
    list-style: none;
    width: 219px;
}

ul.servicesNavigation li a {
    padding: 3px 5px;
    background-color: #ccc;
    color: #000;
    text-decoration: none;
    width: 219px;
}

ul.servicesNavigation li a.selected, ul.tabNavigation li a:hover {
    background-color: #333;
    color: #fff;
    padding-top: 7px;
}

ul.servicesNavigation li a:focus {
    outline: 0;
}

HTML

<ul class="servicesNavigation">
<li><a href="#Web">Web</a></li>
<li><a href="#Print">Print</a></li>
<li><a href="#DynamicContent">Dynamic Content</a></li>
<li><a href="#Hosting">Hosting</a></li>
</ul>       

Jquery

var tabContainers = $('div.servicesInfo > div');
tabContainers.hide().filter(':first').show();

$('div.servicesInfo ul.servicesNavigation a').click(function () {
    tabContainers.hide();
    tabContainers.filter(this.hash).show();
    $('div.servicesInfo ul.servicesNavigation a').removeClass('selected');
    $(this).addClass('selected');
    return false;
}).filter(':first').click();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

望她远 2024-09-12 01:20:44

锚点的宽度

默认情况下,锚点显示为内联元素。内联元素只会被赋予显示其内容所需的最小高度和宽度。

您可以声明它们应显示为 block 元素。这样,浏览器将遵循您提供的 width 声明。

为了防止链接超出列表元素右侧 10 像素,请删除 li 的宽度规范。

.servicesNavigation li {
    float: left;
    list-style: none;
    /* width: 219px; */ <-- Remove this declaration
}

ul.servicesNavigation li a {
    display: block; <-- Add this declaration
    padding: 3px 5px;
    background-color: #ccc;
    color: #000;
    text-decoration: none;
    width: 219px;
}

下一个/上一个

我建议在列表之外的某个位置添加以下标记,并以您想要的任何方式设置样式:

<a id="previous" href="#previous">previous</a>
<a id="next" href="#next">next</a>

然后您可以轻松地将处理程序绑定到每个标记的 click 事件,以查找与要显示的新选项卡并依次触发 click 事件。

$('#next').click(function() {
   var selectedLink = 
      $('div.servicesInfo ul.servicesNavigation a.selected').first();
   selectedLink.parent().next().children().click();
   return false;
});

$('#previous').click(function() {
   var selectedLink = 
      $('div.servicesInfo ul.servicesNavigation a.selected').first();
   selectedLink.parent().prev().children().click();
   return false;
});

Width of Anchor

Anchors are by default displayed as inline elements. An inline element will only be given the minimum amount of height and width necessary to display its contents.

You could declare that they should be displayed as block elements. This way, the browser will honor the width declaration you have provided.

To then prevent your links from overflowing out the right of your list elements by 10px, remove the width specification for the li.

.servicesNavigation li {
    float: left;
    list-style: none;
    /* width: 219px; */ <-- Remove this declaration
}

ul.servicesNavigation li a {
    display: block; <-- Add this declaration
    padding: 3px 5px;
    background-color: #ccc;
    color: #000;
    text-decoration: none;
    width: 219px;
}

Next/Previous

I would suggest adding the following tags somewhere outside of your list, styled any way you'd like:

<a id="previous" href="#previous">previous</a>
<a id="next" href="#next">next</a>

Then you can easily bind a handler to the click event of each to find the link corresponding with the new tab to display and in turn trigger its click event.

$('#next').click(function() {
   var selectedLink = 
      $('div.servicesInfo ul.servicesNavigation a.selected').first();
   selectedLink.parent().next().children().click();
   return false;
});

$('#previous').click(function() {
   var selectedLink = 
      $('div.servicesInfo ul.servicesNavigation a.selected').first();
   selectedLink.parent().prev().children().click();
   return false;
});
゛时过境迁 2024-09-12 01:20:44

您不能为内联元素设置宽度。尝试li a {display:inline-block;}

You cannot set a width to inline elements. Try li a {display:inline-block;}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文