簡體   English   中英

在較小的div中將大圖像設置為背景圖像不起作用

[英]Setting large image as a background-image in a smaller div not working

我有以下小提琴 我試圖將div的背景圖像設置如下:

.close-button{
    position: absolute;
    width: 25px;
    height: 25px;
    background-image: url('https://cdn4.iconfinder.com/data/icons/brightmix/128/monotone_close_exit_delete_small.png');
    z-index: 1;
    cursor: pointer;
    background-color: blue;
}

這是div:

<div class="close-button" data-dismiss="modal" aria-hidden="true"></div>

為什么這不起作用?

您將需要使用background-size,background-size:25px; background-size:contain; 圖片,因為它比div的尺寸大得多。

.close-button {
    position: absolute;
    width: 25px;
    height: 25px;
    background-image: url('https://cdn4.iconfinder.com/data/icons/brightmix/128/monotone_close_exit_delete_small.png');
    background-size:25px;
    z-index: 1;
    cursor: pointer;
    background-color: blue;
}

演示

附帶說明一下,此圖像太大了,不能作為圖標使用,您可以嘗試使用圖像精靈將所有圖標合並到一個圖像文件中,而僅使用css背景位置進行選擇。

您的圖片大於div。 更改div的寬度和高度,您將看到背景圖像。 或者,您必須使用較小的背景圖像。

.close-button 
{
    position: absolute;
    width: 128px;
    height: 128px;
    background-image: url('https://cdn4.iconfinder.com/data/icons/brightmix/128/monotone_close_exit_delete_small.png');
    z-index: 1;
    cursor: pointer;
    background-color: blue;
}

http://jsfiddle.net/2LTYY/4/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM