Search code examples
cssnavigationtabular

tabular navigation using only css


I have a tabular navigation list (with the styles I choose for) in an external file contains the following code:

.tabs
{
    position:relative;
    text-align:left; /* This is only if you want the tab items at the center */        
    width: 90%;   
    padding: 0;
    margin: 0;
    /*border: 1px solid green;*/

}
.tabs ul.menu
{
    list-style-type:none;
    display:block; /* Change this to block or inline for non-center alignment */
    width:570px;  
    /*  min-width:570px;  
      max-width:800px;     
    vertical-align: bottom;
    /*border: 1px solid red;*/
}
.tabs ul.menu > li
{
    display:inline;
    float:center;
    vertical-align: bottom;   
   /** border: 1px solid yellow;*/  
    cursor:hand; 

}
.tabs ul.menu li > a
{
    color:#7a7883;
    text-decoration:none;
    display:inline-block;
    text-align:center;
    border:1px solid #f1f3f4;
    padding:5px 10px 5px 10px;  
    width: 25%;  

    font-size:15px;   
    font-family:"Times New Roman", Times, serif;

    border-top-left-radius:5px; -moz-border-radius-topleft:4px; -webkit-border-top-left-radius:5px;
    border-top-right-radius:5px; -moz-border-radius-topright:4px; -webkit-border-top-right-radius:5px;
    -moz-user-select:none;
    cursor:hand;    

      /* Safari 4-5, Chrome 1-9 */
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#aeb8c0));

  /* Safari 5.1, Chrome 10+ */
  background: -webkit-linear-gradient(top, #aeb8c0, #fff);

  /* Firefox 3.6+ */
  background: -moz-linear-gradient(top, #aeb8c0, #fff);

  /* IE 10 */
  background: -ms-linear-gradient(top, #aeb8c0, #fff);

  /* Opera 11.10+ */
  background: -o-linear-gradient(top, #aeb8c0, #fff);    
}
.tabs ul.menu li > a:hover
{

    color: #fff;   
    cursor:hand; 

}
.tabs ul.menu li > div
{
    display:none;
    position:absolute;
     width:98%;  
    /* max-width:700px;*/ 
     min-height:230px;
    left:0; 
    margin: 0 15px 0 15px;
    z-index:-1;
    text-align:left;
    padding:0;  
}
.tabs ul.menu li > div > p
{
    border:1px solid #f1f3f4;      
    background-color: #f5f9fc;  
    width: 99%;
    padding:10px;
    margin:0;  
    color: #65636e;
    font-size:12px;   
    font-family:"Times New Roman", Times, serif;
    text-decoration: none;       
    min-height:200px;

}
.tabs ul.menu li > a:focus
{  
    color: #f5f9fc;  

}

.tabs ul.menu li:target > a
{
    cursor:default;
         /* Safari 4-5, Chrome 1-9 */
  background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#f1f3f4), to(#fff));

  /* Safari 5.1, Chrome 10+ */
  background: -webkit-linear-gradient(top, #fff, #f1f3f4);

  /* Firefox 3.6+ */
  background: -moz-linear-gradient(top, #fff, #f1f3f4);

  /* IE 10 */
  background: -ms-linear-gradient(top, #fff, #f1f3f4);

  /* Opera 11.10+ */
  background: -o-linear-gradient(top, #fff, #f1f3f4);   
    cursor:hand; 
}

.tabs ul.menu li:target > div
{
    display:block;
}

and in the web page I have this:

<!-- Side NAVIGATION -->
<!-- Wrapper 2-Content -->
  <div class="wrapper" style="min-height: 200px;"">
    <!-- content -->
    <div class="content">
    <div class="tabs">
    <ul class="menu">
    <li id="item-1">
        <a href="#item-1">Bla Bla 1</a>
        <div><p>Tab Content 1</p></div>
    </li>
    <li id="item-2">
        <a href="#item-2">Bla Bla 2</a>
        <div><p>Tab Content 2</p></div>
    </li>
    <li id="item-3">
        <a href="#item-3">Bla Bla 3</a>
        <div><p>Tab Content 3</p></div>
    </li>            
    </ul>

</div>  
    </div> 
    <!-- content -->
<!-- end of Side NAVIGATION -->

All goes fine except that it displays the tabs only without the box where the content should appear. I want one of the contents to be visible as default. I just don't know how to activated it without using javaScript.

Thank you in advanced.


Solution

  • add display : block as style for the div which u want to display by default. For example see this fiddle I hv created for making item1 visible on run http://jsfiddle.net/X6Agf/

     <div style="display:block"><p>Tab Content 1</p></div>