最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I add plus minus symbol to CSS Accordion - Stack Overflow

programmeradmin1浏览0评论

The original accordion is by Jasson Qasqant on Codepen.

Here is my version:

I would like to add a plus minus similar to this:

Can someone please help me, nothing I've tried worked and I've never written JS before so I was hoping to copy the functions but it's not working.

All tested suggestions welcome. I would need a working example as I don't know how to implement the JS so it works with the CSS and HTML.

Thank you!

The original accordion is by Jasson Qasqant on Codepen.

Here is my version: http://cdpn.io/kaHeo

I would like to add a plus minus similar to this:

http://codepen.io/auginator/pen/tCwDc

Can someone please help me, nothing I've tried worked and I've never written JS before so I was hoping to copy the functions but it's not working.

All tested suggestions welcome. I would need a working example as I don't know how to implement the JS so it works with the CSS and HTML.

Thank you!

Share Improve this question edited Nov 24, 2013 at 1:40 PeeHaa 72.7k60 gold badges194 silver badges264 bronze badges asked Aug 13, 2013 at 13:19 user2660470user2660470 531 gold badge2 silver badges6 bronze badges 1
  • Did you write the js to open and close the containers? – lharby Commented Aug 13, 2013 at 13:26
Add a comment  | 

2 Answers 2

Reset to default 9

Add a pseudo class:

content:"+";

And some js like so:

http://jsfiddle.net/Na5FY/2/

OR

just use JQuerys UI method:

$(".accordion").accordion({
    collapsible: true,
    active: parseInt(active_item),
    heightStyle: "content",
    icons: {
        "header": "ui-icon-plus",
        "activeHeader": "ui-icon-minus"
    }
});

http://jsfiddle.net/4M6vH/3/

http://jsfiddle.net/vkdzuqex/8/

There is some code I busted out, using all css to generate this element, to make the minus, just take away the :after...

.plus {
  width: 31px;
  height: 31px;
  border-radius: 50%;
  border: 1px solid #B4B4B4;
}
.plus:before {
  content: '';  
  width: 25px;
  height: 1px;
  border-top: 1px solid #B4B4B4;
  display: block;
  position: absolute;
  margin-top: 15px;
  margin-left: 3px;
}
.plus:after {
  content: '';  
  width: 1px;
  height: 25px;
  border-right: 1px solid #B4B4B4;
  display: block;
  position: absolute;
  margin-top: 3px;
  margin-left: 14px;
}

<div class="plus"></div>
发布评论

评论列表(0)

  1. 暂无评论