简体   繁体   English

边框图像不会在chrome中渲染块的内部背景

[英]border-image doesn't render block's interior background in chrome

When I'm using the border-image property on a block, the interior portion of the block - where the content would go - remains transparent. 当我在块上使用border-image属性时,块的内部(内容将到达的位置)保持透明。

That's while my sprite image has a perfectly opaque white interior. 那时我的子画面图像具有完全不透明的白色内部。

I can circumvent the problem by adding an internal div with the correct background, but that's unelegant. 我可以通过添加具有正确背景的内部div来规避该问题,但这很简单。 Is there a way to have the sprite's interior portion display without additional block workarounds? 有没有一种方法可以使精灵的内部显示而无需其他块解决方法? Thanks 谢谢

Problem demo page (please view in Chrome) 问题演示页面 (请在Chrome中查看)

Source: 资源:

   <style type="text/css">
    body { background: orange; padding: 30px; }
    .filling { background: white; height: inherit; margin-top: -16px; }
    .box {
        margin: auto auto;
        width: 200px; height: 200px;
        border-width: 31px 25px 25px 20px;
        -moz-border-image: url(image-border_sprite.png) 31 25 25 20 / 31px 25px 25px 20px stretch;
        -webkit-border-image: url(image-border_sprite.png) 31 25 25 20 / 31px 25px 25px 20px stretch;
        -o-border-image: url(image-border_sprite.png) 31 25 25 20 / 31px 25px 25px 20px stretch;
        border-image: url(image-border_sprite.png) 31 25 25 20 / 31px 25px 25px 20px stretch;
    }
</style>

<div class="box">
    <p>Why does the page background show through??</p>
</div>
<br /><br />
<div class="box">
    <div class="filling">
        <p>It should look like this!</p>
    </div>
</div>

I dont know why it is caused , probably a chrome bug. 我不知道为什么会造成这种情况,可能是Chrome错误。

Here is a fix however. 但是,这里有个解决方法。

Add this to your .box css 将此添加到您的.box CSS

-moz-background-clip: padding-box;
-webkit-background-clip: padding-box;
background-clip: padding-box;
background-color: white;

This will add a white background colour and clip it to its contents (including the padding). 这将添加白色背景色并将其裁剪到其内容(包括填充)。 More info on background-clip can be found here . 可以在此处找到有关background-clip更多信息。


Working Example. 工作示例。

http://jsfiddle.net/blowsie/u8ctc/ http://jsfiddle.net/blowsie/u8ctc/

For anybody with the same problem, I just found a more direct fix: the fill property. 对于任何有相同问题的人,我只是找到了一个更直接的解决方法: fill属性。 It seems that in a recent draft for border-image, the default behavior was set to keep the interior of the box transparent . 似乎在最近的border-image草稿中,默认行为已设置为保持盒子内部透明 If you want the interior to be rendered from your image sprite, you should add fill . 如果要从图像精灵渲染内部,则应添加fill For example, 例如,

Turn this: border-image: url(image-border_sprite.png) 31 25 25 20 / 31px 25px 25px 20px stretch; 转到此:border-image:url(image-border_sprite.png)31 25 25 20 / 31px 25px 25px 20px拉伸;

Into this: border-image: url(image-border_sprite.png) 31 25 25 20 fill / 31px 25px 25px 20px stretch; 变成这样:border-image:url(image-border_sprite.png)31 25 25 20 填充 / 31px 25px 25px 20px拉伸;

From my tests this negates the need for adding a background and clipping it to padding-box (thanks for the answer though). 根据我的测试,不需要添加背景并将其剪切到padding-box中(尽管需要答案)。

I got the same error with the border while using the class with attribute. 使用带属性的类时,边框出现相同的错误。 The problem was solved easily when I changed the attribute to . 将属性更改为时,该问题很容易解决。 instead of: CSS - img.pic1 {width...} htm - 而不是:CSS-img.pic1 {width ...} htm-

I used : 我用了 :

CSS - .pic1 {width...} html = CSS-.pic1 {width ...} html =

that fixed all the image bugs I had... 修复了我所有的图像错误...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM