- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我在悬停和带有边框半径的 div 时遇到问题。
当 div 内部有图像和边框半径时,它的“hitbox”是不正确的。将鼠标悬停在 div 的任何 Angular 上(如果它没有边框半径, Angular 将位于何处)会导致显示悬停样式。我希望样式仅在鼠标实际位于圆圈内时显示。
如果 div 中没有任何内容,则 div 的“hitbox”是正确的,但是当其中有元素时它会超出边界。
我可以在 div 中使用背景图片,但出于可访问性原因我不希望这样做。
#test-wrapper {
background-color: #EEE;
border: 4px dashed #999;
display: inline-block;
}
#switcher {
border-radius: 50%;
overflow: hidden;
position: relative;
}
#switcher,
#switcher .first,
#switcher .second {
width: 100px;
height: 100px;
}
#switcher .first,
#switcher .second {
position: absolute;
top: 0;
left: 0;
}
#switcher:hover .first {
display: none;
}
<!-- This is used to show the "hitbox" for the switcher and has no effect on the switcher itself -->
<div id="test-wrapper">
<div id="switcher">
<!-- Shown on hover -->
<img src="https://placeholdit.imgix.net/~text?txtsize=30&txt=Second&w=100&h=100&txttrack=0" class="second">
<!-- Always shown -->
<img src="https://placeholdit.imgix.net/~text?txtsize=30&txt=First&w=100&h=100&txttrack=0" class="first">
</div>
</div>
最佳答案
这里的问题是子元素不继承其父元素的border-radius
。有两种方法可以实现您想要的:您可以将子元素的 border-radius
设置为匹配或大于父元素的半径,或者设置 overflow
父元素的属性为隐藏
。
这是一个说明问题和两种解决方案的快速片段:
*{box-sizing:border-box;color:#fff;font-family:arial;margin:0;padding:0;}
div{
background:#000;
border-radius:50%;
display:inline-block;
line-height:150px;
margin:10px;
text-align:center;
vertical-align:top;
width:150px;
}
p{
background:rgba(255,0,0,.25);
}
div:nth-of-type(2)>p{
border-radius:50%;
}
div:nth-of-type(3){
overflow:hidden;
}
<div><p>Square hit area</p></div><div><p>Round hit area 1</p></div><div><p>Round hit area 2</p></div>
如果子元素是图像,那么您将需要使用图像映射来裁剪它们的命中区域(图片来源:Border-radius and :hover state area issue),如下所示:
*{box-sizing:border-box;color:#fff;font-family:arial;margin:0;padding:0;}
div{
background:#000;
border-radius:50%;
display:inline-block;
margin:10px;
text-align:center;
vertical-align:top;
width:calc(33% - 20px);
max-width:600px;
}
img{
display:block;
cursor:pointer;
height:auto;
width:100%;
}
div:nth-of-type(2)>img{
border-radius:50%;
}
div:nth-of-type(3){
overflow:hidden;
}
<div><img alt="" height="600" src="http://lorempixel.com/600/600/nature/3/" width="600"></div><div><img alt="" height="600" src="http://lorempixel.com/600/600/nature/3/" width="600" usemap="circle"></div><div><img alt="" height="600" src="http://lorempixel.com/600/600/nature/3/" width="600" usemap="circle"></div>
<map name="circle"><area shape="circle" coords="0,100%,100%,100%"></map>
关于html - :hover on a div with a border radius,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33373735/
我正在尝试实现 RADIUS 协议(protocol)。根据 RFC 2866,对于 RADIUS 记帐,在计算 Authenticator 字段时,这些步骤如下: The Authenticator
有一台pptp服务器,我使用radius服务器进行认证。有时 vpn 客户端不明原因离线,因此 radius 无法清除客户端的 session 。 我想用radius client运行一个进程来监控c
struct circle { int center; int radius; }; struct circle *cir; cir.center cir->radius (cir.rad
IE9、Firefox 4、Opera 10.5、Safari 5、Chrome 4、WebKit 532.5 支持 CSS3 border-radius。 最新的 jquerycurvycorner
环境: Radius 服务器:FreeRadius Radius 客户端:TinyRadius 我正在我们的组织中设置 RADIUS 服务器。我想保护我的 RADIUS 服务器,以便客户端需要提供两件
我继承了一个应该在 IE8 中工作的 Web 元素(以及其他浏览器,但相比之下我并不担心它们)。当我在 Firefox 中运行该网站并检查它提到的错误控制台时: “警告:未知属性‘-moz-borde
我是 Threejs 的新手。我试图用不同的方式画一个肘部 begin_radius和 end_radius沿着带有 curve_radius 的曲线路径和一个 angle ,却无法取得成果。 Cyl
有什么方法可以在 CSS 验证器中验证 -moz-border-radius/-webkit-border-radius 吗? 客户想要侧边栏中的验证按钮(呃!),但我找不到任何绕过它的方法。我也使用
我的 Captiveportal 显示出非常奇怪的行为。 偶尔(5-6 天内 2-3 次)它会返回有关耗尽允许内存大小的标准 php 错误。日志显示此时 FreeRadius 没有应答 Error s
Edit1: Span code in the code and it's style are not needed, i just added them to show, where my bord
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
基本上我想知道 Microsoft、LinkedIn 和其他人所指的渲染性能差异是在 0px 和 1px 之间还是在 1px 到无穷大 px 之间。 最佳答案 看看this article ,它没有回
谁能澄清为什么添加 padding-top 似乎会导致浏览器忽略 border-radius 属性? 您可以通过从样式属性中删除/添加填充来进行快速测试,注意如何使用填充,忽略边框半径。 这是一个错
我正在研究在 iOS 的 UIWebView 中使用的一些 CSS。我可以使用 border-radius 属性在 iOS 6 中将 div 的 Angular 变圆,但我无法使用 border-ra
这是数学高手的数学/几何问题(不是我最擅长的科目)。这是针对 WPF 的,但应该足够通用以解决问题: 我有两个嵌入的 Border 元素,外部元素具有特定的角半径 R 和边框厚度 T。给定这两个值,内
我有这个 HTML 代码: 还有这个 CSS: .categoryButton { position:
我正在使用 cakephp 并想为某些部分的圆 Angular 做 css border-radius。它适用于除 IE 之外的所有其他浏览器。我现在指的是链接 http://www.htmlremi
我在按钮上遇到 border-top-left-radius 和 border-bottom-left-radius 的问题,这似乎在开发构建中有效,但在生产。当我运行 ng serve 时,我得到了
我一直在寻找 acctinputoctets 或 acctoutputoctets 的明确含义我一直将它用作字节。 但是这个属性的真正单位是什么?我不懂八位位组,而且它太含糊了。 你能用通俗的语言解释
我一直在寻找 acctinputoctets 或 acctoutputoctets 的明确含义我一直将它用作字节。 但是这个属性的真正单位是什么?我不懂八位位组,而且它太含糊了。 你能用通俗的语言解释
我是一名优秀的程序员,十分优秀!