0

Using my code posted below.

I want to center the div and the text inside to the center of the webpage. My end result is still showing div and content on the top left.

I have tried setting margins to 0 auto.

a {
    float: left;
    width: 8em;
    text-decoration: none;
    color: white;
    background-color: #0094ff;
    padding: 0.2em 0.4em;
    border-right: 1px solid white;
    margin-left:0 auto;
    margin-right:0 auto;
}

a:hover {
    background-color: #00ff90;
}

li {
    display: inline;
}


 div {
    
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

 #horizontal-list ul {
     list-style:none;
     width:10%;
     padding-right:20px;
}

 #horizontal-list ul li {
    list-style:none;
    margin:0 auto;
    display:inline-block;
 }

Html below:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" type="text/css" href="Sitestyles.css">
    <title>blahblah</title>
</head>
<body>
    <div id="menu-outer">
        <div class="table">
            <ul id="horizontal-list">
                <li><a href="#"><img src="image.png" onmousedown="return false;" alt="Something" /></a></li>
                <li><a href="#"><img src="image.png" onmousedown="return false;" alt="Something" /></a></li>
                <li><a href="#"><img src="image.png" onmousedown="return false;" alt="Something" /></a></li>
                <li><a href="#"><img src="image.png" onmousedown="return false;" alt="Something" /></a></li>
                <li><a href="#"><img src="image.png" onmousedown="return false;" alt="Something" /></a></li>
            </ul>
        </div>
    </div>

</body>
</html>
Chris
  • 107
  • 1
  • 11
  • possible duplicate of [center content in div with CSS](http://stackoverflow.com/questions/4374650/center-content-in-div-with-css) – Huey Apr 25 '15 at 04:06
  • where is html code?, your code didn't work. – pcs Apr 25 '15 at 04:09

1 Answers1

0

You will need to add a width to the div you want to center. Otherwise the margin:auto; will not know how to calculate the margins.

Here is an example of how to do this - JSfiddle

And here is the code that makes this possible:

.table{
    margin: auto;
    width: 50%
}

Here is also a definitive guide to centering in CSS.

If you had something else in mind, comment below. Thanks

Ben Rondeau
  • 2,983
  • 1
  • 15
  • 21
  • Thanks, I seem to get confused and think that setting width for div would change the elements width. – Chris Apr 25 '15 at 04:40