An example of a pure CSS implementation of accordion effects

Source: Internet
Author: User
This article mainly introduces the use of pure CSS to achieve the accordion effect of the sample code of the relevant data, small series feel very good, and now share to everyone, but also for everyone to do a reference. Follow the small series together to see it, hope to help everyone.

Yesterday in the project to do a travel page, the front page implementation of the process encountered such a requirement. A set of pictures needs to be formed to display the accordion effect. After serious thinking over, the decision to use the ordinary html+css can achieve this demand. Take advantage of your free time today to comb a bit.

Implementation principle:

The main use of CSS hover properties, when the mouse is not moved up, all the Li share the entire width of the container. When the mouse move up, hover effective, let the LI tag back to the original width of the image, the other graphs share the remaining width. Add the transition attribute to create a gradient effect.

Here's a little demo to get a feel for yourself:

HTML code:


<body> <p class= "contain" > <ul> <li> <a HRE f= "#" >  </a> <p clas s= "title" > <a href= "#" > Yunnan. Dali </a> </p> </l                     i> <li> <a href= "#" >  </a> <p class= "title" > <a href= "#" > Guangxi. Guilin &L t;/a> </p> </li> <li> <a href= "#" >  </a> <p class= "title" > <a href= "#" > Fujian. Xiamen </a> </p> </li&                Gt <lI> <a href= "#" >  </a                    > <p class= "title" > <a href= "#" > Zhejiang Qiandaohu </a>                        </p> </li> <li> <a href= "#" >                         </a> <p class= "title" > <a href= "#" > Changjiang River. Sanxia </a> </p> </li> </ul&gt        ; </p></body>

CSS code:


        . contain {            width:1050px;            margin:100px auto;        }                . Contain li {            float:left;            List-style:none;            width:200px;            height:284px;            Transition:all 2s;            position:relative;            Overflow:hidden;            border-left:2px Solid Rgba (255, 255, 255,. 8);            box-shadow:0px 0px 20px rgba (0, 0, 0, 0.8);        }                . Contain ul:hover li {            width:80px;        }                . Contain ul li:hover {            width:500px;        }                . Contain li. title {            Position:absolute;            width:100%;            height:50px;            Background-color:rgba (0, 0, 0,. 5);            Text-indent:2em;            line-height:50px;            bottom:0px;            left:0        }                . contain a {            color: #fff;            Text-decoration:none;        }

The implementation is as follows:

effect when the mouse is not moved up

Mouse moves to a picture effect

This is a very simple small demo, easy to get started, it is not difficult for beginners. At the same time also through this demo feel the strong and charm of CSS, hope to bring you a little help. Finally, comb, do a summary of the knowledge points used in this demo:

1.hover Selector

Explanation:: The hover selector is used to select the mouse pointer floating above the element. : The hover selector is available for all elements, not just links.

Add:: Link selector Sets the style of links to pages that have not been visited: the visited selector is used to set a link to a page that has been visited: the active selector is used for the active link.

Expansion: In the CSS definition, the hover must be located after link and: visited (if present) before the style can take effect.

2.transition Properties

Explanation: Transition is a shorthand property for CSS3 to set four transition properties:

    1. Transition-property: Specifies the name of the CSS property that sets the transition effect.

    2. Transition-duration: Specifies how many seconds or milliseconds to complete the transition effect.

    3. Transition-timing-function: Speed curve that specifies the speed effect.

    4. Transition-delay: Defines when the transition effect starts.

Syntax: transition:property duration timing-function delay;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.