This time I will bring you CSS to implement accordion layout. What are the precautions to implement accordion layout with CSS? . The following is a practical case, let’s take a look.
Yesterday I was working on a travel page project, and encountered such a demand during the implementation of the front-end page. It is necessary to form a group of pictures into an accordion display effect. After thinking about it carefully, I decided to use ordinary HTML+CSS to achieve this requirement. I took advantage of my free time to sort it out a little today.
Implementation principle:
Mainly uses the hover attribute of CSS. When the mouse is not moved up, all li share the width of the entire container. When the mouse moves up, hover takes effect, allowing the li tag to return to the width of the original image, and other images share the remaining width. At the same time, the transition attribute is added to produce a gradient effect.
Next, let’s experience it personally through a small demo:
HTML code:
<p> </p>
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 rendering is as follows:
The effect when the mouse is not moved up
The effect when the mouse is moved to a certain picture
This It is a very simple small demo, easy to get started, and not difficult for beginners. At the same time, I also felt the power and charm of CSS through this demo, and I hope it can bring you a little help. Finally, sort it out and make a summary of the knowledge points used in this demo:
1.hover selector
Explanation: The :hover selector is used to select the mouse pointer The element that floats above. The :hover selector can be used on all elements, not just links.
Supplement: The :link selector sets the style of links pointing to pages that have not been visited, the :visited selector is used to set links to pages that have been visited, and the :active selector is used for active links.
Extension: In the CSS definition, :hover must be located after :link and :visited (if present), so that the style can take effect.
2.Transition attribute
Explanation: Transition is a shorthand attribute of CSS3, used to set four transition attributes:
transition-property: Specifies the name of the CSS property that sets the transition effect.
transition-duration: Specifies how many seconds or milliseconds it takes to complete the transition effect.
transition-timing-function: Specifies the speed curve of the speed effect.
transition-delay: Defines when the transition effect starts.
Syntax: transition: property duration timing-function delay;
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the PHP Chinese website article!
Recommended reading:
Using html and css to implement Cornell Notes
A brief discussion on the layout of css web pages
The above is the detailed content of CSS implements accordion layout. For more information, please follow other related articles on the PHP Chinese website!

I recently found a solution to dynamically update the color of any product image. So with just one of a product, we can colorize it in different ways to show

In this week's roundup, Lighthouse sheds light on third-party scripts, insecure resources will get blocked on secure sites, and many country connection speeds

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used

The document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its

What's happening when you see some JavaScript that calls super()?.In a child class, you use super() to call its parent’s constructor and super. to access its

JavaScript has a variety of built-in popup APIs that display special UI for user interaction. Famously:

I was chatting with some front-end folks the other day about why so many companies struggle at making accessible websites. Why are accessible websites so hard

There is an HTML attribute that does exactly what you think it should do:


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.