简体   繁体   English

CSS Transition Accordion Radio无法使用高度:auto或max-height(已编辑)

[英]CSS Transition Accordion Radio Doesn't work using height: auto or max-height (Edited)

Using radio buttons to trigger hidden/shown accordion menu. 使用单选按钮触发隐藏/显示的手风琴菜单。 Works in jsfiddle... Does not work in any other browser I've tried. 在jsfiddle中可以使用...在我尝试过的任何其他浏览器中都无法使用。 I'm assuming its something small I've miss typed or am missing or I'm totally lost. 我假设它有点小,我想念打字或想念,或者我完全迷失了。 I'm aware not everything works right in all browsers/setups/etc but from what I've read/understood this work? 我知道并非所有功能都可以在所有浏览器/设置/等中正常运行,但是从我所读/理解的工作原理来看,这是正确的吗?

EDIT: max-height does not work in jsfiddle either... So this must be the problem. 编辑:max-height在jsfiddle中也不起作用...所以这一定是问题所在。 Basically I want the ul to auto expand to the length of it's li list. 基本上,我希望ul自动扩展到li列表的长度。 So using a fixed height will not work. 因此,使用固定高度将不起作用。 height: auto; 高度:自动; as well as max-height; 以及最大高度; neither work.. 都不行..

Any and all help is appreciated it. 任何和所有帮助,我们感激不尽。

HTML 的HTML

<section class="container">
<div>
    <input id="test1" name="acctest" type="radio" checked />
    <label for="test1">About us</label>
    <ul>
        <li>test</li>
        <li>test2</li>
    </ul>
</div>
<div>
    <input id="test2" name="acctest" type="radio" />
    <label for="test2">About us</label>
    <ul>
        <li>test</li>
        <li>test2</li>
    </ul>
</div>

CSS 的CSS

.container ul{
background: rgba(255, 255, 255, 0.5);
margin: 0px;
overflow: hidden;
height: 0px;
position: relative;
    margin: 0;
z-index: 1;
    -webkit-transition: height 0.5s ease-in-out, box-shadow 0.9s linear;
    -moz-transition: height 0.5s ease-in-out, box-shadow 0.9s linear;
    -o-transition: height 0.5s ease-in-out, box-shadow 0.9s linear;
    -ms-transition: height 0.5s ease-in-out, box-shadow 0.9s linear;
    transition: height 0.5s ease-in-out, box-shadow 0.9s linear;}
.container li{
    height: 25px;
    color: #000;
    font-size: 12px;}
.container input:checked ~ ul{
    -webkit-transition: height 0.5s ease-in-out, box-shadow 0.9s linear;
    -moz-transition: height 0.5s ease-in-out, box-shadow 0.9s linear;
    -o-transition: height 0.5s ease-in-out, box-shadow 0.9s linear;
    -ms-transition: height 0.5s ease-in-out, box-shadow 0.9s linear;
    transition: height 0.5s ease-in-out, box-shadow 0.9s linear;
    max-height: 50px;}

UPDATED jsfiddle link: http://jsfiddle.net/ETaXr/2/ 更新的jsfiddle链接: http : //jsfiddle.net/ETaXr/2/

Thanks again! 再次感谢!

So I found CSS transition auto height not working (click that title for the link) 所以我发现CSS过渡自动高度不起作用 (单击该标题以获取链接)

props to Christofer Vilander for the answer and fiddle link. 克里斯托弗·维兰德(Christofer Vilander)的道具,以作为答案和小提琴的联系

I edited the fiddle over to radio buttons (the demo used checkboxes) and changed some of the class/id names... and it works... It seems I needed to define the UL more than I did. 我将小提琴编辑为单选按钮(演示使用复选框),并更改了一些类/ ID名称...并且它可以工作...似乎我需要比我定义UL多得多。

http://jsfiddle.net/3WK9Y/11/ http://jsfiddle.net/3WK9Y/11/

<div class="ac-container">
<div>

    <input id="ac-1" name="accordion-1" type="radio" checked/>
    <ul class="ac-small">
        <li>Some content</li>
    </ul>
    <label for="ac-1">About us</label>

</div>    

<div>    
    <input id="ac-2" name="accordion-1" type="radio" />
    <ul class="ac-small">
        <li>Some more content</li>
        <li>test</li>
    </ul>
    <label for="ac-2">About us</label>
</div>
</div>

see the fiddle for the css plz... its much longer and more detailed. 看到CSS PLZ的小提琴...它的更长更详细。

I manage to put something together from bits and peaces from both Christofer and Elementalsin on the subject. 我设法将Christofer和Elementalsin的点点滴滴放在一起。 See fiddle for a better understanding of the css3 involved. 请参阅小提琴以更好地了解所涉及的css3。 This modification works a lot better because the above example could only close an item after clicking a second one. 此修改效果更好,因为上面的示例只能在单击第二个项目后关闭它。 Here you can toggle them. 在这里您可以切换它们。

<div class="css3-acc">
<input id="css3-acc-def" type="radio" name="ccs3-acc-grp" checked="checked" />

<label>
  <input class="inner" type="radio" name="ccs3-acc-grp" />
  <h3>Item 1</h3>
  <label for="css3-acc-def"></label>
  <ul>
    <li><a href="#">Sub nav</a></li>
    <li><a href="#">Sub nav</a></li>
    <li><a href="#">Sub nav</a></li>
    <li><a href="#">Sub nav</a></li>
  </ul>
</label>   

</div>

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

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