Jquery 选项卡帮助
所以我试图在菜单中创建一个选项卡,但无法使每个选项卡的整个宽度为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
锚点的宽度
默认情况下,锚点显示为
内联
元素。内联元素只会被赋予显示其内容所需的最小高度和宽度。您可以声明它们应显示为
block
元素。这样,浏览器将遵循您提供的width
声明。为了防止链接超出列表元素右侧 10 像素,请删除
li
的宽度规范。下一个/上一个
我建议在列表之外的某个位置添加以下标记,并以您想要的任何方式设置样式:
然后您可以轻松地将处理程序绑定到每个标记的
click
事件,以查找与要显示的新选项卡并依次触发其click
事件。Width of Anchor
Anchors are by default displayed as
inline
elements. Aninline
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 thewidth
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
.Next/Previous
I would suggest adding the following tags somewhere outside of your list, styled any way you'd like:
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 itsclick
event.您不能为内联元素设置宽度。尝试
li a {display:inline-block;}
You cannot set a width to inline elements. Try
li a {display:inline-block;}