简体   繁体   中英

how to stretch or fit a background image using css attribute background in a class

How to stretch or fit a background image using css attribute background in a class. I am using a icon in li and want to fit on specific width. but it not render.

HMTL code.

<ul>
   <li class="social-bg-facebook">F</li>
   <li class="social-bg-twitter">T</li>
   <li class="social-bg-user">U</li>
   <li>UN</li>
</ul>

i am using these classes to fit background in li

CSS code.

.icon-list li {
    margin:0px;
    padding:0px;
    position: relative;
    top: -36px;
    left: 5px;

}
.icon-list li.social-bg-facebook {
    background:url(images/facebook.png) no-repeat;
    width:35px;
}
.icon-list li.social-bg-twitter {
    background:url(images/twitter-icon.png) no-repeat;
    width:35px;
}

You can use background-size :

.icon-list li.social-bg-facebook {
    background:url(images/facebook.png) no-repeat;
    background-size: 100% 100%;
    width:35px;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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