{"id":2024,"date":"2012-02-14T00:09:53","date_gmt":"2012-02-14T00:09:53","guid":{"rendered":"https:\/\/deepubalan.com\/blog\/?p=2024"},"modified":"2019-06-08T00:02:49","modified_gmt":"2019-06-07T18:32:49","slug":"notify-pure-css-notification-bar-using-target-pseudo-class","status":"publish","type":"post","link":"https:\/\/deepubalan.com\/blog\/2012\/02\/14\/notify-pure-css-notification-bar-using-target-pseudo-class\/","title":{"rendered":"Notify: Pure CSS notification bar using :target pseudo class"},"content":{"rendered":"<div class=\"splashpic\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/deepubalan.com\/blog\/wp-content\/uploads\/2012\/02\/pure-css-notification-bar.png\" alt=\"pure css notification bar\" title=\"pure css notification bar\" width=\"520\" height=\"185\" class=\"aligncenter size-full wp-image-2073\" srcset=\"https:\/\/deepubalan.com\/blog\/wp-content\/uploads\/2012\/02\/pure-css-notification-bar.png 520w, https:\/\/deepubalan.com\/blog\/wp-content\/uploads\/2012\/02\/pure-css-notification-bar-300x106.png 300w\" sizes=\"(max-width: 520px) 100vw, 520px\" \/><\/div>\n<p>For quite some time now, I have had this little idea of a CSS based notification bar floating in my head&#8230; and was wondering, would there be a way to create it purely using CSS. Finally I decided to spend some time this weekend, and the time spent on it was well worth it. Yes it&#8217;s all driven by the <a href=\"https:\/\/deepubalan.com\/blog\/tag\/css3\/\" title=\"css3\">CSS3<\/a> magic. Absolutely no javascript or jquery was used in the making of this notification bar.<\/p>\n<p>I tried a third party service called hellobar for some days in my blog to display a notification bar, It&#8217;s indeed a good option with so many premium features like detailed traffic analysis and things like that. But it refers to external javascript files, moreover the free version has got some functional restrictions as well. So, I want to make my notification bar to be as simple as it can be with no extra http requests.<\/p>\n<p>so the basic idea is to create a decent looking lightweight pure css top notification bar. No images, no javascript&#8230; that means no extra <a href=\"https:\/\/deepubalan.com\/blog\/2010\/01\/18\/cool-sprites-free-overlapped-css-menu-using-css-sprites\/\">http requests<\/a>. You will get a fast loading, less bandwidth burning, fully customizable simple menu for free. The notification-bar will load automatically on page load and it can easily be turned off and on anytime.<\/p>\n<h2>:target Pseudo Class<\/h2>\n<p>This notification bar is created using the css3 feature called :target Pseudo Class. You can read more about CSS pseudo classes and :target pseudo class in one of my previous posts <strong><a href=\"https:\/\/deepubalan.com\/blog\/2011\/06\/17\/free-pure-css-dropdown-menu-using-target-pseudo-class\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><\/strong>.<\/p>\n<h2>The code in Fiddle<\/h2>\n<p><script async=\"\" src=\"\/\/jsfiddle.net\/bdeepu\/Lo2w3gyr\/embed\/html,css,result\/\"><\/script><\/p>\n<h2>Demo<\/h2>\n<p>Before we continue about how to the css\/html code, let\u2019s take a look at the fully-functional top-bar here\u2026<\/p>\n<div align=\"center\" class=\"button-1\" style=\"width: 250px;margin-bottom: 15px;\"><a href=\"https:\/\/deepubalan.com\/blog\/wp-content\/uploads\/2012\/02\/topbar.html?KeepThis=true&amp;TB_iframe=true&amp;height=475&amp;width=920\" title=\"Pure CSS notification bar\" class=\"thickbox\">VIEW DEMO<\/a><\/div>\n<h2>The HTML<\/h2>\n<p>Copy and paste the below HTML code right after the opening &lt;body&gt; tag<\/p>\n<pre lang=\"html4strict\" line=\"1\">\n<div class=\"topBar\" id=\"notify\">\n  Your notification message goes here \n\n\n<div class=\"btnClose\"><a href=\"#notify\">X<\/a><\/div>\n\n\n\n\n<div class=\"btnOpen\"><a href=\"\">notify<\/a><\/div>\n\n\n<\/div>\n\n\n<\/pre>\n<h2>The CSS<\/h2>\n<p>Copy and paste the below CSS code inside the &lt;head&gt; section or to the CSS file.<\/p>\n<pre lang=\"css\" line=\"1\">.topBar {\n\twidth: 100%;\n\theight: 23px;\n\tposition:relative;\n\ttop: 0;\n\ttext-align: center;\n\tborder-bottom: 1px solid #fff;\n\tbox-shadow: 0 2px 5px #ccc;\n\tpadding-top: 7px;\n\tcolor: #fff;\n\tfont-family: Arial, Helvetica, sans-serif;\n\tfont-size: 13px; }\n.topBar .link {\n\tpadding: 2px 8px;\n\tbackground-color: #831e1a;\n\tcolor: #fff;\n\tborder-radius: 2px;\n\tfont-size: 12px;\n\tfont-weight: bold; }\n.topBar .link:hover {\n\tbackground-color: #e62601; }\n.btnClose a, .btnOpen a {\n\twidth: 50px;\n\tposition: absolute;\n\tright: 30px;\n\ttop: -7px;\n\tfont-weight: bold;\n\tcolor: #fff;\n\ttext-shadow: 0 0 2px #921d17; }\n.btnClose a {\n\tfont-size: 12px;\n\tline-height: 44px;\n\theight:25px; }\n.btnOpen a {\n\tfont-size: 0;\n\tborder: 1px solid #fff;\n\tbox-shadow: 0 2px 5px #ccc;\n\tborder-top: none;\n\tborder-radius: 0 0 4px 4px; }\n.topBar a {\n\ttext-decoration: none; }\n.topBar:target {\n\ttop: -36px;\n\ttransition: top 0.4s ease-in; }\n.topBar:target .btnOpen a {\n\ttop: 30px;\n\theight: 30px;\n\tfont-size: 11px;\n\tline-height: 36px;\n\ttransition-property: top;\n\ttransition-duration: .4s; }\n.topBar:target .btnClose {\n\tdisplay: none; }\n.topBar:target .btnOpen a, .topBar {\n\tbackground: linear-gradient(top,  rgba(226,87,81,1) 0%,rgba(228,93,86,1) 49%,rgba(213,82,76,1) 50%,rgba(226,87,81,1) 100%); }\n<\/pre>\n<h2>Browser Compatibility<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/deepubalan.com\/blog\/wp-content\/uploads\/2011\/06\/target-pseudo-class-browser-support.gif\" alt=\"\" title=\"target pseudo class browser support\" width=\"614\" height=\"84\" class=\"alignleft size-full wp-image-1503\" srcset=\"https:\/\/deepubalan.com\/blog\/wp-content\/uploads\/2011\/06\/target-pseudo-class-browser-support.gif 614w, https:\/\/deepubalan.com\/blog\/wp-content\/uploads\/2011\/06\/target-pseudo-class-browser-support-300x41.gif 300w\" sizes=\"(max-width: 614px) 100vw, 614px\" \/><br \/>\nThis notification bar is fully compatible on all major modern browser versions including IE9.<\/p>\n<h3 style=\"padding-bottom: 0;\">Internet Explorer Version 6 to 8<\/h3>\n<p>The CSS3 pseudo class support can be obtained in Internet Explorer versions 6 to 8 with a cool award winning javascript library called <a rel=\"nofollow\" href=\"http:\/\/selectivizr.com\/\">selectivizr<\/a>. selectivizr is a JavaScript utility that emulates CSS3 pseudo-classes and attribute selectors in Internet Explorer 6-8. Simply include the script in your pages and selectivizr will do the rest. Selectivizr works automatically so you don&#8217;t need any JavaScript knowledge to use it &#8211; you won&#8217;t even have to modify your style sheets. Just start writing CSS3 selectors and they will work in IE. Selectivizr requires a JavaScript library to work. If your website already uses one of the 7 supported libraries you just need to add the selectivizr script to your pages. If not, you will need to pick a library too.<\/p>\n<h2>Downoad<\/h2>\n<p>[download id=&#8221;10&#8243;]<\/p>\n<p>You can use this notification bar for personal and commercial projects at free of charge. What I only expect in return is your comments and backlinks, if you like it. You are not allowed to sell or redistribute this anywhere else. If you like to share this please link to this article.<br \/>\nDo not provide the direct download link nor upload this notification bar onto other servers for your own share, without my permission. If you want to spread the words, just link to this article.<\/p>\n<p><a rel=\"nofollow\" href=\"http:\/\/creativecommons.org\/licenses\/by\/2.5\/in\/\"><img decoding=\"async\" alt=\"Creative Commons License\" style=\"border-width:0\" src=\"http:\/\/i.creativecommons.org\/l\/by\/2.5\/in\/88x31.png\"><\/a><br \/>\n<span xmlns:dc=\"http:\/\/purl.org\/dc\/elements\/1.1\/\" href=\"http:\/\/purl.org\/dc\/dcmitype\/StillImage\" property=\"dc:title\" rel=\"dc:type\">Notify: Pure CSS notification bar using :target pseudo class<\/span> by <a xmlns:cc=\"http:\/\/creativecommons.org\/ns#\" href=\"https:\/\/deepubalan.com\" property=\"cc:attributionName\" rel=\"cc:attributionURL\">Deepu Balan<\/a> is licensed under a <a rel=\"nofollow\" href=\"http:\/\/creativecommons.org\/licenses\/by\/2.5\/in\/\">Creative Commons Attribution 2.5 India License<\/a>. Based on a work at <a xmlns:dc=\"http:\/\/purl.org\/dc\/elements\/1.1\/\" href=\"https:\/\/deepubalan.com\" rel=\"dc:source\">deepubalan.com<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For quite some time now, I have had this little idea of a CSS based notification bar floating in my head&#8230; and was wondering, would there be a way to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2073,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[5],"tags":[131,130,128,50,133],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/posts\/2024"}],"collection":[{"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/comments?post=2024"}],"version-history":[{"count":1,"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/posts\/2024\/revisions"}],"predecessor-version":[{"id":27608,"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/posts\/2024\/revisions\/27608"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/media\/2073"}],"wp:attachment":[{"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/media?parent=2024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/categories?post=2024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/deepubalan.com\/blog\/wp-json\/wp\/v2\/tags?post=2024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}