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
1. Background As the project's business conti...
For some systems with large amounts of data, the ...
Preface Now the operating system used by my compa...
Table of contents Preparation Install VMware Work...
Use HTML to write a dynamic web clock. The code i...
Preface Hello everyone, this is the CSS wizard - ...
Table of contents Block-level functions Directly ...
byzhangxinxu from https://www.zhangxinxu.com/word...
In MySQL, most indexes (such as PRIMARY KEY, UNIQ...
Problem Description As we all know, when writing ...
Table of contents Dirty pages (memory pages) Why ...
Table of contents The browser's rendering mec...
There are many commands used in the system, so ho...
How to define and use: Use the slot tag definitio...
In the Linux system, in addition to various accou...