CSS Picture


Release date:2024-01-18 Update date:2024-01-18 Editor:admin View counts:72

Label:

CSS Picture

This section will show you how to use CSS to lay out pictures.

Rounded corner picture

Example

Fillet picture:

img{
    border-radius:8px;
}

Example

Oval picture:

img{
    border-radius:50%;
}

Thumbnail image

We use border property to create a thumbnail.

Example

img{
    border:1px solid #ddd;
    border-radius:4px;
    padding:5px;
}
<img src="paris.jpg" alt="Paris">

Example

a{
    display:inline-block;
    border:1px solid #ddd;
    border-radius:4px;
    padding:5px;
    transition:0.3s;
}
a:hover{
    box-shadow:0 0 2px 1px rgba
    (0, 140, 186, 0.5);
}
<a href="paris.jpg">
  <img src="paris.jpg" alt="Paris">
</a>

Responsive picture

Responsive pictures automatically adapt to screens of all sizes.

In the example, you can view the effect by resizing the browser:

Image0

If you need to zoom the picture freely and the size of the picture is not larger than its original maximum, you can use the following code:

Example

img{
    max-width:100%;
    height:auto;
}

Tip: Web responsive design can refer to the CSS responsive design tutorial for more information.

Picture text

How to locate the picture text:

Example

Image0

Lower left corner

Upper left corner

Upper right corner

Lower right corner

In the middle

Card picture

Example

div.polaroid{
    width:80%;
    background-color:white;
    box-shadow:0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0,
0, 0.19);
}
img{width:100%}
div.container{
    text-align:center;
    padding:10px 20px;
}

Picture filter

CSS filter attributes are used to add visual effects to elements (for example, blur and saturation).

Note: this attribute is not supported by Internet Explorer or Safari 5.1 (and earlier).

Example

Change the color of all pictures to black and white (100% grayscale):

img{
    -webkit-filter:grayscale(100%); /\* Chrome, Safari, Opera \*/
    filter:grayscale(100%);
}

Tip: visit the CSS filter reference manual for more information.

Responsive photo album

Example

.responsive{
    padding:0 6px;
    float:left;
    width:24.99999%;
}
@media only screen and (max-width: 700px){
    .responsive{
        width:49.99999%;
        margin:6px 0;
    }
}
@media only screen and (max-width: 500px){
    .responsive{
        width:100%;
    }
}

Powered by TorCMS (https://github.com/bukun/TorCMS).