【问题标题】:CSS Folding Paper Like Menu IssueCSS折叠纸像菜单问题
【发布时间】:2013-06-18 12:17:44
【问题描述】:

我正在尝试构建一个菜单,该菜单具有折纸之类的过渡效果,有点像这样:

现场测试:http://www.cssplay.co.uk/menus/cssplay-3d-unfolding-menu.html

这是我的代码:

HTML

<nav>
  <li class="hov">Hover Me!
    <ul class="main">
      <li>Item1</li>
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
    </ul>
  </li>
</nav>

CSS

nav{

}

ul,li{
  margin: 0;
  padding: 0;
}
.main{
  position:absolute;
  z-index:1;

}
.main li{
  list-style:none;
  background: blue;
  width:100px;
  padding: 0 5px;
  border: 1px solid black;
  height: 30px;

  line-height: 30px;
  /*margin-top: -30px;*/

  -webkit-transition: all .5s ease-in-out;

}

.main li:nth-child(odd){

  -webkit-transform-origin: top;
  -webkit-transform: perspective(350px) rotateX(-90deg);
}

.main li:nth-child(even){

  -webkit-transform-origin: bottom;
  -webkit-transform: perspective(350px) rotateX(90deg);
}

.main {

  -webkit-transition: all .5s ease-in-out;
  -webkit-transform-origin: 50% 0%;
  -webkit-transform: perspective(350px) rotateX(-90deg);
}

.hov:hover .main {

  -webkit-transform-origin: top;
  -webkit-transform: perspective(350px) rotateX(0deg);
}

.hov:hover li:nth-child(odd){
  -webkit-transform-origin: top;
  -webkit-transform: perspective(350px) rotateX(0deg);
  margin-top:0;
}

.hov:hover li:nth-child(even){
  -webkit-transform-origin: bottom;
  -webkit-transform: perspective(350px) rotateX(0deg);
   margin-top:0;
}

.main li:first-child{
  margin-top:0;
}

.hov{
  position:relative;
  height: 40px;
  width:112px;
  background: green;
  color: white;
  font-size: 13px;
  font-family: Helvetica;
  font-weight:bold;
  text-align: center;
  line-height: 40px;
  list-style:none;
  z-index:2;



}

现场演示

http://codepen.io/razvan-tudosa/pen/BxgJl

问题:

如何使子菜单像示例中那样粘在一起?

【问题讨论】:

  • http://codepen.io/razvan-tudosa/pen/BxgJl 在 FF 中不起作用。
  • 你需要在这里发布你的代码,而不仅仅是链接,好像链接会死,你的问题对未来的访问者没有用,所以投一个密切的投票,希望你将代码添加到你的很快的问题..
  • 问题是How can i make the sub-menus dont 粘在一起?`
  • 这个问题仍然没有意义。教程域。不好问。旺旺旺旺之类的问题,不关心在这个 CSS 领域之类的具体要问什么。为什么重新开放?
  • @hakre 给他一个机会..

标签: html css css-transitions css-transforms


【解决方案1】:

他想坚持子菜单。

为此编辑这些 css 类,如下所示:

.main li:nth-child(even){
  margin-top:-65px;
  -webkit-transform-origin: bottom;
  -webkit-transform: perspective(350px) rotateX(90deg);
}

.hov:hover li:nth-child(odd){
  -webkit-transform-origin: top;
  -webkit-transform: perspective(30px) rotateX(0deg);
  margin-top:0;
}

.hov:hover li:nth-child(even){
  -webkit-transform-origin: bottom;
  -webkit-transform: perspective(30px) rotateX(0deg);
  margin-top:0;
}

然后它看起来真的很接近另一个效果。

更新:

示例here

nav{

}

ul,li{
  margin: 0;
  padding: 0;
}
.main{
  position:absolute;
  z-index:1;
  
}
.main li{
  list-style:none;
  background: blue;
  width:100px;
  padding: 0 5px;
  border: 1px solid black;
  height: 30px;

  line-height: 30px;
  /*margin-top: -30px;*/
  
  -webkit-transition: all .5s ease-in-out;
  
}

.main li:nth-child(odd){
  
  -webkit-transform-origin: top;
  -webkit-transform: perspective(350px) rotateX(-90deg);
}

.main li:nth-child(even){
  margin-top:-65px;
  -webkit-transform-origin: bottom;
  -webkit-transform: perspective(350px) rotateX(90deg);
}

.main {
  
  -webkit-transition: all .5s ease-in-out;
  -webkit-transform-origin: 50% 0%;
  -webkit-transform: perspective(350px) rotateX(-90deg);
}

.hov:hover .main {
  
  -webkit-transform-origin: top;
  -webkit-transform: perspective(350px) rotateX(0deg);
}

.hov:hover li:nth-child(odd){
  -webkit-transform-origin: top;
  -webkit-transform: perspective(30px) rotateX(0deg);
  margin-top:0;
}

.hov:hover li:nth-child(even){
  -webkit-transform-origin: bottom;
  -webkit-transform: perspective(30px) rotateX(0deg);
   margin-top:0;
}

.main li:first-child{
  margin-top:0;
}

.hov{
  position:relative;
  height: 40px;
  width:112px;
  background: green;
  color: white;
  font-size: 13px;
  font-family: Helvetica;
  font-weight:bold;
  text-align: center;
  line-height: 40px;
  list-style:none;
  z-index:2;
  
  
  
}
<nav>
  <li class="hov">Hover Me!
    <ul class="main">
      <li>Item1</li>
      <li>Item2</li>
      <li>Item3</li>
      <li>Item4</li>
    </ul>
  </li>
</nav>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 2011-09-21
    • 2023-03-15
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    相关资源
    最近更新 更多