Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering an inline ul/li around center li element

Tags:

html

css

I have to make a website for computer science at school and I have a problem with centering the menu bar. I want it to be centered around the menu button, but it puts the icon off-center the way I do it.

How can I center the entire menu around the central li element?

Here's the code:

body {
  background-color: /*#C94421*/
  #353535;
  margin: 0;
  /* reset de standard marges van de body -> geen randen links en rechts naast .menuBar div */
  text-align: center;
}

.menuBar {
  height: 70px;
  width: 100%;
}

.menuBar img {
  text-align: center;
}

.menuBar ul li {
  display: inline;
  padding-right: 65px;
  line-height: 70px;
}

.menuBar ul li a {
  color: white;
  text-decoration: none;
  line-height: 70px;
  font-family: 'Raleway', sans-serif;
  font-size: 36px;
  width: 100px;
}

.menuBar a:hover {
  border-bottom: 1px solid white;
}

.jumbotron .container {
  height: 550px;
  width: 60%;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 10px;
  border-top: 4.5px double white;
  border-bottom: 4.5px double white;
}
<!DOCTYPE html>
<html>

<head>
  <title> Homepagina </title>
  <link rel="stylesheet" type="text/css" href="main.css">
  <link href='https://fonts.googleapis.com/css?family=Raleway:300' rel='stylesheet' type='text/css'>
  <meta charset="utf-8">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">
  </script>
</head>

<body>

  <div class="menuBar">
    <ul>
      <li> <a href="#"> Over mij </a> </li>
      <li> <a href="#"> Hobbies </a> </li>
      <li>
        <a href="#"> <img src="logoNaam.jpg"> </a>
      </li>
      <li> <a href="#"> Muziek </a> </li>
      <li> <a href="#"> Waarom informatica </a> </li>
    </ul>
  </div>

  <div class="jumbotron">
    <div class="container">

      hoi

    </div>
  </div>

</body>

</html>
like image 622
Candy_In_Mah_Van Avatar asked Oct 24 '25 15:10

Candy_In_Mah_Van


1 Answers

Here are the changes in the code :

You have to add :

.menuBar ul{
padding-left: 0px;}

also relace this :

.menuBar ul li {
display: inline;
padding-right: 65px;
line-height: 70px;}

with

.menuBar ul li {
display: inline-block;
width: 150px;
padding-right: 15px;
line-height: 70px;}

Also remove width: 100px; from .menuBar ul li a

  • Better to reduce the font size to get it well aligned in the frame.
like image 88
nabeel Avatar answered Oct 27 '25 03:10

nabeel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!