Mateaș Mario
Mateaș Mario

Reputation: 77

Fix div on top of the screen

So, I made a navigation bar using the HTML div and table elements.

.menu {
  background-color: black;
  color: white;
  font-family: Segoe UI;
}
<div class="menu">
  <table border="0" cellspacing="10">
    <tr>
      <td>Home</td>
      <td>About</td>
      <td>Login</td>
    </tr>
  </table>
</div>

Of course, it isn't finished right now and please don't ask why I didn't use an unordered list <ul> instead of a table.

So, the thing is I want to fix this menu on the top of the screen. No white spaces left before the div. What is the CSS code for this?

Upvotes: 1

Views: 82

Answers (3)

Hanif
Hanif

Reputation: 3797

Try by following CSS codes:

.menu {
  background-color: black;
  color: white;
  font-family: Segoe UI;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
}

Upvotes: 1

Gallaoui
Gallaoui

Reputation: 511

you can use the css attribute position : fixed; and width : 100% to display it over all the screen

Upvotes: 1

user3589620
user3589620

Reputation:

body {
  margin: 0;
}

.menu {
  background-color: black;
  color: white;
  font-family: Segoe UI;
}
<div class="menu">
  <table border="0" cellspacing="10">
    <tr>
      <td>Home</td>
      <td>About</td>
      <td>Login</td>
  </table>
</div>

Upvotes: 2

Related Questions