【发布时间】:2022-04-23 21:02:05
【问题描述】:
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) 时,蓝色活动状态现在在角上显示小的白色像素.我似乎无法弄清楚如何防止这种情况发生。谢谢你的帮助。 .
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')
});
});
【问题讨论】:
-
我认为你在 div 上应用了一些东西(也许是 box-shadow?),你应该应用到每个单独的 li 甚至链接上。父 div 不知道border-radius 被应用在它的一些孩子上,它应该适应它。
-
您好,感谢您的帮助。我认为不可能将 box-shadow 应用于单个 li 或链接,这会使每个框都有自己的阴影而不是整个无序列表。我很困惑为什么如果所有内容的边界半径都相同,父 div 会导致问题?
-
这段代码很粗糙。我建议把它降低一个档次,把问题提炼成简单的事情。我以前从未在 jsfiddle 中使用过 !important 。这些选择器很疯狂。我想你可能想多了。另外-您可能要注意,有时边界半径看起来很奇怪,例如 4px 等-平均屏幕无法流畅地渲染它,因为它太小而且像素太小了。在视网膜屏幕上检查它作为侧面测试。