Anton Fernando
Anton Fernando

Reputation: 63

Add a separator between buttons in a menu bar (HTML/CSS)

I'm making a mobile website and having some difficulty with making a few changes to my menu bar. I'm not an expert on this field so your help would be greatly appreciated.

Below is the codes to the menu bar.

CSS

<style type="text/css">
    * { padding: 0; margin: 3; }
    body { padding: 5px; font-family: Helvetica, Arial, sans-serif; width:95%; font-size:12px}
    ul { list-style: none; }
    ul li {
float: left;
padding: 1.5px;
position: relative;
margin: auto;}
ul a { display: table-cell; vertical-align: middle; width: 75%; height: 50px; text-align:center; background: #FFF; color:#000; border-style: solid; border-width:2px; border-color:#1570a6; text-decoration: none; }
    ul a:hover {background-color:#5A87B4; }

HTML

<div> 
<ul>
<li>
  <div align="center"><a href="../Software.html" >Software</a>
    </div>
</li>
  <li>
    <div align="center"><a href="../Products.html">Products</a></div>
  </li>
<li>
<a href="../Order Online.html">FAQ</a></li>
</ul>

This is a basic menu bar and i want to adjust this to the center and also have horozontal lines to break each button apart while all this is centered and fits a 100% on a mobile screen. All your help is greatly appreciated

EDIT: Its like having some space after each button but instead theres a horizontal line

EDIT: Changed the width from 75% to 80px. Note that i also changed the div ID of my code because i was having some other problems with identification. :) Hope this wont confuse you

#menubar * { padding: 0; margin: 2; }
    body { padding: 5px; font-family: Helvetica, Arial, sans-serif; width:95%; font-size:12px}

#menubar ul{text-align:center;}

#menubar ul li { display:inline-block; padding: 2px;  position: relative;  }

#menubar ul a { display: table-cell; vertical-align: middle; width: 80px; height: 50px; text-align:center; background: #FFF; color:#000; border-style: solid; border-width:2px; border-color:#1570a6; text-decoration: none; }

Upvotes: 2

Views: 25971

Answers (3)

Mr_Green
Mr_Green

Reputation: 41832

I added below lines in your css code. I hope this is what you want.

ul{
   display:inline-block;
   overflow:hidden;
}

div{
  text-align:center;
}

li:after{
   border-right:50px solid black;
   content:"";
   position:relative;
   left:10px;
   top:-27px;  
   z-index:-1;
   display:block;
   height:1px;
}

li:last-child{
   margin-right:-14px
}

Working Fiddle

Upvotes: 2

Amyth
Amyth

Reputation: 32949

from your current css remove float:left; on li's and add text-align:center; and it should work:

ul li {
    text-align: center;
    padding: 1.5px;
    position: relative;
    margin: auto;
}

here is a working JSFiddle.

Update

In that case you can change the CSS to.

ul li{
    text-align:center;
    display:inline-block;
}

ul li:before {
    content: " - ";
}

ul li:first-child:before {
    content: none;
}

Here is a working JSFiddle

Upvotes: 0

Rohit Azad Malik
Rohit Azad Malik

Reputation: 32182

Now just remove float:left in your li and add display:inline-block; and add text-align center in your ul tag

as like this

ul{
text-align:center;
}

ul li{
display:inline-block;
vertical-align:top;
float:left; // remove this line
}

Demo

Upvotes: 0

Related Questions