我正在尝试创建一个选项卡式界面,以便所选选项卡下面没有任何行,无论选项卡内文本的字体大小如何,并且仅使用CSS2。我添加了一个底部边框,但我不确定如何删除所选标签下方的底部边框。如果我尝试使用负边距,则只需在底部边框和标签之间添加一个空格。我可以尝试使用图像来创建底部边框,而不是使用底部边框CSS功能;但是,我试图避免这种情况。有什么想法吗?
HTML:
<body>
<div id="tabs">
<ul>
<li><a href="#1"><span>Tab1</span></a></li>
<li id="selected"><a href="#2"><span>Tab2</span></a></li>
<li><a href="#3"><span>Tab3</span></a></li>
</ul>
</div>
</body>
CSS:
body {
/* Centers and adjusts length of the line that is
separating the tabs from the rest of the page */
margin-left: auto;
margin-right: auto;
width: 98%;
}
#tabs {
float: left;
width:100%;
font: 12px Arial;
/* Adds line separating tabs from rest of page */
border-bottom-style: solid;
border-bottom-color: #cccccc;
border-bottom-width: 1px;
}
#tabs ul {
list-style: none;
margin: 0;
/* Adds padding on sides of the entire tabbed bar */
padding:5px 5px;
}
#tabs ul li {
float:left;
background-image: url('righttab.jpg');
background-repeat: no-repeat;
background-position: right top;
/* Adds space between each tab */
margin:0px 3px;
padding:0;
}
#tabs ul li a {
display: block;
float:left;
text-decoration: none;
color: #000000;
background-image: url('lefttab.jpg');
background-repeat: no-repeat;
background-position: left top;
/* Adds padding on sides of hyperlink area
to reveal curved edges of tab */
padding:0px 3px;
margin:0px;
}
#tabs ul li a span {
float: left;
background-image: url('midtab.jpg');
background-repeat: repeat-x;
background-position: center top;
/* Adds padding between the tab text
and the edges of the tab */
padding:3px 5px;
margin:0px;
}
/* Formatting for selected tab */
#tabs li#selected {
background-image: url('right-selected.jpg');
background-repeat: no-repeat;
background-position: right top;
}
#tabs li#selected a {
display:block;
font-weight: bold;
background-image: url('left-selected.jpg');
background-repeat: no-repeat;
background-position: left top;
}
#tabs li#selected a span {
background-image: url('mid-selected.jpg');
background-repeat: repeat-x;
background-position: center top;
}
答案 0 :(得分:0)
在这里:http://jsfiddle.net/th8bucda/
我修改了所选项目的css结尾:
#tabs li#selected a {
display:block;
font-weight: bold;
background-image: url('http://s10.postimg.org/kberhjcr9/left_selected.gif');
background-repeat: no-repeat;
background-position: left top;
**border-bottom-style: solid;
border-bottom-color: #fff;
border-bottom-width: 5px;
margin-bottom:-5px;**
答案 1 :(得分:-1)
我创造了一个小提琴,我猜可以帮助你朝着正确的方向前进。因为我不知道你的图像是什么样的,这个小提琴是没有图像。
唯一修改过的CSS是:
#tabs li#selected {
background-image: url('right-selected.jpg');
background-repeat: no-repeat;
background-position: right top;
/* added: */
background-color: #ffffff;
height:21px; // one pixel more then original tab
position: relative;
margin-top:-1px;
top:1px; // position tab over bottom border
}