0

I've created a simple unordered list with rounded corners, when selecting a list item I want the background to become blue to show the active state. 当我没有边界半径时,一切看起来都很棒。

然而,当我使用 4px 的边框半径来圆所有边缘,并选择底部有圆角的最后一个列表项 (#5) 时,蓝色活动状态现在在角上显示小的白色像素。我似乎无法弄清楚如何防止这种情况发生。谢谢你的帮助。.

http://jsfiddle.net/8PN8Z/

HTML

<div class="left-dash">
  <div class="dash-stats-3">
        <ul class="dash-stats-3-ul">
            <li><span id="explore-themes">testing</span></li>
            <li>
                <a href="#" class="tab-link" data-remote="true">
                    <span class="ss-pika ss-icon">1</span><span class="theme"> test-1</span>
                </a>
            </li>
            <li>
                <a href=#"" class="tab-link" data-remote="true">
                    <span class="ss-pika ss-icon">2</span><span class="theme"> test-2</span>
                </a>
            </li>
            <li>
                <a href="" class="tab-link" data-remote="true">
                    <span class="ss-pika ss-icon">3</span><span class="theme"> test-3</span>
                </a>
            </li>
            <li>
                <a href="/theme/inspiring" class="tab-link" data-remote="true">
                    <span class="ss-pika ss-icon">4</span><span class="theme"> test-4</span>
                </a>
            </li>
            <li>
                <a href="#" class="tab-link" data-remote="true">
                    <span class="ss-pika ss-icon">5</span><span class="theme"> test-5</span>
                </a>
            </li>
        </ul>
    </div>
</div>

CSS

.left-dash {
    background: #444;
    height: 500px;
}
.left-dash div {
  -webkit-border-radius: 4px 4px 4px 4px;
  border-radius: 4px 4px 4px 4px;
}
.left-dash div ul li:first-child, .left-dash div ul li:first-child a {
  -webkit-border-radius: 4px 4px 0px 0px;
  border-radius: 4px 4px 0px 0px; 
}

.left-dash div ul li:last-child,
.left-dash div ul li:last-child a {
  -webkit-border-radius: 0px 0px 4px 4px;
  border-radius: 0px 0px 4px 4px; 
}



.dash-stats-3 {
    width: 220px;
    margin-bottom: 17px;
    background: #9f9f9f;
    -webkit-background-clip: padding-box; /* for transparent border with solid bg - Safari */
    background-clip: padding-box;/* for IE9+, Firefox 4+, Opera, Chrome */
    border-radius: 0px;
    border: 1px solid rgba( 0, 0, 0, 0.15);
    box-shadow: inset 0px 0px 2px 0px #FFFFFF,0px 1px 3px 0px rgba(0,0,0, 0.15);
    -webkit-box-shadow: inset 0px 0px 2px 0px #FFFFFF,0px 1px 3px 0px rgba(0,0,0, 0.15);
    -moz-box-shadow: inset 0px 0px 2px 0px #FFFFFF,0px 1px 3px 0px rgba(0,0,0, 0.15);
    -o-box-shadow: inset 0px 0px 2px 0px #FFFFFF,0px 1px 3px 0px rgba(0,0,0, 0.15);
    font-family:'Museo Sans W01 700' san-serif;
    font-size: 14px;
    color: #828282;
    text-shadow: 0px 1px 1px #FFFFFF;
    font-weight: normal !important;
}



.dash-stats-3 ul li a, .dash-stats-3 ul li:first-child {
    height: 41px;
    border-bottom: solid rgba( 0, 0, 0, 0.15) 1px;
    border-top: solid rgba(255, 255, 255, .65) 1px;
}
.left-dash div ul li:last-child, .left-dash div ul li:last-child a {
    border-bottom: none;
}

.dash-stats-3 ul li a {
    position:relative;
    line-height:43px;
    display:block;
}


.dash-stats-3 ul li a.active-tab {
    z-index:120;
    border-top: 1px solid #5b82a7;
    background: #4e81be; /* Old browsers */ 
}

JS

$(function(){
        $('a.tab-link').click(function(){
          $('a.tab-link').removeClass('active-tab')
          $(this).addClass('active-tab')
        });
      });
4

2 回答 2

0

First, give the active-tab a radius.

.dash-stats-3 ul li a.active-tab {
    z-index:120;
    border-top: 1px solid #5b82a7;
    background: #4e81be; /* Old browsers */ 
        -webkit-border-radius: 0px 0px 2px 2px;
        border-radius: 0px 0px 2px 2px;  
}

Make sure its smaller than the li's radius, (2px).

And remove the radius for the a in its default state. Remove this.

.left-dash div ul li:last-child a{
  -webkit-border-radius: 0px 0px 4px 4px;
  border-radius: 0px 0px 4px 4px; 
}

Keep this.

.left-dash div ul li:last-child{
  -webkit-border-radius: 0px 0px 4px 4px;
  border-radius: 0px 0px 4px 4px; 
}

Check it out : http://jsfiddle.net/FcXVY/

The problem is that you're giving a child element the same border radius as the parent element. Even if the parent element won't have a border, there will be some tiny pixels shown, and with a border, its worse. Check this out : http://jsfiddle.net/UVTJQ/

于 2013-02-16T16:55:59.010 回答
0

好的。我认为这可以简化事情。一探究竟。我希望它有所帮助。

http://jsfiddle.net/sheriffderek/8WTam/

<ul class="test-list">
    <li><a href="?">Item thing</a></li>
    <li><a href="?">Item thing</a></li>
    <li><a href="?">Item thing</a></li>
    <li><a href="?">Item thing</a></li>
    <li><a href="?">Item thing</a></li>
    <li><a href="?">Item thing</a></li>
</ul>

CSS:

/* border box - google it. it rules*/ 
* { 
    -moz-box-sizing: border-box; 
    -webkit-box-sizing: border-box; 
    box-sizing: border-box; 
}

.test-list {
    float: left;
    overflow: hidden;
    list-style: none;

    /* just to show the properly containing ul */  
    margin: 2em;
    background-color: rgba(0,0,0,.05);
    padding: 1em;
}

.test-list li {

}

.test-list a {
    display: block;
    float: left;
    clear: left;
    background-color: #f06;
    padding: 1em 2em;
    min-width: 12em;

    color: white;
    text-decoration: none;
    border: 3px solid rgba(0,0,0,1);
    border-bottom: 0;
}

.test-list a:hover {
    background-color: lightblue;
    color: black;
}

.test-list li:first-of-type a {
    -webkit-border-radius:.4em .4em 0 0;
    border-radius: .4em .4em 0 0;
}

.test-list li:last-of-type a {
    -webkit-border-radius: 0 0 .4em .4em;
    border-radius: 0 0 .4em .4em;
    border-bottom: 3px solid black;
}
于 2013-02-16T21:14:33.393 回答