简体   繁体   English

仅取消选中 html 和 css 中的复选框?

[英]Uncheck checkboxes in html and css only?

I've been trying to create something similar to google images (when you click on an image it 'opens' a larger version with information and links and when you click again it closes).我一直在尝试创建类似于谷歌图片的东西(当你点击一张图片时,它会“打开”一个带有信息和链接的大版本,当你再次点击它时它会关闭)。

My task (school) is to realise this with only pure html(5) and css(3), so no javascript or JQuery or any other programming language.我的任务(学校)是只用纯 html(5) 和 css(3) 来实现这一点,所以没有 javascript 或 JQuery 或任何其他编程语言。

I already tried using checkboxes and radio.我已经尝试过使用复选框和收音机。 When I use checkboxes, it will expand an 'informationbox' which will not close when I open the next one.当我使用复选框时,它会展开一个“信息框”,当我打开下一个复选框时它不会关闭。 There only needs to be one open at a time.一次只需要打开一个。 Therefore I also tried using radio.因此我也尝试使用收音机。 The problem here is that I'm not able to deselect them.这里的问题是我无法取消选择它们。

Is it possible to realise this with only html and css?是否可以仅使用 html 和 css 来实现这一点?

Is there anyone who can help me?有谁能帮助我吗?

Thanks in advance!提前致谢!

 .folder { width: 100%; visibility: hidden; } .fold { visibility: hidden; background-color: #8b0000; width: 60%; height: 0px; color: transparent; -webkit-transition: all 0.3s; -moz-transition: all 0.3s; transition: all 0.3s; position: absolute; } .toggle { display: none; } .toggle-label { display: inline-block; cursor: pointer; margin-top: 10px; margin-bottom: 10px; border: 1px solid #fff; font-size: 11px; color: #999; background-color: #8b0000; padding: 5px; } .toggle-label:hover { background-color: #400000; } .toggle:checked ~ .fold { height: 80px; visibility: visible; color: #fff; } .content{ width: 100%; min-height: 0; position: static; -webkit-transition: all 0.3s; -moz-transition: all 0.3s; transition: all 0.3s; } .toggle:checked ~ .content { min-height: 80px; }
 <label for="toggle1" class="toggle-label">FOLD/UNFOLD</label> <label for="toggle2" class="toggle-label">FOLD/UNFOLD</label> <label for="toggle3" class="toggle-label">CLOSE</label> <div class="content"> <aside class="folder"> <input type="checkbox" name="xinfo" class="toggle" id="toggle1"/> <div class="fold">Element 1</div> </aside> <aside class="folder"> <input type="checkbox" name="xinfo" class="toggle" id="toggle2"/> <div class="fold">Element 2</div> </aside> <aside class="folder"> <input type="checkbox" name="xinfo" class="toggle" id="toggle3"/> </aside> </div>

The best solution I found till now is to use radio.到目前为止,我发现的最佳解决方案是使用收音机。 You need to use 1 extra input that has no content, so it will not show when you select it.您需要使用 1 个没有内容的额外输入,因此当您选择它时它不会显示。 This way the other ones will close.这样其他的就会关闭。

<aside class="folder">
  <input type="radio" name="xinfo" class="toggle" id="toggle3"/>
</aside>

JSFiddle example: https://jsfiddle.net/zv1pd6wn/ JSFiddle 示例: https ://jsfiddle.net/zv1pd6wn/

The only problem now is that the close button will be visible till the end of the animation, I already tried to solve it, but no luck, help is appreciated.现在唯一的问题是关闭按钮将在动画结束之前可见,我已经尝试解决它,但没有运气,感谢帮助。

Is this you want.这是你想要的吗。 kindly try below code.请尝试以下代码。

   <label for="toggle1" class="toggle-label">FOLD/UNFOLD</label>
            <label for="toggle2" class="toggle-label">FOLD/UNFOLD</label>
            <label for="toggle3" class="toggle-label">CLOSE</label>
      <input type="radio" name="xinfo" class="toggle" id="toggle3"/>

    
            <div class="content">
                <aside class="folder">
                    <input type="radio" name="xinfo" class="toggle" id="toggle1"/>
                    <div class="fold">Element 1</div>
                </aside>

                <aside class="folder">
                    <input type="radio" name="xinfo" class="toggle" id="toggle2"/>
                    <div class="fold">Element 2</div>
                </aside>
                
            </div>



   --css---

    .folder {
        width: 100%;
        visibility: hidden;
    }

    .fold {
        visibility: hidden;
        background-color: #8b0000;
        width: 60%;
        height: 0px;
        color: transparent;
        -webkit-transition: all 0.3s;
        -moz-transition: all 0.3s;
        transition: all 0.3s;
        position: absolute;
    }

    .toggle { display: none; }

    .toggle-label {
        display: inline-block;
        cursor: pointer;
        margin-top: 10px;
        margin-bottom: 10px;
        border: 1px solid #fff;
        font-size: 11px;
        color: #999;
        background-color: #8b0000;
        padding: 5px;
    }

    .toggle-label:hover {
        background-color: #400000;
    }

    .toggle:checked ~ .fold {
        height: 80px;
        visibility: visible;
        color: #fff;
    }

    .content{
        width: 100%;
        min-height: 0;
        position: static;
        -webkit-transition: all 0.3s;
        -moz-transition: all 0.3s;
        transition: all 0.3s;
    }

    .toggle:checked ~ .content {
        min-height: 80px;
    }
    
    
    #toggle3:checked + .content .fold
    {
      visibility: hidden;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM