简体   繁体   中英

Space between menu items

I'm trying to make menu on top bar but I want to make a little bit of space between each element. How can I make some space between each menu item?

 .TopMenu { display: flex; justify-content: center; align-items: center; width: 50%; height: 40px }
 <div class="TopMenu"> <a class="active" href="#home">Inicio</a> <a href="#tecnologias">Tecnologias Que Trabajamos</a> <a href="#labs">Labs</a> <a href="#contacto">Contacto</a> <a href="#legal">Legal</a> </div>

You should also add some styling to the a links. Adding :not(:first-of-type) makes sure this will only happen from the second item and onward

.TopMenu a:not(:first-of-type) {
    padding-left: 8px;
}

Since you are using a flexbox container you can use the gap on your flex element as follows:

.TopMenu {
  gap: 10px;
}

Just switch justify-content to space-between

 .TopMenu{ display: flex; align-items: center; width: 50%; height: 40px; justify-content: space-between; }
 <html> <body> <div class="TopMenu"> <a class="active" href="#home">Inicio</a> <a href="#tecnologias">Tecnologias Que Trabajamos</a> <a href="labs">Labs</a> <a href="contacto">Contacto</a> <a href="#legal">Legal</a> </div> </body> </html>

See it in jsfiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM