📜 ⬆️ ⬇️

Creating an image preview on the main Overflow properties

At the request of users after reading the article Visualization of data on CSS

The goal of this article is to make it possible to create a preview for an image, the dimensions of which can be set independently. It so happens that we do not have free space on the page to show the preview of the image completely. But I do not want to make cropping from pictures. The trick given in the article will allow us to create the preview sizes we need and display its full size when you hover the cursor over the preview.

Introduction
In fact, we will not manage the image size, but the size of the scope when you hover over the image. Naturally, the overflow property will help us to realize this.
This property determines how the content of the element will be displayed when it covers the area of ​​the block containing it. If, for one reason or another, the size of this block is limited, then we use the overflow property to determine the behavior of its contents. Possible overflow values ​​are:
visible (visible), hidden (invisible), scroll , auto .
The first two combinations are enough to realize our idea.

In principle, we will do the following: hide a part of the full preview of the image when it is not involved, and show it completely when the cursor is hovering.
')
Implementation
The basic idea is to put an image in a specific block. Because we are talking about the preview, then this element will serve as an element . ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


  • . ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


    , , .

    , :
    ul#thumbs a{
    display:block;
    float:left;
    width:100px;
    height:100px;
    line-height:100px;
    overflow:hidden;
    position:relative;
    z-index:1;
    }
    ul#thumbs a img{
    float:left;
    position:absolute;
    top:-20px;
    left:-50px;
    }

    , . overflow hidden . top left , «» . .
    ul#thumbs a img{
    float:left;
    position:absolute;
    top:-20px;
    left:-50px;
    }
    ul#thumbs li#image1 a img{
    top:-28px;
    left:-55px;
    }
    ul#thumbs li#image2 a img{
    top:-18px;
    left:-48px;
    }
    ul#thumbs li#image3 a img{
    top:-21px;
    left:-30px;
    }
    .
    .
    .

    visible , .
    ul#thumbs a:hover{
    overflow:visible;
    z-index:1000;
    border:none;
    }

    , z-index , . , .. , . , .



    , , , . . , «» , , :

    width1 – ,
    width2 – , ( ul#thumbs a )
    padding – , , .

    left :
    Value = (width1 - width2) / 2 + padding top , width height

    , ul#thumbs a:hover :
    left: -1px; ( border..)
    top: -1px;

    .


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.
visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}
, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;
.


. ( ) , relative . , left top, «» . overflow hidden , , . . a:hover : overflow: visible; .


, , .

, :
ul#thumbs a{
display:block;
float:left;
width:100px;
height:100px;
line-height:100px;
overflow:hidden;
position:relative;
z-index:1;
}
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}

, . overflow hidden . top left , «» . .
ul#thumbs a img{
float:left;
position:absolute;
top:-20px;
left:-50px;
}
ul#thumbs li#image1 a img{
top:-28px;
left:-55px;
}
ul#thumbs li#image2 a img{
top:-18px;
left:-48px;
}
ul#thumbs li#image3 a img{
top:-21px;
left:-30px;
}
.
.
.

visible , .
ul#thumbs a:hover{
overflow:visible;
z-index:1000;
border:none;
}

, z-index , . , .. , . , .



, , , . . , «» , , :

width1 – ,
width2 – , ( ul#thumbs a )
padding – , , .

left :
Value = (width1 - width2) / 2 + padding top , width height

, ul#thumbs a:hover :
left: -1px; ( border..)
top: -1px;

.


Source: https://habr.com/ru/post/31455/


All Articles