0

I have a problem with my menu, I'm just a beginner and I'm learning.

The problem is: My menu goes in three lines. (I need only one, straight line.) I tried display:inline but it doesn't work.

MY CSS like this:

 body {
    height:auto;
    width:auto;
    background-image: url("img/bgr.png");
}

.header {
    text-align:center;
    margin:0px auto;
}

#header {
    height:300px;
    width:960px;
    background-image:url("img/top.png")
}
#menu ul {
    list-style: none;
}
#menu li a  {
    color:#fff; 
    text-decoration:none; 
    display:block; 
    background:url(img/manu.png); 
    padding:0 10px 0 10px;  
    height:54px; 
    width: 150px;

    line-height:54px;
}

#menu li a:hover {
    color:#fff; 
    text-decoration: none; 
    background:url(img/manu1.png);  
    height:54px; 
    width:150px;
    line-height:54px;
}

And my HTML like this:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Pagrindinis Puslapis</title>
</head>
    <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
<body>
<div class="header" id="header">
    <tekstas><br><br><br><br><br><br>http://www.profilio.com</tekstas>
    </div>
<div class="header" id='menu'>
<ul>
   <li><a href='#'><span>Pagrindinis</span></a></li>
   <li><a href='#'><span>Kontaktai</span></a></li>
   <li><a href='#'><span>Paslaugos</span></a></li>
</ul>
</div>


    
</body>
</html>

Have no idea what's wrong....

Adding some extra text

3
  • Please try to describe your problem more clearly in your question itself. What exactly is bugged? What should it do and what does it do instead? Commented Nov 20, 2015 at 15:15
  • EDIT: The problem is: Menu goes in three lines( I need only one), and the imagebackground is spammed... I only need him to appear when I enter a new menu item <li></li> Commented Nov 20, 2015 at 15:17
  • As a small sidenote: Don't use <br><br><br><br><br><br> to add space. Use margin or padding instead. It's much cleaner. Commented Nov 20, 2015 at 16:08

1 Answer 1

3

The links are set to display:block and so they wrap. They do not line up by default.

If you set the li to display:inline-block they will only be as wide as they need to be which is dtermined by the size of the links.

.header {
  text-align: center;
  margin: 0px auto;
  max-width: 960px;
  background: green;
}
#menu ul {
  list-style: none;
}
#menu li {
  display: inline-block;
}
#menu li a {
  color: #fff;
  text-decoration: none;
  display: block;
  background: blue;
  padding: 0 10px 0 10px;
  height: 54px;
  line-height: 54px;
  width:150px;
}
#menu li a:hover {
  color: #fff;
  text-decoration: none;
  background: red;
  height: 54px;
  line-height: 54px;
}
<header class="header" id="menu">
  <ul>
    <li><a href='#'><span>Pagrindinis</span></a>

    </li>
    <li><a href='#'><span>Kontaktai</span></a>

    </li>
    <li><a href='#'><span>Paslaugos</span></a>

    </li>
  </ul>
</header>

Sign up to request clarification or add additional context in comments.

7 Comments

I changed my question a bit, I realised, that I missed width in menu li a style
s4.postimg.org/fswu35vwt/ketvirtas.png this is what I get after your Edit. And another problem appeared: space between header and menu
@Tomas Can you try to reproduce your issue in JSFiddle with minimal amount of code? (don't just copy&paste the entire site code in it) It will be much easier to debug your issue with the code instead of just screenshots.
jsfiddle.net/cvk5a3nn well the code is small enough , don't know what to delete. Maybe there is a problem it other things.
@Tomas Here you go. You had the display: inline-block; on the #menu li a element instead of the #menu li element.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.