Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Clip and Absolute Positioning

I'm using clip to create thumbnails for a gallery. Unfortunately, clip can only be used when an element is absolutely positioned. Applied equally to each img, this of course makes them all sit on each other while using one CSS style, something like this.

.Thumbnails {
    position: absolute;
    height: 105px;
    clip: rect(50px 218px 155px 82px);
}

How can I then position them relative to each other? I just want basic rows.

like image 396
prestomation Avatar asked Jul 21 '09 00:07

prestomation


People also ask

What does CSS clip do?

The clip CSS property defines a visible portion of an element. The clip property applies only to absolutely positioned elements — that is, elements with position:absolute or position:fixed .

What is position Absolute CSS?

An absolutely positioned element is an element whose computed position value is absolute or fixed . The top , right , bottom , and left properties specify offsets from the edges of the element's containing block. (The containing block is the ancestor relative to which the element is positioned.)

What is absolute and relative position in CSS?

position: relative places an element relative to its current position without changing the layout around it, whereas position: absolute places an element relative to its parent's position and changing the layout around it.


2 Answers

Here are a few options:

  1. You can use the clip property to prevent the overlap and create thumbnails at the same time: http://www.cssplay.co.uk/menu/clip_gallery.html

  2. You can use negative margins to separate the images from each other, and overflow to create the thumbnails: http://cssglobe.com/post/6089/3-easy-and-fast-css-techniques-for-faux-image

like image 77
Paul Sweatte Avatar answered Sep 17 '22 17:09

Paul Sweatte


Update from 2021. CSS3 has introduced clip-path property, which provides the desired functionality - clipping any element. https://www.w3schools.com/cssref/css3_pr_clip-path.asp

like image 29
Mike Avatar answered Sep 19 '22 17:09

Mike