目标伪类选择器target——手风琴效果





    
    手风琴
    


    

css代码


/*设置位置*/
.accordionMenu{
    background: #fff;
    color: #424242;
    margin: 0 auto;
    width: 500px;
    border: 1px solid red;
    font-size: 12px;
    font-family: Arial, Verdana, sans-serif;
}
/*accordionMenu下所有的子元素或者孙辈元素h2*/
.accordionMenu h2{
    margin: 5px 0;
    position: relative;
}
 
/*制作向下三角效果*/
.accordionMenu h2:before {
    border: 5px solid black;
    content: "";
    height: 0;
    position: absolute;
    right: 10px;
    top: 10px;
    border-color:#fff transparent transparent transparent;
    width: 0;
}
 
/*制作手风琴标题栏效果*/
.accordionMenu h2 a{
    background: #8f8f8f;
    display: block;/*块级元素,铺满整个区域*/
    color:#424242;/*默认的字体颜色*/
    font-size: 13px;
    margin: 0;
    padding: 10px 10px;/*文字距离四周的间距*/
    text-shadow: 2px 2px 2px #aeaeae;
    text-decoration: none;
}
 
/*目标标题的效果,点击之后标题的效果*/
.accordionMenu :target h2 a,
.accordionMenu h2 a:focus,
.accordionMenu h2 a:hover,
.accordionMenu h2 a:active{
    background: #2288dd;
    color:#FFF;
}
 
/*标题栏对应的内容*/
.accordionMenu p{
    margin: 0;
    height: 0;/*默认栏目内容高度为0,达到隐藏的效果*/
    overflow: hidden;
    /*padding: 0 10px;*/
}
/*关键代码,展开对应目标内容*/
.accordionMenu :target p{
    height: 100px;
    overflow: auto;
}
/*展开时标题上的三角效果*/
.accordionMenu :target h2:before{
    border-color: transparent transparent transparent #fff;
}

 

你可能感兴趣的:(web前端)