lta*_*ett 6 css jquery google-chrome browser-detection
这仍然是Chrome 5.0.375.125的最新版本,这是撰写本文时的最新Windows版本.
此处会跟踪错误:http: //code.google.com/p/chromium/issues/detail?id = 25334
所以,问题是,如果您使用的是Windows或Linux,并且有人在也具有border-radius的元素上使用了插入框阴影,则会出现错误 - 边框半径被保留,但插入框 - 阴影溢出来,好像它仍然是一个方盒子.它在Mac OS X上的Chrome中按预期工作.
使用纹理背景的人不能使用这种黑客,因为它需要不透明的边框颜色.它也只适用于较小的半径.
这个黑客的两个部分.一个小Javascript(jQuery + jQuery.client插件):
if ($.client.browser == "Chrome" && $.client.os != "Mac"){
  $('html').addClass("inset-radius-hack");
};
Run Code Online (Sandbox Code Playgroud)
和CSS
#div{
  -moz-border-radius: 7px;
  -webkit-border-radius: 7px;
  border-radius: 7px;
  -moz-box-shadow: rgba(0, 0, 0, 0.4) 1px 1px 4px 0 inset;
  -webkit-box-shadow: rgba(0, 0, 0, 0.4) 1px 1px 4px 0 inset;
  box-shadow: rgba(0, 0, 0, 0.4) 1px 1px 4px 0 inset;
  padding: 5px 10px;
  margin-bottom: 10px;
  max-width: 120px;
}
  html.inset-radius-hack #div {
    border: 2px solid #fff; /* cover the edges with the border
    margin: 0 -2px 0 -2px; /* and take back the extra pixels the border adds
  }
Run Code Online (Sandbox Code Playgroud)
我现在可以洗个澡吗?这个黑客让我觉得很糟糕.
有没有人为此提出更好的解决方法?
您可以通过 css hack 瞄准 safari 来摆脱 JS 部分,至于纹理背景,您可以使用相同的纹理作为边框(很棘手!但适用于某些纹理):
<style type="text/css">
#div{ 
  -moz-border-radius: 7px; 
  -webkit-border-radius: 7px; 
  border-radius: 7px; 
  -moz-box-shadow: rgba(0, 0, 0, 0.4) 1px 1px 4px 0 inset; 
  -webkit-box-shadow: rgba(0, 0, 0, 0.4) 1px 1px 4px 0 inset; 
  box-shadow: rgba(0, 0, 0, 0.4) 1px 1px 4px 0 inset; 
  padding: 5px 10px; 
  margin-bottom: 10px; 
  max-width: 120px; 
} 
/* Safari */
@media screen and (-webkit-min-device-pixel-ratio:0) 
{ 
   #div{
     border: 3px solid #fff; /* cover the edges with the border*/
     margin: 0 -3px 0 -3px; /* and take back the extra pixels the border adds*/
     -webkit-border-image: url(texture.gif) 4 repeat ; /*add the texture to the border*/
   }
}
</style>
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           1788 次  |  
        
|   最近记录:  |