代码之家  ›  专栏  ›  技术社区  ›  kit

按边框线分割选项,选中时隐藏

  •  0
  • kit  · 技术社区  · 8 年前

    input {
      position: absolute;
      left: -9999px;
    }
    
    input + label {
      border-right: solid 1px #000;
      padding-right: 8px;
      margin-right: 8px;
    }
    
    input:checked + label {
      display: none;
    }
    <input type="radio" id="one" name="option" checked/>
    <label for="one">One</label>
    <input type="radio" id="two" name="option" />
    <label for="two">Two</label>
    <input type="radio" id="three" name="option" />
    <label for="three">Three</label>

    有三个选项,选择该选项时,应将其隐藏,包括选项和下一个选项之间的边框线。

    例如,

    当我选择“一”时,我会看到“二|三”。

    当我选择“三”时,我应该看到“一|二”。

    它不需要单选按钮,任何其他可能的解决方案也欢迎,但我想实现这一点只使用CSS。

    1 回复  |  直到 8 年前
        1
  •  1
  •   Harley    8 年前

    尝试CSS选择器 :last-of-type . 只是,使用CSS,你可能不得不放弃最后一条边界线。

    input {
      position: absolute;
      left: -9999px;
    }
    
    /*input:first-of-type + label {
      border-right: solid 1px #000;
      padding-right: 4px;
      margin-right: 4px;
    }*/
    
    input:not(:first-of-type) + label {
      border-left: solid 1px #000;
      padding-left: 8px;
      margin-left: 8px;
    }
    
    input:checked + label {
      display: none;
    }
    
    /*label:not(:checked):last-of-type {
      border-right: none;
    }*/
    <html>
    <input type="radio" id="one" name="option" />
    <label for="one">One</label>
    <input type="radio" id="two" name="option" />
    <label for="two">Two</label>
    <input type="radio" id="three" name="option" />
    <label for="three">Three</label>
    <input type="radio" id="four" name="option" checked/>
    <label for="four">Four</label>
    <input type="radio" id="five" name="option" />
    <label for="five">Five</label>
    
    </html>