Note When developing an article display list interface, you may want to display part of the article header content to provide a basic overview of the information, and display a button that says The idea of pure CSS in the article caibaojian.com/css-tonggle… was referred to. However, the content described in the article is applicable to the effect of a single article, and it is not friendly when using <div> <ul id="content-ul"> <!-- This is the body of the LI tag that stores the article content--> </ul> </div> [id^="contTab"] { display: none; } .content-more { display: none; } [id^="contTab"]:checked ~ #content { max-height: 95px; overflow: hidden; } [id^="contTab"]:checked ~ .content-more { display: block; position: relative; text-align: center; } [id^="contTab"]:checked ~ .content-more .gradient { background-image: -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 0)), to(#fff)); background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, 0), #fff); background-image: linear-gradient(-180deg, rgba(255, 255, 255, 0), #fff); height: 80px; position: absolute; left: 0; top: -79px; width: 100%; } [id^="contTab"]:checked ~ .content-more .readmore { display: inline-block; background: #319a1717; color: #0014ff9e; width: 300px; height: 30px; border-radius: 32px; line-height: 32px; font-size: 14px; cursor: pointer; text-indent: 0; } Of course, here is a piece of JS code: function inner(response) { for (var val of response.data) { document.getElementById('content-ul').innerHTML += '' + '<li>' + '<h2 class="title">' + val.title + '</h2>' + '<p class="update_author">' + val.author_name + ' / ' + layui.util.toDateString(val.update, "yyyy-MM-dd HH:mm:ss") + '</p>' + '<input type="checkbox" id="contTab_' + val.id + '" checked="checked" class="tabbed">' + '<div id="content">' + val.content + '</div>' + '<div class="content-more"><div class="gradient"></div> <label for="contTab_' + val.id + '" class="readmore">Click to read the full text</label></div>' + '</li>' } } illustrate The improvement method is to dynamically generate and bind the bound tag ID attribute, and then use the CSS selector, using a fuzzy matching method that is not limited to a specific ID selector. Source code This code snippet is used in the M&OAS project. You can click here to view the relevant code information and get a more complete code. PS: If you find that there is no relevant code block after entering, don't panic, maybe I haven't uploaded it to GITHU yet, please forgive me QAQ ~ The brain is a good thing, hahahaha~ This is the end of this article about how to implement the [click to expand and read full text] function with pure CSS. For more relevant CSS click to expand and read full text content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: Build a severe weather real-time warning system with Node.JS
>>: Solution to "No such file or directory" in locale after installing glibc-2.14 in CentOS6.5
Grid layout Attributes added to the parent elemen...
MySQL is easy to install, fast and has rich funct...
MySQL full text search Chinese solution Recently,...
Table of contents Proxy forwarding rules The firs...
by Take the effect shown in the picture as an exa...
Today I experimented with the network settings un...
Written in front Weibo components are component p...
This article shares the specific code of JS+AJAX ...
RocketMQ is a distributed, queue-based messaging ...
Now many mobile phones have the function of switc...
This article shares the specific code of jQuery t...
Because the data binding mechanism of Vue and oth...
Effect screenshots: Implementation code: Copy code...
Table of contents Too long to read Component styl...
Batch replace part of the data of a field in MYSQ...