Just make sure the target's closest positionned parent is the body or a fixed, full-width-and-height overlay div.

.lightbox(@width, @height, @margin) {
    position: absolute;
    top: 50%;
    left: 50%;
    width: @width;
    height: @height;
    margin: -(@height / 2) 0 0 -(@width / 2);

    @media screen and (max-width: (@width + @margin * 2)) {
        right: @margin;
        left: @margin;
        width: auto;
        margin-left: 0;
    }

    @media screen and (max-height: (@height + @margin * 2)) {
        top: @margin;
        bottom: @margin;
        height: auto;
        margin-top: 0;
    }
}