html - CSS Sprite 下面的空白区域

标签 html css sprite css-sprites

我的 sprite css 有问题,我提供了一个 jsfiddle,所以你可以明白我的意思。所以你可以观察到图像下方有空间,我似乎无法找到问题所在。这是定位的原因吗?我尝试使用 float,但它只会减少空间。

我想要完成的是删除下面的空格,因为它在我的网站上看起来真的很难看,有空格。

附言。此外,如果我使用绝对值,它会与我网站中的文本重叠。

JsFiddle

HTML

<div class="container">
<div class="row" style="text-align:center;">
<div class="arrow-sprite"></div>
<div class="arrow-sprite-2"></div>
<div class="arrow-sprite-3"></div>
<div class="arrow-sprite-4"></div>
<div class="arrow-sprite-5"></div>
</div>
</div>

CSS

.arrow-sprite {
    background: no-repeat url(http://i.imgur.com/O8R881E.png) 19px 7px;
    width: 450px;
    height: 441px;
    position: relative;
    top: 11px;
    left: 139px;
    z-index: 1;
}
.arrow-sprite-2 {
    background: no-repeat url(http://i.imgur.com/O8R881E.png) -1381px -12px;
    width: 475px;
    height: 419px;
    position: relative;
    top: -375px;
    left: 507px;
    z-index: 4;
}
.arrow-sprite-3 {
    background: no-repeat url(http://i.imgur.com/O8R881E.png) -430px -8px;
    width: 387px;
    height: 416px;
    position: relative;
    top: -523px;
    left: 134px;
    z-index: 3;
}
.arrow-sprite-4 {
    background: no-repeat url(http://i.imgur.com/O8R881E.png) -900px 12px;
    width: 442px;
    height: 427px;
    position: relative;
    top: -908px;
    left: 418px;
    z-index: 3;
}
.arrow-sprite-5 {
    background: no-repeat url(http://i.imgur.com/O8R881E.png) 30px -438px;
    width: 519px;
    height: 490px;
    position: relative;
    top: -1529px;
    left: 239px;
    z-index: 0;
}

.arrow-sprite:hover, .arrow-sprite-2:hover,.arrow-sprite-3:hover,.arrow-sprite-4:hover {
    filter: contrast(160%);
    transition: 0.5s ease-in;
}

最佳答案

尝试将 row 的位置更改为 relative,然后将 Sprite 设置为 position:absolute; 并重新调整 top Sprite 的位置就可以了。

Also set a specific height for the row so that it won't overlap any other content below.

运行下面的代码片段:

.arrow-sprite {
        background: no-repeat url(http://i.imgur.com/O8R881E.png) 19px 7px;
        width: 450px;
        height: 441px;
        position: absolute;
        top: 11px;
        left: 139px;
        z-index: 1;
    }
    .arrow-sprite-2 {
        background: no-repeat url(http://i.imgur.com/O8R881E.png) -1381px -12px;
        width: 475px;
        height: 419px;
        position: absolute;
        top: 65px;
        left: 507px;
        z-index: 4;
    }
    .arrow-sprite-3 {
        background: no-repeat url(http://i.imgur.com/O8R881E.png) -430px -8px;
        width: 387px;
        height: 416px;
        position: absolute;
        top: 333px;
        left: 134px;
        z-index: 3;
    }
    .arrow-sprite-4 {
        background: no-repeat url(http://i.imgur.com/O8R881E.png) -900px 12px;
        width: 442px;
        height: 427px;
        position: absolute;
        top: 358px;
        left: 418px;
        z-index: 3;
    }
    .arrow-sprite-5 {
        background: no-repeat url(http://i.imgur.com/O8R881E.png) 30px -438px;
        width: 519px;
        height: 490px;
        position: absolute;
        top: 169px;
        left: 239px;
        z-index: 0;
    }
    
    .arrow-sprite:hover, .arrow-sprite-2:hover,.arrow-sprite-3:hover,.arrow-sprite-4:hover {
        filter: contrast(160%);
        transition: 0.5s ease-in;
    }
<div class="container">
<div class="row" style="text-align:center;position: relative;height: 850px;">
<div class="arrow-sprite"></div>
<div class="arrow-sprite-2"></div>
<div class="arrow-sprite-3"></div>
<div class="arrow-sprite-4"></div>
<div class="arrow-sprite-5"></div>
</div>
<div class="row">Prow scuttle parrel provost Sail ho shrouds spirits boom mizzenmast yardarm. Pinnace holystone mizzenmast quarter crow's nest nipperkin grog yardarm hempen halter furl. Swab barque interloper chantey doubloon starboard grog black jack gangway rutters.
Deadlights jack lad schooner scallywag dance the hempen jig carouser broadside cable strike colors. Bring a spring upon her cable holystone blow the man down spanker Shiver me timbers to go on account lookout wherry doubloon chase. Belay yo-ho-ho keelhaul squiffy black spot yardarm spyglass sheet transom heave to.
Trysail Sail ho Corsair red ensign hulk smartly boom jib rum gangway. Case shot Shiver me timbers gangplank crack Jennys tea cup ballast Blimey lee snow crow's nest rutters. Fluke jib scourge of the seven seas boatswain schooner gaff booty Jack Tar transom spirits.</div>
</div>

关于html - CSS Sprite 下面的空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45559421/

相关文章:

unity-game-engine - 如何统一比较两个 Sprite 纹理

css - 'filter' 属性像素化我的字体?

java - 在Android应用程序中定义位图的大小

css - 如何在完全未知的宽度上垂直对齐 div?

html - 图片未显示在 Whatsapp 链接中

php - Mysqli从表错误获取值

android - 我需要在正文中添加 href 以实现 gmail Intent 。适用于 Android 4.3,但不适用于 6/7

html - 如何内联 Bootstrap 3 进度条?

javascript - HTML5 : input type duration

python - 即使函数设置参数不移动,PygameSprites也会移出屏幕