What's new
HTML Forums | An HTML and CSS Coding Community

Welcome to HTMLForums; home of web development discussion! Please sign in or register your free account to get involved. Once registered you will be able to connect with other members, send and receive private messages, reply to topics and create your very own. Our registration process is hassle-free and takes no time at all!

Center the navbar text

Lariekoekebroek

New member
Hey everybody!
I am working on a website with a fixed navbar on top.
The text starts on de left side of the page.
But i want it to be centered.
This is de html i have.
Can someone please help me out? Thank you!

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin-left: 0px;
font-size: 20px;
font-family: inherit;
background-color: white

}

#navbar {
overflow: hidden;
text-align: center;
background-color: rgba(0, 0, 0, 0.3);
padding-left: 250px
margin-left: 0px;
margin-right: 0px;
}

#navbar a {
float: left;
display: block;
color: white;
background-color:
text-align: center;
padding: 14px 15px;
text-decoration: none;
font-size: 20px;
}

.dropdown {
float: left;
overflow: hidden;
}

.dropdown .dropbtn {
font-size: 20px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}

#navbar a:hover, .dropdown:hover .dropbtn {
background-color: #A89100;
color: white;
text-align: center;

}

.dropdown-content {
display: none;
position: fixed;
background-color: rgba(0, 0, 0, 0.3);
width: 176px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}

.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}

.dropdown-content a:hover {
background-color: #ddd;
width: 176px;
}

.dropdown:hover .dropdown-content {
display: block;
}

.content {
padding: 60px;
text-align: center;

}

.sticky {
position: fixed;
top: 0;
width: 100%;
text-align: center;
}

.sticky + .content {
padding-top: 60px;
text-align: center;

}
</style>
</head>
<body>

<div id="navbar">
<text-align: center;>
<a class="active" href="#home">Home</a>
<a href="#boomwinkel">Adopteer een boom</a>
<a href="#boomwinkel">Webwinkel</a>
<a href="#overons">Over ons</a>
<div class="dropdown">
<button class="dropbtn">Verdere informatie
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#diensten">Diensten</a>
<a href="#horeca">Horeca</a>
<a href="#gezondleven">Gezond leven</a>
</div>
</div>
<a href="#contacteer">Contacteer</a></text-align:>
</div>

<script>
window.onscroll = function() {myFunction()};

var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;

function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
</script>

</body>
</html>
 
Back
Top