{"id":12,"date":"2007-03-02T17:48:48","date_gmt":"2007-03-02T17:48:48","guid":{"rendered":"http:\/\/www.gurnaik.com\/blog\/?p=12"},"modified":"2007-04-03T08:29:37","modified_gmt":"2007-04-03T08:29:37","slug":"simple-css-tabs","status":"publish","type":"post","link":"https:\/\/www.gurnaik.com\/blog\/2007\/03\/02\/simple-css-tabs\/","title":{"rendered":"Simple CSS Tabs"},"content":{"rendered":"<p>There a number of websites that cover how to do simple navigational tabs<br \/>\nusing only CSS and HTML. One of the top hits in a Google search is  <a href=\"http:\/\/unraveled.com\/\" title=\"unraveled.com\" target=\"_blank\">Joshua Kaufman<\/a>&#8216;s excellent <a href=\"http:\/\/unraveled.com\/projects\/html\/css_tabs\/\" target=\"_blank\" title=\"CSS Tabs 2.0\"> CSS Tabs 2.0<\/a>. There is also Adam Kalsey&#8217;s  <a href=\"http:\/\/kalsey.com\/tools\/csstabs\/\" target=\"_blank\" title=\"CSS Tabs\">implementation<\/a>, although this has problems if the user changes the font size on the page.<\/p>\n<p>I thought I would share my implementation as well. The fully working example is <a href=\"http:\/\/gurnaik.com\/htmltabs\/tabsrc1.html\" target=\"_blank\" title=\"Simple CSS Tabs - first page\">here<\/a>. Clicking on each tab will load the appropriate page. Rather than having separate files for each tab, some JavaScript could be used to show\/hide the content as appropriate.<\/p>\n<p><strong>The HTML Markup<\/strong><\/p>\n<p>The basis of this example is a fairly simple HTML file (tabsrc1.html).<\/p>\n<blockquote>\n<pre>\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;title&gt;Tab Test Page&lt;\/title&gt;\r\n    &lt;link rel=\"stylesheet\" href=\"tabs.css\" type=\"text\/css\" \/&gt;\r\n  &lt;\/head&gt;\r\n  &lt;body&gt;\r\n    &lt;div id=\"tabbar\"&gt;\r\n      &lt;a href=\"#\" title=\"Tab 1\" class=\"first current\"&gt;Tab 1&lt;\/a&gt;\r\n      &lt;a href=\"tabsrc2.html\" title=\"Tab 2\"&gt;Tab 2&lt;\/a&gt;\r\n      &lt;a href=\"tabsrc3.html\" title=\"Tab 3\"&gt;Tab 3&lt;\/a&gt;\r\n      &lt;a href=\"tabsrc4.html\" title=\"Tab 4\"&gt;Tab 4&lt;\/a&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div id=\"tabcontent\"&gt;\r\n      &lt;p&gt;This is the first tab.&lt;\/p&gt;\r\n    &lt;div&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<\/blockquote>\n<p>This basically contains two divs: one for the tab bar and one for the<br \/>\ncontent. The tab bar contains the tab anchor markup.<br \/>\nFor the purposes of this exercise, this page is cloned (and adjusted accordingly) for each tab anchor.<\/p>\n<p>The import thing to note is that the currently selected tab has a CSS<br \/>\nclass assigned to it.<\/p>\n<p><strong>The CSS<\/strong><\/p>\n<p>First, turn off the underlining of the anchors.<\/p>\n<blockquote>\n<pre>\r\na {\r\n  text-decoration: none;\r\n}<\/pre>\n<\/blockquote>\n<p>Then, style the tab bar div to have a border at the bottom.<\/p>\n<blockquote>\n<pre>\r\n#tabbar {\r\n  margin: 0px;\r\n  padding: 0px;\r\n  border-bottom: 1px solid;\r\n}<\/pre>\n<\/blockquote>\n<p>For every anchor in the tab bar, give it a border, but omit the bottom border as that is taken care of with the tab bar border.<\/p>\n<blockquote>\n<pre>\r\n#tabbar a {\r\n  border: 1px solid #778899;\r\n  border-bottom: 0px;\r\n  margin: 0px 0px 0.2em 0.2em;\r\n  padding: 0.2em 0.2em 0em 0.2em;\r\n  font-size: 80%;\r\n}\r\n<\/pre>\n<\/blockquote>\n<p>For stylistic purposes, the first tab in the tab list is indented.<\/p>\n<blockquote>\n<pre> \r\n#tabbar a.first {\r\n  margin-left: 1em;\r\n}\r\n<\/pre>\n<\/blockquote>\n<p>This is the styling for the currently selected tab. It is positioned<br \/>\nrelatively so that the bottom overlaps the tab bar.<\/p>\n<blockquote>\n<pre> \r\n#tabbar a.current {\r\n  position: relative;\r\n  top: 0.1em;\r\n  color: #0066FF;\r\n  background-color: #FFFFFF;\r\n  font-weight: bold;\r\n  border-bottom: 1px solid #FFFFFF;\r\n  border-top: 2px solid #0066FF;\r\n}\r\n<\/pre>\n<\/blockquote>\n<p>Finally, some minimal styling for the tab content.<\/p>\n<blockquote>\n<pre> \r\n#tabcontent {\r\n  margin-left: 0.5em;\r\n  padding: 1em;\r\n}\r\n<\/pre>\n<\/blockquote>\n<p>A fairly simple tabbed interface with a minimal amount of CSS. The example directory containing all the files is <a href=\"http:\/\/gurnaik.com\/htmltabs\/\" target=\"_blank\" title=\"CSS Tabs Directory\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There a number of websites that cover how to do simple navigational tabs using only CSS and HTML. One of the top hits in a Google search is Joshua Kaufman&#8216;s excellent CSS Tabs 2.0. There is also Adam Kalsey&#8217;s implementation, although this has problems if the user changes the font size on the page. I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-web-development"],"_links":{"self":[{"href":"https:\/\/www.gurnaik.com\/blog\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gurnaik.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gurnaik.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gurnaik.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gurnaik.com\/blog\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":0,"href":"https:\/\/www.gurnaik.com\/blog\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gurnaik.com\/blog\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gurnaik.com\/blog\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gurnaik.com\/blog\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}