边界半径;溢出:隐藏,文本不被剪切
我正在圆形 div 内制作一些风格文本,其中文本正好碰到容器的顶部。我已经能够控制几乎所有内容、嵌套 div、设置为背景的图像等,并成功剪辑它们,但这一个一直给我带来严重的悲伤。
使用老式图像边框或遮盖并不是解决方案,因为我们有动态图形背景。我们需要一个解决方案来实际剪辑文本。
这在 Firefox 3.x 和旧版本的 Chrome 中最为明显。
以下是可使用的示例代码:
div {
-moz-border-radius: 45px;
border-radius: 45px;
background-color: #ccc;
font-size: 100px;
color: #777;
line-height: 70%;
overflow: hidden;
width: 257px;
}
卡顿:
请注意,它已在新的 Chrome 和 FireFox 4 中修复 - shui:
我们网站的大多数用户都使用 Firefox 3.6,因此也希望能够为他们提供一个优雅的解决方案。任何帮助表示赞赏!干杯
I'm doing some stylistic text inside of rounded divs, where the text bumps right up against the top of the container. I've been able to control almost all content, nested divs, images set as backgrounds, etc, and had them all clip successfully, but this one has been giving me serious grief.
Using the old-school image borders or cover-ups is not a solution as we have dynamic graphical backgrounds. We need a solution to actually clip the text.
This is mostly visible in Firefox 3.x and older versions of Chrome
Here's the sample code to play with:
div {
-moz-border-radius: 45px;
border-radius: 45px;
background-color: #ccc;
font-size: 100px;
color: #777;
line-height: 70%;
overflow: hidden;
width: 257px;
}
the jank:
Notice it's been fixed in the new Chrome and FireFox 4 - the shui:
Most of our site users are Firefox 3.6, so would love to be able to provide an elegant solution for them as well. Any help appreciated! Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个适用于 FF 3.6: http://jsfiddle.net/vfp3v/15/
它有一些缺点,正如您在第二个示例(在 FF 3.6 中)中看到的,剪掉的边框具有纯色,因此如果您使用某种背景,这可能看起来很难看。看看吧,它可能适合您的需求。
我刚刚添加了一个跨度:
然后将其放置在文本上,边框颜色与背景相同,位移与边框一样大:
编辑:刚刚在 chrome 10.0.6 中测试了这一点(有剪切错误)成功了!
在正确支持边框半径的浏览器中,跨度(及其边框颜色)甚至不可见,因为它被剪掉了(溢出:隐藏)。
This one works in FF 3.6: http://jsfiddle.net/vfp3v/15/
It has some drawbacks, as you can see in the second example (in FF 3.6) the clipped off border has a solid color, so if you are using some kind of background this might look ugly. Just take a look at it, it might fit your needs.
I just added a span:
and then positioned it over the text with a border in the same color as the background, and a displacement as big as the border:
edit: just tested this in chrome 10.0.6 (which has the clipping bug) and it worked!
In browsers that correctly support the border-radius the span (and it's border-color) isn't even visible because it is clipped off (overflow:hidden).