Due to some circumstances, this blog is now up for sale, for more enquires contact: Plushista@gmail.com
RealcomBiz
Pin It

How to Expand & Collapse (toggle) div Layer Using Only CSS3

by Durodola Ridwan | Saturday, January 18, 2014 | | 125 Comments

Lists are one of the best ways to present information in a structured way, we can create different level of depth according to categories or level of details. But sometimes when the information is too much, showing all the full data at a click can overload the design, especially if we want to keep it simple and clean.

One way to having a list that shows an important amount of data and at the same time not hinder the rest of design is making the list expandable and collapsible in a dynamic way.

More and more lately I’ve seen developers creating toggle states most especially with jQuery. But this guide is going to show you how to create expand and collapse toggle effect with pure CSS3. I have tried to keep it as simple as possible with a few lines of code.




Demo:

Lorem ipsum dolor sit amet, consectetuer adipiscing.
Lorem ipsum dolor sit amet, consectetuer adipiscing.

HTML
<input class="toggle-box" id="header1" type="checkbox" >
<label for="header1">Click here to read more!</label>
<div>Lorem ipsum dolor sit amet, consectetuer adipiscing.</div>

In the HTML code above, i have use header1 as the header class, duplicating the layer means you will to give it another unique ID like header2.


CSS
.toggle-box {
  display: none;
}

.toggle-box + label {
  cursor: pointer;
  display: block;
  font-weight: bold;
  line-height: 21px;
  margin-bottom: 5px;
}

.toggle-box + label + div {
  display: none;
  margin-bottom: 10px;
}

.toggle-box:checked + label + div {
  display: block;
}

.toggle-box + label:before {
  background-color: #4F5150;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;
  border-radius: 10px;
  color: #FFFFFF;
  content: "+";
  display: block;
  float: left;
  font-weight: bold;
  height: 20px;
  line-height: 20px;
  margin-right: 5px;
  text-align: center;
  width: 20px;
}

.toggle-box:checked + label:before {
  content: "\2212";
}

I have set the toogle-box to display: none; so as to to prevent div element from appearing, and with pseudo class i have add set a positive sign (content: "+") to indicate inactive and a negative sign to indicate active (content: "\2212").
That's it! Expandible-Collapsible panel is ready.



Go Social:

Subscribe For Free Updates!

*Please confirm the email sent to your inbox after clicking "Sign Up!".

125 comments : Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. html5 details/summary element does this nicely without even needing extra css. now if only firefox would implement the darn thing after two years of dithering ... heck, even OLD Opera 12 has it.

    ReplyDelete
  2. Today is the requirement of classic web designer who knows everything about the design, but concern seo professionals is a good idea as it solves half of search engine issues, because search engines are looking for some typical web design rules in every websites.
    Ref - Web Design Jaipur

    ReplyDelete
  3. Is it possible to implement an Expand All / Collapse All?

    How to default the view to Expand?

    ReplyDelete
  4. Packers Movers Provide Best Packing Moving Services, Shipping Delivery, ... Kolkata Packers Movers, Packers Movers Kolkata, Loading and Unloading.
    Packers And Movers Kolkata
    Packers And Movers
    Movers And Packers Kolkata
    Packers And Movers in Kolkata

    ReplyDelete
  5. Your method of explaining in the blog that’s superb I have now words to praise your blog. recommended auto insurance deductibles

    ReplyDelete
  6. It's great, except I can't get it to work in IE 11. Any ideas on why?

    ReplyDelete
    Replies
    1. I am having the same problem. It does not work on IE 11. Did you figure out why?

      Delete
    2. This comment has been removed by the author.

      Delete
  7. Packers and movers Noida @ http://www.noidapackers.co.in/
    packers and movers noida sector 12 @ http://www.noidapackers.co.in/
    packers and movers noida sector 53 @ http://www.noidapackers.co.in/
    packers and movers noida sector 51 @ http://www.noidapackers.co.in/
    packers and movers noida sector 50 @ http://www.noidapackers.co.in/
    packers and movers noida sector 49 @ http://www.noidapackers.co.in/
    packers and movers noida sector 41 @ http://www.noidapackers.co.in/
    packers and movers noida sector 39 @ http://www.noidapackers.co.in/
    packers and movers noida sector 62 @ http://www.noidapackers.co.in/
    packers and movers noida sector 61 @ http://www.noidapackers.co.in/

    ReplyDelete

  8. Delhi packers and movers @ http://b2bad.in/Packers-and-Movers-in-Delhi/
    Packers and movers in Delhi @ http://b2bad.in/Packers-and-Movers-in-Delhi/
    Movers and packers in Delhi @ http://b2bad.in/Packers-and-Movers-in-Delhi/
    Packers and movers Delhi @ http://b2bad.in/Packers-and-Movers-in-Delhi/

    ReplyDelete
  9. That was a great article and helped me a lot in developing my own site.
    web design jaipur

    ReplyDelete
  10. thank you for this code, I have it working nicely but my site is not live yet. I wanted to know if there was a way to highlight the accordion headers when you hover to indicate that they are in fact something to click on and open. something similar to the way the hand appears in the CSS version but without using the CSS version.


    Ref:- web designing company in jaipur

    ReplyDelete
    Replies
    1. There is the :hover pseudo class you can use in CSS.

      Got a jsfiddle for you: https://jsfiddle.net/k3Lvzu2a/
      Lines 43 - 46 are what you are looking for.

      Delete
  11. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know.
    geometry dash|agario |pacman | my little pony games | sniper games |happy wheels | happy wheels 2 mickey mouse games mahjong

    ReplyDelete
  12. What a great content thanks for amazing sharing great work keep it up..:) Conference Call App

    ReplyDelete
  13. Thanks, you guys that is a great explanation. keep up the good work in your granite blog.
    mickey mouse games
    happy wheels
    agario

    ReplyDelete
  14. Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
    earn to die
    Hi! I’ve been reading your blog for a while now and finally got the courage to go ahead and give youu a shout out from Austin Texas! Just wanted to tell you keep up the fantastic work!my weblog:
    tank trouble
    tank trouble

    earn to die 1

    earn to die 2

    earn to die 3

    tank trouble 4
    tank trouble 3
    tank trouble 2

    ReplyDelete
  15. Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
    age of war 5
    Hi! I’ve been reading your blog for a while
    now and finally got the courage to go ahead and give youu a shout out from Austin Texas! Just wanted to tell you keep up the fantastic work!my weblog:
    age of war 6
    age of war 4

    age of war 3

    earn to die game vip

    ReplyDelete
  16. Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!

    hotmail sign in Hotmail is an email account of Microsoft Corporation. Like Google’s Gmail, it is full of the features of a regular email.

    hotmail login Hotmail was previously a quite popular email service. It has the features and utilities similar to other email services, but users encountered many annoying issues, and even lost fees they had paid for this service.


    recover hotmail password Therefore, there are many users who have a registered Hotmail account but no longer wish to use it as they are unhappy with the service.

    sign in to Hotmail  At this time, some users sought to remove their Hotmail account, but has some difficulties as it is a complicated process.

    ReplyDelete
  17. Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
    Tank trouble
    Hi! I’ve been reading your blog for a while
    now and finally got the courage to go ahead and give youu a shout out from Austin Texas! Just wanted to tell you keep up the fantastic work!my weblog:
    Earn to die

    Barron Games

    Subble shooter

    Tank trouble

    ReplyDelete
  18. This blog is so nice to me. I will continue to come here again and again. Visit my link as well. Good luck
    obat aborsi
    cara menggugurkan kandungan
    obat telat datang bulan
    obat penggugur kandungan

    ReplyDelete
  19. All the best blogs that is very useful for keeping me share the ideas
    of the future as well this is really what I was looking for, and I am
    very happy to come here. Thank you very much
    earn to die
    earn to die 2
    earn to die 3
    Hi! I’ve been reading your blog for a while now and finally got the
    earn to die 4
    courage to go ahead and give youu a shout out from
    earn to die 6
    Austin Texas! Just wanted to tell
    earn to die 5
    Hi! I’ve been reading your blog for a while now and finally got the
    happy wheels
    strike force heroes
    slitherio
    you keep up the fantastic work!my weblog
    age of war
    earn to die 5
    good game empire

    ReplyDelete
  20. This blog is so nice to me. I will continue to come here again and again. Visit my link as well. Good luck
    obat aborsi
    cara menggugurkan kandungan
    obat telat datang bulan
    obat penggugur kandungan

    ReplyDelete

  21. One way to having a list that shows an important amount of data and at the same time not hinder the rest of design is making the list expandable and collapsible in a dynamic way.
    digitalopeners.com

    ReplyDelete
  22. The war between humans, orcs and elves continues. Lead your race through a series of epic battles, using your crossbow to fend off foes and sending out units to destroy castles. Researching and upgrading wisely will be crucial to your success! There are 5 ages total and each one will bring you new units to train to fight in the war for you cause.
    earn to die 2 | game earn to die
    | unfair mario | slitherio
    Whatever you do, don’t neglect your home base because you cannot repair it and once it is destroyed, you lose! Age of War is the first game of the series and really sets the tone for the Age of War games . Also try out the Age of Defense series as it is pretty similar.
    In this game, you start at the cavern men’s age, then evolve! There is a total of 5 ages, each with its units and turrets. Take control of 16 different units and 15 different turrets to defend your base and destroy your enemy.
    tank trouble | age of war | age of war 6 | gold miner
    The goal of the game also differs depending on the level. In most levels the goal is to reach a finish line or to collect tokens. Many levels feature alternate or nonexistent goals for the player.

    ReplyDelete
  23. Religion is an Integral Part of Human Life. It tells us how to worship & Moral Values.
    Role Of Religion

    ReplyDelete
  24. The war between humans, orcs and elves continues. Lead your race through a series of epic battles, using your crossbow to fend off foes and sending out units to destroy castles. Researching and upgrading wisely will be crucial to your success!
    age of war 3 | age of war 2 | unfair mario 2 | tank trouble 3 | tank trouble
    The game controls are shown just under . Movement mechanisms primarily include acceleration and tilting controls.
    cubefield | tank trouble | happy wheels | slitherio | gold mine

    ReplyDelete

  25. A good blog. Thanks for sharing the information. It is very useful for my future. keep sharing
    duck life 3 | Slither io |Red Ball 3 |
    gmail sign in | gmail login |

    ReplyDelete
  26. The war between humans, orcs and elves continues. Lead your race through a series of epic battles, using your crossbow to fend off foes and sending out units to destroy castles. Researching and upgrading wisely will be crucial to your success!
    age of war 3 | slitherio | unfair mario 2 |
    The game controls are shown just under . Movement mechanisms primarily include acceleration and tilting controls.
    cubefield | tank trouble | happy wheels | earn to die 4
    | earn to die

    ReplyDelete
  27. Thanks for sharing this quality information with us. I really enjoyed reading.
    slither io | wings io | science kombat | tank trouble 4

    ReplyDelete
  28. http://www.urdupoetry4u.com/2015/11/best-sad-urdu-poetry-images-2016-mujhe.html
    http://www.urdupoetry4u.com/2016/07/eid-poetry.html

    ReplyDelete
  29. Welcomes to google terminal keep sharing such ideas in the future as well.
    google snake this was actually EARN TO DIE
    what i was looking for,and i am glad to came here! AGE OF WAR 2
    Hi! I’ve been reading your blog for a while HAPPY WHEELS
    I want you to thank for your time of this wonderful read!!! Slitherio
    Amazing insight you have on this, Slither io This article always blew me BIG FARM

    ReplyDelete
  30. The war between humans, orcs and elves continues. Lead your race through a series of epic battles, using your crossbow to fend off foes and sending out units to destroy castles. Researching and upgrading wisely will be crucial to your success!
    slitherio | unfair mario 2 | age of war 2
    The game controls are shown just under . Movement mechanisms primarily include acceleration and tilting controls.
    cubefield | tank trouble | happy wheels | earn to die 2 |
    earn to die 4 |earn to die 3 | duck life

    ReplyDelete
  31. Hotmail is an email account of Microsoft Corporation. Like Google's Gmail, it is full of features usually xuyen.Neu of an email you want to register an account please follow these basic steps:
    hotmail login | hotmail review | sign in to hotmail

    login to hotmail | recover hotmail password

    hotmail login

    ReplyDelete
  32. Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
    kids games free | games games | shooting games | tank games | apple shooter | stick war 2 | unblocked games

    ReplyDelete
  33. The best space for your child to relax!: wingsio | slither io | abc

    ReplyDelete
  34. this is one of the cult game now, a lot of people enjoy playing them . Also you can refer to the game :
    age of war | earn to die 5 | Tank trouble | happy wheels | earn to die 6
    The game controls are shown just under . Movement mechanisms primarily include acceleration and tilting controls.
    tank trouble unblocked | wings io | strike force heroes

    ReplyDelete
  35. LG is about to launch its new flagship device, the LG G6 shortly.
    It has got awesome features and specs and is going to give tough competition to the Samsung galaxy series of smart phones.
    You will get all the information about the LG G6 from my blog. Just check it out.

    ReplyDelete
  36. Gmail is an free e-mail service provided to Internet users by the giant Google.
    If you are a new user of this service, you can follow the steps below to log in to your Gmail account.
    gmail login | create gmail account
    gmail sign in | change gmail password
    recover gmail password

    ReplyDelete
  37. This is a very good post. Just wonderful. Truly, I am amazed at what informative things you've told us today. Thanks a million for that. Kimcil Susu Besar Pengen Dientot

    ReplyDelete
  38. These are great games that page. The game let's you go too. You will feel this wonderful thing.
    gum mayhem | can you pet 2
    learn to fly | happy whell game
    tank trouble

    ReplyDelete

  39. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.

    Discover our website bounty of free online games now!
    Our website has the biggest collection of free online games. Totally new games are added every day!

    age of war 2
    gold Miner 2
    unfair Mario 2
    cubefield 2
    tanki Online 2

    ReplyDelete
  40. And money. Thank God for instant loans! It is usually fast loans difficult to approach
    happy wheels
    return man 3
    friv4school

    ReplyDelete
  41. This was actually what i was looking for, and i am glad to came here! Thank you very much

    Cookie Clicker
    Cookie Clicker play
    Cookie Clicker game
    Cookie Clicker online

    ReplyDelete
  42. Nice information . Thank for sharing article …
    contact form | snapchat emoji

    ReplyDelete
  43. I was working and suddenly I visits your site frequently and recommended it to me to read also. Age Of War 2
    Big Farm | Slitherio
    Tank Trouble | Happy Wheels
    Goodgeme Empire | Slither.io

    ReplyDelete
  44. nice! thank you so much! Thank you for sharing. Your blog posts are more interesting and impressive. I think there are many people like and visit it regularly, including me.
    192.168.1.1

    ReplyDelete
  45. This was actually what i was looking for, and i am glad to came here! Thank you very much
    wikidot
    ucoz.net
    wikidot

    ReplyDelete
  46. I found this is the Best Blogging Website in the world & I am sure that you will also like it.
    http://www.shestylehunt.com/
    Modern Lipstick Shades Catalogue

    ReplyDelete
  47. Star Incheon Escorts agency is a unique blend of elegant girls of various ethnicites you can Call 82-10-7309-6791 to find beautiful Incheon escorts girl services in town.
    Incheon Escorts
    Incheon Escort
    Incheon Escorts Services
    Escorts Incheon

    ReplyDelete
  48. The blog or and best that is extremely useful to keep I can share the ideas
    of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    gold miner|stick war 3| pokemongo
    | stick man|animal jam login

    ReplyDelete
  49. IOS 10 is the tenth major release of the iOS operating system developed by Apple Inc. to use it without any restriction imposed by Apple Inc.You can download iOS 10 Jailbreak. from CydiaNerd.

    ReplyDelete

About Me

My Photo
Durodola Ridwan is a Professional blogger, SEO Consultant, Certified Web developer/designer and founder of www.realcombiz.com. He love writing about Blogging tips, SEO, and play around with codes. You can connect with him on facebook, twitter @realcombiz, and Google+.

Recent Posts

Let's Connect

Site Links

Copyright © 2014 RealcomBiz. All Rights Reserved.
Powered by Blogger