繁体   English   中英

用图案或图像填充边框?

[英]fill border with pattern or image?

我有按类别分开的企业列表。 在每个类别名称的旁边,相隔大约20像素,我希望有一个3像素高的边框延伸到div的末尾。 我希望该边框充满图案或图像。 最初,我尝试仅使用图像,但是由于每个类别名称的长度都不同,因此被证明是不切实际的。

我敢肯定有一个相对简单的方法可以做到这一点,但我不确定如何实现它。 有想法吗?

谢谢。

理想

更新图片 在此处输入图片说明

在这里,我使用<div>来显示<h1> 类别后面的边框,其中<body><h1>都具有匹配的背景图案(也已对齐)

例子jsfiddle

的CSS

body {
    background:url('http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/gray_jean.png');
    font-family:helvetica,arial,sans-serif;
}

#container {
    margin:0 20px;
    position:relative;
}

h1 {
    position:relative;
    float:left;
    padding-top:6px;
    padding-right:20px;
    font-size:2em;
    background:url('http://subtlepatterns.subtlepatterns.netdna-cdn.com/patterns/gray_jean.png')
}

.border {
    background:url('http://s3.amazonaws.com/creattica/uploaded-images/0016/6142/patterns_009_blue-hexagon-pattern_crop-iphone_web_for-creattica.jpg') repeat-x -10px 0;
    position:absolute;
    top:20px;
    width:100%;
    height:3px;
}

.listings {
    clear:both;
}
​

的HTML

<div id="container">
    <div class="border"></div>
    <h1>Catering</h1>
    <div class="listings">
        <ul>
            <li>
                Catering Company 1
            </li>
            <li>
                ...
            </li>
        </ul>
    </div>
</div>​

如果允许使用其他标记(并且您的父元素具有坚实的背景),则可以通过以下方式进行处理:

h1 {
    background: red; /* replace with background-image */
}

h1 span {
    background: white; /* replace with color of parent element's bg */
}

<h1><span>Test Headline</span></h1>

http://jsfiddle.net/358Gg/

暂无
暂无

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

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