Skip to content

Instantly share code, notes, and snippets.

@tiagocordeiro
Last active April 25, 2022 08:14
Show Gist options
  • Save tiagocordeiro/0d43421ef0483445dc842aaca6341d90 to your computer and use it in GitHub Desktop.
Save tiagocordeiro/0d43421ef0483445dc842aaca6341d90 to your computer and use it in GitHub Desktop.
Responsive Topnav Example (Only CSS)
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<style>
</style>
</head>
<body>
<div class="topnav">
<a href="#home" class="active"><img class="logo" src="https://www.programaria.org/wp-content/uploads/2015/08/logo-04.png" alt="PrograMaria"></a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>
<div style="padding-left:16px">
<h2>Responsive Topnav Example</h2>
<p>Resize the browser window to see how it works.</p>
</div>
</body>
</html>
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.logo {max-width: 100px;}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.active {
background-color: white;
color: black;
padding: 0px;
}
.topnav .icon {
display: none;
}
@media screen and (max-width: 600px) {
.topnav {position: relative;}
.topnav a {
float: none;
display: block;
text-align: center;
}
.topnav a.icon {
float: right;
display: block;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment