문제

Please check this page: http://www.thamon.co.uk/e-store/

The 20px right margin float leaves an epty 20px space that can't be occupied by an image. The image jumps to the second row if I try to increase the .gallery-columns-3 width at least by 0.1%.

How can I delete the margin on the last image in gallery line?

* Default WordPress Gallery
     */
    .gallery {
        float: left;
        margin-bottom: 20px; 
    }
        .gallery br {
            display: none;
        }
        .gallery .gallery-item {
            margin: 0 20px 20px 0 !important;
            width: 100%;
            float: left;
            position: relative; 
            overflow: hidden;
        }

        .gallery-columns-2 .gallery-item { 
        width: 50% !important; 
        }
        .gallery-columns-3 .gallery-item { 
            width: 31.2% !important; 
도움이 되었습니까?

해결책

I would do something like this:

.gallery {
  margin: 0 -10px;
}
.gallery-item {
  margin: 10px;
}

That way you give the items an even margin all round, which still results in a gap of 20px, and you make the edges align with your content by making the wrapper 10px larger then the content area at each side.

(have a look at you HTML, <dl> does not seem really appropriate for a gallery item)

In your code, that would look something like this:

    .gallery {
        float: left;
        /* margin-bottom: 20px; */
        margin: 0 -10px;
    }
    /*.gallery br {
        display: none;
    }*/
    .gallery .gallery-item {
        /* margin: 0 20px 20px 0 !important; */
        margin: 10px;
        width: 100%;
        float: left;
        position: relative; 
        overflow: hidden;
    }

    .gallery-columns-2 .gallery-item { 
        width: 50% !important; 
    }
    .gallery-columns-3 .gallery-item { 
        width: 31.2% !important; 

다른 팁

Use a pseudo selector

.gallery-item:last-child{margin-right:0;}

More info: https://developer.mozilla.org/en-US/docs/Web/CSS/:last-child

This should work:

.gallery-item:first-child + .gallery-item + .gallery-item
{
    margin-right: 0px;
}

The above is the as using

.gallery-item:last-child
{
    margin-right:0px;
}

but last-child doesn't work on older versions of IE, while first-child does.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top