0

I have a very simple HTML file with some styles given to it, but for some reason I can't change the width of the links inside of the div, I tried it with width, max-width, min width and with some different containers such as an unordered list, but no matter what, they stay the same size.

  body {
  width: 100%;
  height: 100vh;
  padding: 0px;
  margin: 0px;
}

#navbar {
  margin: 0px;
  padding: 0px;
  height: 10%;
  text-align: center;
}

a:visited,
a:link {
  color: #ffffff;
  border: 2px solid black;
  text-decoration: none;
}

a:hover {
  color: #30cc00;
  background-color: #003333;
<div id="navbar">
  <a href="Seiten/Home.html">Home</a>
  <a href="Seiten/Gedichte.html">Gedichte</a>
  <a href="Seiten/Bücher.html">Bücher</a>
  <a href="Seiten/Aktuelles.html">Aktuelles</a>
  <a href="Seiten/Kontakt.html">Kontakt</a>
</div>
j08691
  • 204,283
  • 31
  • 260
  • 272
alexkleyn
  • 11
  • 2

2 Answers2

1

the a tag is an inline element. change it to inline-block and set width. However, if you are just trying to get more space between the links you might want to consider using flexbox.

body {
    width: 100%;
    height: 100vh;
    padding: 0px;
    margin: 0px;
}

#navbar {
    margin: 0px;
    padding: 0px;
    height: 10%;
    text-align: center;
}

a{
display:inline-block;
width:100px;

}

a:visited, a:link {
    color: #ffffff;
    border: 2px solid black;
    text-decoration: none;
    
}

a:hover{
    color: #30cc00;
    background-color: #003333;
    }
<!DOCTYPE html>
<html lang="de" dir="ltr" style="background-color: #002050; color: #ffffff;">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Stihi</title>
    <link rel="stylesheet" href="index.css">
    <script defer src="index.js"></script>
  </head>

  <body>
      <div id="navbar">
       <a href="Seiten/Home.html">Home</a>
       <a href="Seiten/Gedichte.html">Gedichte</a>
       <a href="Seiten/Bücher.html">Bücher</a>
       <a href="Seiten/Aktuelles.html">Aktuelles</a>
       <a href="Seiten/Kontakt.html">Kontakt</a>
      </div>
  </body>
</html>
DCR
  • 14,737
  • 12
  • 52
  • 115
1

You just need to add in your element <a href="Seiten/Home.html">Home</a>

display: block;

or

display: inline-block;

source: Setting a width and height on an A tag

j08691
  • 204,283
  • 31
  • 260
  • 272