将背景延伸到边距 [英] Extend a background into the margin

查看:93
本文介绍了将背景延伸到边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有10个像素边距的< div> 元素,如下面的代码所示。我的问题很简单:如何将背景图片放入边缘?我尝试过使用CSS3 background-clip background-origin 子属性,但它们没有选项来扩展背景进入保证金。

I have a <div> element that has a 10 pixel margin, as shown in the code below. My question is rather simple: how do I extend the background image into the margin? I tried using the CSS3 background-clip and background-origin sub-atributes, but they have no option for extending a background into the margin.

CSS:

CSS:

#pagesidebar
{
    background-image:url('/Users/bagavatu/images/background.png');
    margin:10px;
}

HTML:

HTML:

<div id="pagesidebar">Hello</div>

我知道我可以追加页面边栏 div转换为父div,并simpyl在那里应用background-image,但我更喜欢不需要新div的解决方案。

I know I could append the pagesidebar div into a parent div, and simpyl apply the background-image there, but I would prefer a solution not requiring a new div.

推荐答案

开关保证金:10px padding:10px 并且它应该有效。

Switch margin: 10px to padding: 10px and it should do the trick.

这篇关于将背景延伸到边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆