Center menu or by 10% left margin without compromising resposivity

Asked

Viewed 70 times

0

.nav-tabs {
    background-color: #ffff00;
}
.nav-tabs a {
    color: red;
}
<ul>
  <li role="presentation" class="active" ><a href="index.html">Home</a></li>
  <li role="presentation"><a href="produto.html">Produtos</a></li>
  <li role="presentation"><a href="sobre.html">Sobre</a></li>
  <li role="presentation"><a href="contato.html">Contato</a></li>
</ul>

  • good at first if you need to edit and put the rest of css and html...

  • 1

    You can use @media queries to define a specific css only for certain devices, or certain resolution. Learn More

  • You have defined the width of the element?

1 answer

0

The explanation and more examples are here , (in English)

To center an element use: margin: auto;

The section you showed would look like this:

.nav-tabs {
    background-color: #ffff00; 
    margin: auto;
}
.nav-tabs a {
    color: red; 
}
  • I tried, but without success. The home is on the left without any margin and when I put margin-left: 10%; all menu items are left with margin.

  • The answer shows only the css rule that centers an element. (margin:auto;) Since you only presented a CSS line, I assumed this is the one you want to center. Edit your question, showing more code, so that you can understand which html/css combination should receive the rule. In this excerpt you’ve posted, there’s not even a relationship between HTML and CSS.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.