0

I have the following menu. and I want to align all the menu title to the center of the page. I have tried align-text and align content with no luck. I even put the menu inside the table with td that align to the center and it is not working. any help?

 <ul id="menu" style="width:200%; text-align:center; margin:0 auto;">
                    <li>
                        <a href=" #">
                            Home
                        </a>
                    </li>
                    <li>
                        <a href="#">About &#65516;</a>
                        <ul class="hidden">
                            <li><a href="#">Who We Are</a></li>
                            <li><a href="#">What We Do</a></li>
                        </ul>
                    </li>
                    <li>
                        <a href="#">Portfolio &#65516;</a>
                        <ul class="hidden">
                            <li><a href="#">Photography</a></li>
                            <li><a href="#">Web &amp; User Interface Design</a></li>
                            <li><a href="#">Illustration</a></li>
                        </ul>
                    </li>
                    <li><a href="#">News</a></li>
                    <li><a href="#">Contact</a></li>
                </ul>

and here is the CSS:

 ul {
     background-repeat: repeat-x;
        list-style-type: none;
        margin: 0;
        padding: 0;
        position: absolute;

    }

    /*Create a horizontal list with spacing*/
    li {
        display: inline-block;
        float: left;
        margin-right: 0px;

    }

        /*Style for menu links*/
        li a {
         background-image:url("../image_menu/bg.jpg");
         background-repeat: repeat-x;
            display: block;
            min-width: 140px;
            width:100%;
            height: 85px;
            text-align: center;
            line-height: 50px;
            font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            color: #fff;

            text-decoration: none;
        }

        /*Hover state for top level links*/
        li:hover a {
            background: #19c589;
        }

        /*Style for dropdown links*/
        li:hover ul a {
            background: #f3f3f3;
            color: #2f3036;
            height: 40px;
            line-height: 40px;
        }

            /*Hover state for dropdown links*/
            li:hover ul a:hover {
                background: #19c589;
                color: #fff;
            }

        /*Hide dropdown links until they are needed*/
        li ul {
            display: none;
        }

            /*Make dropdown links vertical*/
            li ul li {
                display: block;
                float: none;
            }

                /*Prevent text wrapping*/
                li ul li a {
                    width: auto;
                    min-width: 100px;
                    padding: 0 20px;
                }

    /*Display the dropdown on hover*/
    ul li a:hover + .hidden, .hidden:hover {
        display: block;
    }

    /*Style 'show menu' label button and hide it by default*/
    .show-menu {
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
        text-decoration: none;
        color: #fff;
        background: #19c589;
        text-align: center;
        padding: 10px 0;
        display: none;
                background:url("../image_menu/bg.png");
     background-repeat: repeat-x;
    }

    /*Hide checkbox*/
    input[type=checkbox] {
        display: none;
        -webkit-appearance: none;
    }

        /*Show menu when invisible checkbox is checked*/
        input[type=checkbox]:checked ~ #menu {
            display: block;
        }


    /*Responsive Styles*/

    @media screen and (max-width : 760px) {
        /*Make dropdown links appear inline*/
        ul {
            position: static;
            display: none;
        }
        /*Create vertical spacing*/
        li {
            margin-bottom: 1px;
        }
            /*Make all menu links full width*/
            ul li, li a {
                width: 100%;
            }
        /*Display 'show menu' link*/
        .show-menu {
                    background:url("../image_menu/bg.jpg");
     background-repeat: repeat-x;
            display: block;
        }
    }

appreciate any help

James KM
  • 69
  • 8

2 Answers2

0

If you want the navigation to be centered in the menu bar. All you have to do is change the #menu to width:100% instead of width:200% and get rid of the float:left; on the li. Here is a JSFiddle. Hope this helps.

https://jsfiddle.net/h1v85zuf/

Jorden
  • 153
  • 1
  • 3
  • 16
0

Change the inline width for the ul to 100%, erase the floats for the menu items and add margin: 0to the body:

Additon: You have to switch that snippet to "full page" mode to see the solution.

body {
background: #333;
margin: 0;
}
ul {
  background-repeat: repeat-x;
  list-style-type: none;
  margin: 0;
  padding: 0;
  position: absolute;
}


/*Create a horizontal list with spacing*/

li {
  display: inline-block;
  margin-right: 0px;
}


/*Style for menu links*/

li a {
  background-image: url("../image_menu/bg.jpg");
  background-repeat: repeat-x;
  display: block;
  min-width: 140px;
  width: 100%;
  height: 85px;
  text-align: center;
  line-height: 50px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #fff;
  text-decoration: none;
}


/*Hover state for top level links*/

li:hover a {
  background: #19c589;
}


/*Style for dropdown links*/

li:hover ul a {
  background: #f3f3f3;
  color: #2f3036;
  height: 40px;
  line-height: 40px;
}


/*Hover state for dropdown links*/

li:hover ul a:hover {
  background: #19c589;
  color: #fff;
}


/*Hide dropdown links until they are needed*/

li ul {
  display: none;
}


/*Make dropdown links vertical*/

li ul li {
  display: block;
  float: none;
}


/*Prevent text wrapping*/

li ul li a {
  width: auto;
  min-width: 100px;
  padding: 0 20px;
}


/*Display the dropdown on hover*/

ul li a:hover+.hidden,
.hidden:hover {
  display: block;
}


/*Style 'show menu' label button and hide it by default*/

.show-menu {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  text-decoration: none;
  color: #fff;
  background: #19c589;
  text-align: center;
  padding: 10px 0;
  display: none;
  background: url("../image_menu/bg.png");
  background-repeat: repeat-x;
}


/*Hide checkbox*/

input[type=checkbox] {
  display: none;
  -webkit-appearance: none;
}


/*Show menu when invisible checkbox is checked*/

input[type=checkbox]:checked~#menu {
  display: block;
}


/*Responsive Styles*/

@media screen and (max-width: 760px) {
  /*Make dropdown links appear inline*/
  ul {
    position: static;
    display: none;
  }
  /*Create vertical spacing*/
  li {
    margin-bottom: 1px;
  }
  /*Make all menu links full width*/
  ul li,
  li a {
    width: 100%;
  }
  /*Display 'show menu' link*/
  .show-menu {
    background: url("../image_menu/bg.jpg");
    background-repeat: repeat-x;
    display: block;
  }
}
<ul id="menu" style="width:100%; text-align:center; margin:0 auto;">
  <li>
    <a href=" #">
                            Home
                        </a>
  </li>
  <li>
    <a href="#">About &#65516;</a>
    <ul class="hidden">
      <li><a href="#">Who We Are</a></li>
      <li><a href="#">What We Do</a></li>
    </ul>
  </li>
  <li>
    <a href="#">Portfolio &#65516;</a>
    <ul class="hidden">
      <li><a href="#">Photography</a></li>
      <li><a href="#">Web &amp; User Interface Design</a></li>
      <li><a href="#">Illustration</a></li>
    </ul>
  </li>
  <li><a href="#">News</a></li>
  <li><a href="#">Contact</a></li>
</ul>
Johannes
  • 64,305
  • 18
  • 73
  • 130