单击复杂形状容器内的隐藏/显示面板

时间:2018-05-30 09:57:04

标签: html5 css3 flexbox css-transitions css-shapes

只是想弄清楚这个工作的布局。当您单击图标面板底部的箭头形状时,我必须显示和隐藏菜单,然后再次单击相同的形状时显示面板。困扰我的部分是如何塑造箭头容器,我应该使用css3形状还是只用于那部分的背景img(这似乎不太可能,因为它必须与图标容器完美契合)或者只是制作整个东西(容器和底部形状为css3形状)。

我知道如何使切换上/下工作,但只是尝试以最佳方式布局,任何想法都会非常感激。我可以使用css3形状,flex等,交叉浏览不是这个问题。

这是图片:

enter image description here

enter image description here

这是我到目前为止的HTML:

            <nav class="l-apps l-container">
            <ul>
                <li>
                    <img src="assets/img/icons/google.png">  
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/word.png">                     
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/file.png">
                    <a href="#">Lorem Ipsum</a>                         
                </li>
                <li>
                    <img src="assets/img/icons/network.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/powerpoint.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/diamond.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/other.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/pencil.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/excel.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/triangle.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
            </ul>
        </nav>

2 个答案:

答案 0 :(得分:0)

好吧我想出来,以防其他人有一天需要这样做:

基本相同的html,但为css3形状的div添加了一些带有切换触发器的容器:

            <nav class="l-apps l-container">
            <ul>
                <li>
                    <img src="assets/img/icons/google.png">  
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/word.png">                     
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/file.png">
                    <a href="#">Lorem Ipsum</a>                         
                </li>
                <li>
                    <img src="assets/img/icons/network.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/powerpoint.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/diamond.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/other.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/pencil.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/excel.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
                <li>
                    <img src="assets/img/icons/triangle.png">                         
                    <a href="#">Lorem Ipsum</a>
                </li>
            </ul>
            <div class="shape-container">    
                <div class="base">
                    <a href="#"><i class="icon-toogle fa fa-angle-double-up"></i></a>
                </div>
            </div>        
        </nav>

然后这是形状的scss:

    .base {
    background: $blue;
    display: inline-block;
    height: 105px;
    margin-top: 50px;
    position: relative;
    width: 150px;
    .icon-toogle {
        position:absolute;
        color: $white;
        font-size:1.8em;
        bottom:-.35em;
        left:0;
        right:0;
        margin:auto;
        text-align:center;
    }
    &:before {
        border-top: 20px solid $blue;
        border-left: 75px solid transparent;
        border-right: 75px solid transparent;            
        content: "";
        height: 0;
        left: 0;
        position: absolute;
        bottom: -20px;
        width: 0;
    }
}

现在我有其他问题,整个形状有一个图案背景图像(图标容器和底部的CSS形状),我无法将背景图像放到形状,也许是因为我使用边框使css形状。有没有办法在形状上放置背景图像?

答案 1 :(得分:-1)

我的想法是

$('div').on('click', function(){
  var _class = $(this).hasClass('a-top') ? 'b-top' : 'a-top';
  $(this).attr('class',_class);
});
.a-top {
  background: #f00;
  height: 50px;
  top:0px;
  transition: all .3s ease-out;
}

.b-top {
  background: #f00;
  height: 100px;
  transition: all .3s ease-out;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="a-top">
  menu click me.
</div>