Table of Contents
HTML
CSS
 :before element
Art Border
HTML5Gallery" > HTML5Gallery
Home Web Front-end H5 Tutorial HTML5 practice-code sharing for using css to decorate image galleries (2)

HTML5 practice-code sharing for using css to decorate image galleries (2)

Mar 23, 2017 pm 03:43 PM

In the previous lecture, our solution used jquery to create a span tag. In this lecture we will use a better solution, using :before and :after Pseudo-classes. :before is often used to add additional elements.

HTML

The following is a picture gallery represented by a ul list.

<ul class="gallery clip">
    <li>
        <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-1.jpg" alt="image">
    </li>
    <li>
        <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-2.jpg" alt="image">
    </li>
    <li>
        <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-1.jpg" alt="image">
    </li></ul>
Copy after login

CSS

The following is the css set for .gallery. One thing to note here is that we need to set position: relative for the a tag under .gallery.

.gallery {
    margin: 0 0 25px;
    text-align: center;
}.gallery li {
    display: inline-block;
    margin: 5px;
    list-style: none;
}.gallery a {
    position: relative;
    display: inline-block;
}
Copy after login

 :before element

We will specify a 30 x 60px paperclip background image for the :before element. Notice that I set the css content attribute to a null value. Without an empty content attribute, the container will not be displayed.


.clip a:before {
    position: absolute;
    content: &#39; &#39;;
    top: -5px;
    left: -4px;
    width: 30px;
    height: 60px;
    background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/paper-clip.png) no-repeat;
}
Copy after login

Art Border

Using this technique, you can add any masking effect to the image. In the example below, I changed the image background to an artistic border.

.frame a:before {
    position: absolute;
    content: &#39; &#39;;
    top: -22px;
    left: -23px;
    width: 216px;
    height: 166px;
    background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/frame.png) no-repeat;
}
Copy after login

We can use html5 tags to create more advanced galleries. In the following example, we use

to wrap the image, and
to contain the image title.

##

<ul class="gallery tape">
    <li>
        <figure> 
            <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-4.jpg" alt="image">
            <figcaption>Image Caption</figcaption>
        </figure>
    </li>
    <li>
        <figure>
            <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-5.jpg" alt="image">
            <figcaption>Image Caption</figcaption>
        </figure>
    </li>
    <li>
        <figure> <img src="http://webdesignerwall.com/wp-content/uploads/2012/09/sample-6.jpg" alt="image">
            <figcaption>Image Caption</figcaption>
        </figure>
    </li></ul>
Copy after login

CSS

I added two: before in css, one for the
element and the other for the
  • element. The mask image overlay.png is used on figure:before, and the tape image is used on a:before.


    .tape li {
        width: 170px;
        padding: 5px;
        margin: 15px 10px;
        border: solid 1px #cac09f;
        background: #fdf8e4;
        text-align: center;
        box-shadow: inset 0 1px rgba(255,255,255,.8), 0 1px 2px rgba(0,0,0,.2);
    }.tape figure {
        position: relative;
        margin: 0;
    }.tape a:before {
        position: absolute;
        content: &#39; &#39;;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/overlay.png) no-repeat;
    }.tape figcaption {
        font: 100%/120% Handlee, Arial, Helvetica, sans-serif;
        color: #787568;
    }.tape a:before {
        position: absolute;
        z-index: 2;
        content: &#39; &#39;;
        top: -12px;
        left: 50%;
        width: 115px;
        height: 32px;
        margin-left: -57px;
        background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/tape.png) no-repeat;
    }
    Copy after login

    CSS3 Transform

    In this example, I used a cork texture background and transformed it using the transform attribute picture.

    .transform {
        background: url(http://webdesignerwall.com/wp-content/uploads/2012/09/cork-bg.png);
        padding: 25px;
        border-radius: 10px;
        box-shadow: inset 0 1px 5px rgba(0,0,0,.4);
    }.transform li {
        border: none;
    }
    Copy after login

     Nth-of-Type

    In order to make the image rotation more random and natural, I use nth-of-type to filter the images and set different rotation angles for different images.


    .transform li:nth-of-type(4n+1) {
        -webkit-transform: rotate(2deg);
    }.transform li:nth-of-type(2n) {
        -webkit-transform: rotate(-1deg);
    }.transform li:nth-of-type(4n+3) {
        -webkit-transform: rotate(2deg);
    }
    Copy after login
    Okay, that’s it for today’s tutorial.

    The above is the detailed content of HTML5 practice-code sharing for using css to decorate image galleries (2). For more information, please follow other related articles on the PHP Chinese website!

  • Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

    Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

    The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

    HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

    Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

    WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

    How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

    To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

    How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

    There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

    How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

    There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

    What Does H5 Refer To? Exploring the Context What Does H5 Refer To? Exploring the Context Apr 12, 2025 am 12:03 AM

    H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

    How to use bootstrap button How to use bootstrap button Apr 07, 2025 pm 03:09 PM

    How to use the Bootstrap button? Introduce Bootstrap CSS to create button elements and add Bootstrap button class to add button text

    See all articles