首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多个CSS3元件上的垂直手风琴

多个CSS3元件上的垂直手风琴
EN

Stack Overflow用户
提问于 2013-06-26 16:01:05
回答 1查看 376关注 0票数 1

我创建了一个带有手风琴式转换的导航菜单,它是用CSS3制作的.我对此很满意,效果很好。这里是我编写的代码的实时版本:http://codepen.io/anon/pen/EJoxr

我想通过添加一个新特性来改进它:我想弹出我点击的div的文章,但也弹出了之前的div。

我的意思是,如果我点击第四div名为“联系我们”,我想显示所有的文章。点击第二次显示只有第一次和第二次。

用CSS3可以做到这一点吗?

HTML:

代码语言:javascript
复制
<div class="container">
    <section class="ac-container">
        <div>
            <input id="ac-1" name="accordion-1" type="checkbox" />
            <label for="ac-1">About us</label>
            <article class="ac-small">
                <p>Well, the way they make shows is, they make one show. That show's called a pilot. Then they show that show to the people who make shows, and on the strength of that one show they decide if they're going to make more shows.</p>
            </article>
        </div>
        <div>
            <input id="ac-2" name="accordion-1" type="checkbox" />
            <label for="ac-2">How we work</label>
            <article class="ac-medium">
                <p>Like you, I used to think the world was this great place where everybody lived by the same standards I did, then some kid with a nail showed me I was living in his world, a world where chaos rules not order, a world where righteousness is not rewarded. That's Cesar's world, and if you're not willing to play by his rules, then you're gonna have to pay the price. </p>
            </article>
        </div>
        <div>
            <input id="ac-3" name="accordion-1" type="checkbox" />
            <label for="ac-3">References</label>
            <article class="ac-large">
                <p>You think water moves fast? You should see ice. It moves like it has a mind. Like it knows it killed the world once and got a taste for murder. After the avalanche, it took us a week to climb out. Now, I don't know exactly when we turned on each other, but I know that seven of us survived the slide... and only five made it out. Now we took an oath, that I'm breaking now. We said we'd say it was the snow that killed the other two, but it wasn't. Nature is lethal but it doesn't hold a candle to man. </p>
            </article>
        </div>
        <div>
            <input id="ac-4" name="accordion-1" type="checkbox" />
            <label for="ac-4">Contact us</label>
            <article class="ac-large">
                <p>You see? It's curious. Ted did figure it out - time travel. And when we get back, we gonna tell everyone. How it's possible, how it's done, what the dangers are. But then why fifty years in the future when the spacecraft encounters a black hole does the computer call it an 'unknown entry event'? Why don't they know? If they don't know, that means we never told anyone. And if we never told anyone it means we never made it back. Hence we die down here. Just as a matter of deductive logic. </p>
            </article>
        </div>
    </section>
</div>

CSS

代码语言:javascript
复制
div {
  display: block;
  width: 25%;
  float:left;
}
.ac-container{
    width: 900px;
    margin: 10px auto 30px auto;
    text-align: left;
}
.ac-container label{
    font-family: 'BebasNeueRegular', 'Arial Narrow', Arial, sans-serif;
    padding: 5px 20px;
    position: relative;
    z-index: 20;
    display: block;
    height: 30px;
    cursor: pointer;
    color: #777;
    text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
    line-height: 33px;
    font-size: 19px;
    background: #ffffff;
    background: -moz-linear-gradient(top, #ffffff 1%, #eaeaea 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(1%,#ffffff), color-stop(100%,#eaeaea));
    background: -webkit-linear-gradient(top, #ffffff 1%,#eaeaea 100%);
    background: -o-linear-gradient(top, #ffffff 1%,#eaeaea 100%);
    background: -ms-linear-gradient(top, #ffffff 1%,#eaeaea 100%);
    background: linear-gradient(top, #ffffff 1%,#eaeaea 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#eaeaea',GradientType=0 );
    box-shadow: 
        0px 0px 0px 1px rgba(155,155,155,0.3), 
        1px 0px 0px 0px rgba(255,255,255,0.9) inset, 
        0px 2px 2px rgba(0,0,0,0.1);
}
.ac-container label:hover{
    background: #fff;
}
.ac-container input:checked + label,
.ac-container input:checked + label:hover{
    background: #c6e1ec;
    color: #3d7489;
    text-shadow: 0px 1px 1px rgba(255,255,255, 0.6);
    box-shadow: 
        0px 0px 0px 1px rgba(155,155,155,0.3), 
        0px 2px 2px rgba(0,0,0,0.1);
}
.ac-container label:hover:after,
.ac-container input:checked + label:hover:after{
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    right: 13px;
    top: 7px;
    background: transparent url(../images/arrow_down.png) no-repeat center center;  
}
.ac-container input:checked + label:hover:after{
    background-image: url(../images/arrow_up.png);
}
.ac-container input{
    display: none;
}
.ac-container article{
    background: rgba(255, 255, 255, 0.5);
    margin-top: -1px;
    overflow: hidden;
    height: 0px;
    position: relative;
    z-index: 10;
    -webkit-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
    -moz-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
    -o-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
    -ms-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
    transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
}
.ac-container article p{
    font-style: italic;
    color: #777;
    line-height: 23px;
    font-size: 14px;
    padding: 20px;
    text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
}

.ac-container input:checked ~ article.ac-small{
    height: 140px;
}
.ac-container input:checked ~ article.ac-medium{
    height: 180px;
}
.ac-container input:checked ~ article.ac-large{
    height: 230px;
}

注:如果需要的话我可以用SASS。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-26 18:22:32

您如何实现它的答案是:不,您不能仅用CSS来完成这一任务。

但是,如果您更改了标记和显示,那么您可能能够以您想要的方式来确定目标,尽管您可能需要更改您的样式。不管怎样,现在你有:

代码语言:javascript
复制
div-1
  input-1
  article-1
div-2
  input-2
  article-2
...

在检查第二个输入时,不能针对第一篇文章,因为您不能从div-2中遍历,即使可以,也不能从div-2遍历到div-1

尽管如此,如果您真的想尝试,您可以提取div,反转标记和显示顺序(并使用浮点数或文本方向对它们进行反向样式设置)。然后,你可以:

代码语言:javascript
复制
input-4
article-4
input-3
article-3
....

您可以使用浮点数或文本方向来显示1,2,3,4。由于标记为4,3,2,1,理论上,如果选中较高的值,则可以将较低的数字作为目标,如下所示:

代码语言:javascript
复制
input:checked ~ article {/*show*/}

有了这个规则,如果选中第四个输入(尽管它是标记中的第一个,也可以显示在右侧),那么它将显示所有的文章。另外,如果3被选中(4没有),3,2,1将显示等等。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17325012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档