简体   繁体   English

使用img作为背景<h1>

[英]using img as background for <h1>

At the moment i'm working with CSS (really new to it) and i want to have a background img for headers - managed to make it work - however, strugling to make img width adjust to the length of the header (content) 目前,我正在使用CSS(这确实很新),并且我想为标题设置背景img-设法使其正常工作-但是,正在努力使img的宽度适应标题的长度(内容)

h2{
 font-family: Arial, Helvetica, sans-serif; 
 font-size: 20px; 
 padding-left: 20px; 
 padding-top: 10px;
 margin-top:10px;
 color:white;
 }
span h2{
 background-image: url(border.gif);
 background-repeat: no-repeat;
 background-position: bottom left;
 background-size: 100% 100%;
 }

As you can see i've tried to inclose inside inline element such as , tried making as an inline element too, but can't make it work. 如您所见,我尝试在内联元素(例如)中封闭,也尝试将其作为内联元素,但无法使其正常工作。

Any help would be much apriciated 任何帮助将不胜感激

Span is inline element and block headline shouldn't be inside. Span是内联元素,块标题不应在内部。

If you want to set background to h2 , set it to h2 . 如果要将背景设置为h2 ,请将其设置为h2

h2 {
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 20px; 
    padding-left: 20px; 
    padding-top: 10px;
    margin-top:10px;
    color:white;
    background: url('border.gif') left bottom / 100% 100% no-repeat;
}

In HTML there will be just h2 , no span around. 在HTML中,只有h2 ,而没有span

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

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