Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 纯CSS-多读/少读图像_Html_Css_Hide_Show_Show Hide - Fatal编程技术网

Html 纯CSS-多读/少读图像

Html 纯CSS-多读/少读图像,html,css,hide,show,show-hide,Html,Css,Hide,Show,Show Hide,在我寻找一个整洁、漂亮、实用的“多读/少读”函数时,我设法找到了下面的代码。这段代码运行良好,可以在同一页面上多次使用(我真正需要的) 这段代码有一个反斜杠。我还需要显示/隐藏一些图像,这段代码将隐藏,但“显示更多/更少”-按钮将根据图像的大小移动,这实际上不是我需要的 我看不出如何修改此代码,以便它也可以隐藏图像 可以在这个JSFIDLE中看到问题: CSS .read-more-state { display: none; } .read-more-target { opacity

在我寻找一个整洁、漂亮、实用的“多读/少读”函数时,我设法找到了下面的代码。这段代码运行良好,可以在同一页面上多次使用(我真正需要的)

这段代码有一个反斜杠。我还需要显示/隐藏一些图像,这段代码将隐藏,但“显示更多/更少”-按钮将根据图像的大小移动,这实际上不是我需要的

我看不出如何修改此代码,以便它也可以隐藏图像

可以在这个JSFIDLE中看到问题:

CSS

.read-more-state {
  display: none;
}

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

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

.read-more-state ~ .read-more-trigger:before {
  content: 'Show more';
}

.read-more-state:checked ~ .read-more-trigger:before {
  content: 'Show less';
}

.read-more-trigger {
  cursor: pointer;
  display: inline-block;
  padding: 0 .5em;
  color: #666;
  font-size: .9em;
  line-height: 2;
  border: 1px solid #ddd;
  border-radius: .25em;
}
HTML

<input type="checkbox" class="read-more-state" id="post-1" />
<div class="read-more-wrap">
  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. 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.
  <span class="read-more-target">Why do we use it?
<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. 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>
<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" />

<p>Where does it come from?
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. 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>

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.</span></div>
<label for="post-1" class="read-more-trigger"></label>
完整代码:

.read-more-state {
  display: none;
}

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

.read-more-target img {
  height: 0;
}

.read-more-state:checked ~ .read-more-wrap .read-more-target img {
  height: auto;
}

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

.read-more-state ~ .read-more-trigger:before {
  content: 'Show more';
}

.read-more-state:checked ~ .read-more-trigger:before {
  content: 'Show less';
}

.read-more-trigger {
  cursor: pointer;
  display: inline-block;
  padding: 0 .5em;
  color: #666;
  font-size: .9em;
  line-height: 2;
  border: 1px solid #ddd;
  border-radius: .25em;
}

应该能够对
内所有图像的高度使用相同的想法。阅读更多目标

大概是这样的:

.read-more-target img {
  height: 0;
}

.read-more-state:checked ~ .read-more-wrap .read-more-target img {
  height: auto;
}

这里有一个对你的小提琴的编辑,可以做到这一点:

应该能够对
内所有图像的高度使用相同的想法。阅读更多目标

大概是这样的:

.read-more-target img {
  height: 0;
}

.read-more-state:checked ~ .read-more-wrap .read-more-target img {
  height: auto;
}

这里有一个对您的小提琴的编辑,它可以执行以下操作:

事件如果图像的容器设置为
不透明度:0
,则图像仍将占据文档流中的空间

这是一个解决方案,您可以添加以下规则:

.read-more-state ~ .read-more-wrap img {
     display: none;
}

 .read-more-state:checked ~ .read-more-wrap img {
     display: block;
}
这将确保在“读取更多”状态关闭时,图像不会占用任何空间


事件如果图像容器设置为
不透明度:0
,则图像仍将占据文档流中的空间

这是一个解决方案,您可以添加以下规则:

.read-more-state ~ .read-more-wrap img {
     display: none;
}

 .read-more-state:checked ~ .read-more-wrap img {
     display: block;
}
这将确保在“读取更多”状态关闭时,图像不会占用任何空间


使用“高度”可能比使用“显示:无”更有意义,因为使用“显示:无”时,图像会立即弹出或消失。对于高度,使用了漂亮的过渡值。这个值也可以正常工作,但我希望保持漂亮的过渡。谢谢你的回答。使用高度可能比使用
display:none
更有意义,因为使用
display:none
时,图像会立即出现或消失。对于高度,使用了漂亮的过渡值。这个值也可以正常工作,但我希望保持漂亮的过渡。谢谢你的回答。