纯CSS-几种阅读更多阅读更少 [英] Pure CSS - Several Read more Read less

查看:149
本文介绍了纯CSS-几种阅读更多阅读更少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决

请参阅以下代码段中的工作代码. 对可以使用它的人免费使用.

See working code in below snippet. Free of use to those who can use it.

说明: 有一个包装器,其中包含10个查看更多/更少"部分.所有11个均可折叠并合上.按钮具有悬停效果.文字为英文. 没有Javascript或jQuery.纯CSS/HTML解决方案.

Description: There is one wrapper which contains 10 "See more/less" sections. All 11 can be fold out and closed. Buttons have hover effect. Text are in english. No Javascript or jQuery. Pure CSS/HTML solution.

如果不需要全部十个,只需将它们从HTML中删除.无需从CSS中删除它们.

If you doesn't need all ten, simply remove them from the HTML. No need to remove them from the CSS.

由于包装纸很长,我在折叠的底部包括了一个按钮.所有部分均由水平尺划分.

As the wrapper is long I have included a button at the bottom of the fold out. All sections are divided by a horizontal ruler.

兼容于:

  • 文字<p>
  • 图片<img>
  • iframes <iframe>
  • 服务器端包含
  • Textelements <p>
  • Images <img>
  • Iframes <iframe>
  • Server Side Includes

问题

我正在尝试创建两个级别的多读/少读".

I am trying to create a two level "Read More/Read Less".

第一级应隐藏/显示和包装大量信息,例如图像,视频和文本.该信息将分为自己的阅读更多/阅读较少"部分,并在包装​​器内最多分为10个部分.

The first level shall hide/show and wrap a larger amount of information such as images, video and text. This information will be split in their own "Read More/Read Less" section and up to 10 sections in total which is inside the wrapper.

但是,我很难创建第二层,它是包装器的一部分.我相信可以用这种方法来完成,但我真的做不到.

Yet I am having a hard time creating the second level which is part of the wrapper. I believe it can be done this way but I really can't make it work.

hr {
  border: 0;
  border-bottom: 1px dashed #2E181A;
  background: #2E181A;
  width: 50%;
}

/*=============== READ MORE READ LESS ============*/
/******************** Danish **********************/
/*************** See more wrapper *****************/
/**************************************************/

.wrapper-state {
	display: none;
}

.wrapper-target {
	opacity: 0;
	height: 0;
	font-size: 0;
	transition: .25s ease;
}

.wrapper-state ~ .wrapper-wrap {
	display: none;
}

.wrapper-state:checked ~ .wrapper-wrap {
	display: block;
}

.wrapper-state:checked ~ .wrapper-wrap .wrapper-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.wrapper-state ~ .wrapper-trigger:before {
	content: 'Se mere om hingstene';
}

.wrapper-state:checked ~ .wrapper-trigger:before {
	content: 'Luk afsnit';
}

.wrapper-state ~ .wrapper-trigger2:before {
	content: 'Se mere om hingstene';
	display: none;
}

.wrapper-state:checked ~ .wrapper-trigger2:before {
	content: 'Luk afsnit';
	display: inline-block;
}

.wrapper-trigger, .wrapper-trigger2 {
	cursor: pointer;
	display: block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	text-align: center;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

.wrapper-trigger2:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

/****** See more first ******/
/*********************/

.first-state{
	display: none;
}

.wrapper-target .first-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.first-state:checked ~ .wrapper-wrap .first-wrap .first-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}


.first-state ~ .wrapper-wrap .first-trigger:before {
	content: 'Se mere';
}

.first-state:checked ~ .wrapper-wrap .first-trigger:before {
	content: 'Se mindre';
}

.first-state ~ .first-wrap {
	display: none;
}

.first-state:checked ~ .first-wrap {
	display: block;
}

.first-target img {
	height: 0;
}

.first-state:checked ~ .wrapper-wrap .first-target img {
	height: auto;
}

.first-target p {
	display: none;
}

.first-state:checked ~ .wrapper-wrap .first-target p {
	display: block;
}

.first-target iframe {
	height: 0;
}

.first-state:checked ~ .wrapper-wrap .first-target iframe {
	height: 100%;
}

.wrapper-wrap .first-trigger {
	cursor: pointer;
	display: inline-block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-wrap .first-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

/****** See more second ******/
/*********************/

.second-state{
	display: none;
}

.wrapper-target .second-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.second-state:checked ~ .wrapper-wrap .second-wrap .second-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.second-state ~ .wrapper-wrap .second-trigger:before {
	content: 'Se mere';
}

.second-state:checked ~ .wrapper-wrap .second-trigger:before {
	content: 'Se mindre';
}

.second-target img {
	height: 0;
}

.second-state:checked ~ .wrapper-wrap .second-target img {
	height: auto;
}

.second-target p {
	display: none;
}

.second-state:checked ~ .wrapper-wrap .second-target p {
	display: block;
}

.second-target iframe {
	height: 0;
}

.second-state:checked ~ .wrapper-wrap .second-target iframe {
	height: 100%;
}

.wrapper-wrap .second-trigger {
	cursor: pointer;
	display: inline-block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-wrap .second-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

/****** See more third ******/
/*********************/

.third-state{
	display: none;
}

.wrapper-target .third-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.third-state:checked ~ .wrapper-wrap .third-wrap .third-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.third-state ~ .wrapper-wrap .third-trigger:before {
	content: 'Se mere';
}

.third-state:checked ~ .wrapper-wrap .third-trigger:before {
	content: 'Se mindre';
}

.third-target img {
	height: 0;
}

.third-state:checked ~ .wrapper-wrap .third-target img {
	height: auto;
}

.third-target p {
	display: none;
}

.third-state:checked ~ .wrapper-wrap .third-target p {
	display: block;
}

.third-target iframe {
		height: 0;
}

.third-state:checked ~ .wrapper-wrap .third-target iframe {
	height: 100%;
}

.wrapper-wrap .third-trigger {
	cursor: pointer;
	display: inline-block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-wrap .third-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

/****** See more fourth ******/
/*********************/

.fourth-state{
	display: none;
}

.wrapper-target .fourth-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.fourth-state:checked ~ .wrapper-wrap .fourth-wrap .fourth-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.fourth-state ~ .wrapper-wrap .fourth-trigger:before {
	content: 'Se mere';
}

.fourth-state:checked ~ .wrapper-wrap .fourth-trigger:before {
	content: 'Se mindre';
}

.fourth-target img {
	height: 0;
}

.fourth-state:checked ~ .wrapper-wrap .fourth-target img {
	height: auto;
}

.fourth-target p {
	display: none;
}

.fourth-state:checked ~ .wrapper-wrap .fourth-target p {
	display: block;
}

.fourth-target iframe {
	height: 0;
}

.fourth-state:checked ~ .wrapper-wrap .fourth-target iframe {
	height: 100%;
}

.wrapper-wrap .fourth-trigger {
  cursor: pointer;
  display: inline-block;
  padding: 0 .5em;
  background-color:#2E181A;
  color: #E6D9BD;
  font-size: .9em;
  line-height: 2;
  border: 1px solid #E6D9BD;
  border-radius: 0.5em;
}

.wrapper-wrap .fourth-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

/****** See more fifth ******/
/*********************/

.fifth-state{
	display: none;
}

.wrapper-target .fifth-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.fifth-state:checked ~ .wrapper-wrap .fifth-wrap .fifth-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.fifth-state ~ .wrapper-wrap .fifth-trigger:before {
	content: 'Se mere';
}

.fifth-state:checked ~ .wrapper-wrap .fifth-trigger:before {
	content: 'Se mindre';
}

.fifth-target img {
	height: 0;
}

.fifth-state:checked ~ .wrapper-wrap .fifth-target img {
	height: auto;
}

.fifth-target p {
	display: none;
}

.fifth-state:checked ~ .wrapper-wrap .fifth-target p {
	display: block;
}

.fifth-target iframe {
	height: 0;
}

.fifth-state:checked ~ .wrapper-wrap .fifth-target iframe {
	height: 100%;
}

.wrapper-wrap .fifth-trigger {
	cursor: pointer;
	display: inline-block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-wrap .fifth-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

/****** See more sixth ******/
/*********************/

.sixth-state{
	display: none;
}

.wrapper-target .sixth-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.sixth-state:checked ~ .wrapper-wrap .sixth-wrap .sixth-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.sixth-state ~ .wrapper-wrap .sixth-trigger:before {
	content: 'Se mere';
}

.sixth-state:checked ~ .wrapper-wrap .sixth-trigger:before {
	content: 'Se mindre';
}

.sixth-target img {
	height: 0;
}

.sixth-state:checked ~ .wrapper-wrap .sixth-target img {
	height: auto;
}

.sixth-target p {
	display: none;
}

.sixth-state:checked ~ .wrapper-wrap .sixth-target p {
	display: block;
}

.sixth-target iframe {
	height: 0;
}

.sixth-state:checked ~ .wrapper-wrap .sixth-target iframe {
	height: 100%;
}

.wrapper-wrap .sixth-trigger {
	cursor: pointer;
	display: inline-block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-wrap .sixth-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

/****** See more seventh ******/
/*********************/

.seventh-state{
	display: none;
}

.wrapper-target .seventh-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.seventh-state:checked ~ .wrapper-wrap .seventh-wrap .seventh-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.seventh-state ~ .wrapper-wrap .seventh-trigger:before {
	content: 'Se mere';
}

.seventh-state:checked ~ .wrapper-wrap .seventh-trigger:before {
	content: 'Se mindre';
}

.seventh-target img {
	height: 0;
}

.seventh-state:checked ~ .wrapper-wrap .seventh-target img {
	height: auto;
}

.seventh-target p {
	display: none;
}

.seventh-state:checked ~ .wrapper-wrap .seventh-target p {
	display: block;
}

.seventh-target iframe {
	height: 0;
}

.seventh-state:checked ~ .wrapper-wrap .seventh-target iframe {
	height: 100%;
}

.wrapper-wrap .seventh-trigger {
	cursor: pointer;
	display: inline-block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-wrap .seventh-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

/****** See more eight ******/
/*********************/

.eight-state{
	display: none;
}

.wrapper-target .eight-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.eight-state:checked ~ .wrapper-wrap .eight-wrap .eight-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.eight-state ~ .wrapper-wrap .eight-trigger:before {
	content: 'Se mere';
}

.eight-state:checked ~ .wrapper-wrap .eight-trigger:before {
	content: 'Se mindre';
}

.eight-target img {
	height: 0;
}

.eight-state:checked ~ .wrapper-wrap .eight-target img {
	height: auto;
}

.eight-target p {
	display: none;
}

.eight-state:checked ~ .wrapper-wrap .eight-target p {
	display: block;
}

.eight-target iframe {
	height: 0;
}

.eight-state:checked ~ .wrapper-wrap .eight-target iframe {
	height: 100%;
}

.wrapper-wrap .eight-trigger {
	cursor: pointer;
	display: inline-block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-wrap .eight-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

/****** See more nine ******/
/*********************/

.nine-state{
	display: none;
}

.wrapper-target .nine-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.nine-state:checked ~ .wrapper-wrap .nine-wrap .nine-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.nine-state ~ .wrapper-wrap .nine-trigger:before {
	content: 'Se mere';
}

.nine-state:checked ~ .wrapper-wrap .nine-trigger:before {
	content: 'Se mindre';
}

.nine-target img {
	height: 0;
}

.nine-state:checked ~ .wrapper-wrap .nine-target img {
	height: auto;
}

.nine-target p {
	display: none;
}

.nine-state:checked ~ .wrapper-wrap .nine-target p {
	display: block;
}

.nine-target iframe {
	height: 0;
}

.nine-state:checked ~ .wrapper-wrap .nine-target iframe {
	height: 100%;
}

.wrapper-wrap .nine-trigger {
	cursor: pointer;
	display: inline-block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-wrap .nine-trigger:hover {
		border: 1px solid #2E181A;
		background-color: #E6D9BD;
		opacity: 1;
		color:#2E181A;
}

/****** See more ten ******/
/*********************/

.ten-state{
	display: none;
}

.wrapper-target .ten-target {
	opacity: 0;
	max-height: 0;
	font-size: 0;
	transition: .25s ease;
}

.ten-state:checked ~ .wrapper-wrap .ten-wrap .ten-target {
	opacity: 1;
	font-size: inherit;
	max-height: 999em;
}

.ten-state ~ .wrapper-wrap .ten-trigger:before {
	content: 'Se mere';
}

.ten-state:checked ~ .wrapper-wrap .ten-trigger:before {
	content: 'Se mindre';
}

.ten-target img {
	height: 0;
}

.ten-state:checked ~ .wrapper-wrap .ten-target img {
	height: auto;
}

.ten-target p {
	display: none;
}

.ten-state:checked ~ .wrapper-wrap .ten-target p {
	display: block;
}

.ten-target iframe {
	height: 0;
}

.ten-state:checked ~ .wrapper-wrap .ten-target iframe {
	height: 100%;
}

.wrapper-wrap .ten-trigger {
	cursor: pointer;
	display: inline-block;
	padding: 0 .5em;
	background-color:#2E181A;
	color: #E6D9BD;
	font-size: .9em;
	line-height: 2;
	border: 1px solid #E6D9BD;
	border-radius: 0.5em;
}

.wrapper-wrap .ten-trigger:hover {
	border: 1px solid #2E181A;
	background-color: #E6D9BD;
	opacity: 1;
	color:#2E181A;
}

<input type="checkbox" class="wrapper-state" id="post-wrap" />
<input type="checkbox" class="first-state" id="post-1" />
<input type="checkbox" class="second-state" id="post-2" />
<input type="checkbox" class="third-state" id="post-3" />
<input type="checkbox" class="fourth-state" id="post-4" />
<input type="checkbox" class="fifth-state" id="post-5" />
<input type="checkbox" class="sixth-state" id="post-6" />
<input type="checkbox" class="seventh-state" id="post-7" />
<input type="checkbox" class="eight-state" id="post-8" />
<input type="checkbox" class="nine-state" id="post-9" />
<input type="checkbox" class="ten-state" id="post-10" />

<p>What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
  specimen book.</p>

<hr />

<label for="post-wrap" class="wrapper-trigger"></label>

<div class="wrapper-wrap">
  <span class="wrapper-target">

<div class="first-wrap">
<span class="first-target">
<p>It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</span>
</div>
<label for="post-1" class="first-trigger"></label>

<hr />

<div class="second-wrap">
  <span class="second-target">
<h3>Why do we use it?</h3>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.</p>
</span>
</div>
<label for="post-2" class="second-trigger"></label>

<hr />

<div class="third-wrap">
  <span class="third-target">
<p>Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
</span>
</div>
<label for="post-3" class="third-trigger"></label>

<hr />

<div class="fourth-wrap">
  <span class="fourth-target">
<img src="https://images.pexels.com/photos/67636/rose-blue-flower-rose-blooms-67636.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" height="auto" width="250px" />
</span>
</div>
<label for="post-4" class="fourth-trigger"></label>

<hr />

<div class="fifth-wrap">

  <span class="fifth-target">
<iframe src="https://www.youtube.com/embed/vNJnOfyhweo" frameborder="0" tabindex="-1" allowfullscreen></iframe>
</span>
</div>
<label for="post-5" class="fifth-trigger"></label>

<hr />

<div class="sixth-wrap">
  <span class="sixth-target">
<h1>Where does it come from?</h1>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.</p>
</span>
</div>
<label for="post-6" class="sixth-trigger"></label>

<hr />

<div class="seventh-wrap">

  <span class="seventh-target">
<p>Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
</span>
</div>
<label for="post-7" class="seventh-trigger"></label>

<hr />

<div class="eight-wrap">
  <span class="eight-target">
<p>The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
</span>
</div>
<label for="post-8" class="eight-trigger"></label>

<hr />

<div class="nine-wrap">

  <span class="nine-target">
<p>The nine riders......</p>
</span>
</div>
<label for="post-9" class="nine-trigger"></label>

<hr />

<div class="ten-wrap">
  <span class="ten-target">
<p>OMFG... Finally at the end!</p>
</span>
</div>
<label for="post-10" class="ten-trigger"></label>

<hr />
</span>
</div>
<label for="post-wrap" class="wrapper-trigger2"></label>
<div class="clearer"></div>

推荐答案

当我问我的问题时,我一直在致力于解决方案.

As I asked my question I kept on working on the solution.

请找到有问题的代码段作为有效的解决方案.

Please find snippet in question as the working solution.

这篇关于纯CSS-几种阅读更多阅读更少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆