How to create spoiler text?

后端 未结 5 2059
遇见更好的自我
遇见更好的自我 2021-02-20 04:39

Hello I was wondering how to make spoiler text on a website with html/css. What I was is, text that is black with black background, but when hovered over, makes the black text

5条回答
  •  眼角桃花
    2021-02-20 05:15

    I have been spoilers on forums (including my own) that are not just text with the background color changed.

    They have the content hidden until you click a show/hide toggle button.

    I want to add a section to a site that doesn't show up by default to save space.

    https://jsfiddle.net/clarle/bY7m4/

    That seems like it will meet my needs.

    HTML

    Show spoiler Hide spoiler

    People die when they are killed!

    CSS

    .spoiler {
      display: none;
    }
    
    .show {
      display: none; 
    }
    
    .hide:target + .show {
      display: inline; 
    }
    
    .hide:target {
      display: none; 
    }
    
    .hide:target ~ .spoiler {
      display: inline;
    }
    
    /* Just for prettiness, not actually needed */
    
    body {
      margin: 0;
      padding: 20px;
      font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
      font-size: 14px;
      line-height: 20px;
      color: #333333;
      background-color: #ffffff;
    }
    
    .btn {
      padding: 4px 12px;
      margin-bottom: 0;
      *margin-left: .3em;
      font-size: 14px;
      line-height: 20px;
      color: #333333;
      text-align: center;
      text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
      vertical-align: middle;
      cursor: pointer;
      background-color: #f5f5f5;
      *background-color: #e6e6e6;
      background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6);
      background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6));
      background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6);
      background-image: -o-linear-gradient(top, #ffffff, #e6e6e6);
      background-image: linear-gradient(to bottom, #ffffff, #e6e6e6);
      background-repeat: repeat-x;
      border: 1px solid #bbbbbb;
      *border: 0;
      border-color: #e6e6e6 #e6e6e6 #bfbfbf;
      border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
      border-bottom-color: #a2a2a2;
      -webkit-border-radius: 4px;
         -moz-border-radius: 4px;
              border-radius: 4px;
      filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe6e6e6', GradientType=0);
      filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
      *zoom: 1;
      -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
         -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
              box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
      text-decoration: none;
    }
    
    .forum-post {
      padding: 20px;
      border: 1px solid #000;
    }
    
    .spoiler-content {
      padding: 15px;
    }
    

提交回复
热议问题