I am trying to do a navigation bar with some <ul>and<li> but at this time I can position the elements in the order I want, I am learing how to postion elements and I am new at this css :/ I hope you guys can help me out.
#navbar {
width:100%;
height: 75px;
top : 20px;
position: absolute;
z-index: 999;
background-color: #fff;
opacity: 0.8;
}
.logo img {
height: 75px;
}
.navigation{
width: 100%;
height: 75px;
top :10px;
position: absolute;
z-index: 999;
}
ul {
list-style-type: none;
text-decoration: none;
}
li {
display: inline-block;
margin-left :200px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="navbar">
<div class="logo">
<img src="img/logo.png">
</div>
<div class="navigation">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>Services</li>
<li>About Us</li>
<li>Contacts</li>
<li>Partners</li>
</ul>
</div>
</div>
I have this so far but I want something like this
What I want to look like
The problem is when I try to style the li a { it doesnt let me to make only margin from the elements besides he give margin from everthing :/
body {
margin: 0;
background: #222;
font-family: 'Work Sans', sans-serif;
font-weight: 400;
}
.container {
width: 50%;
margin: 0 auto;
}
header {
background: #fff;
opacity: 0.8;
position: fixed !important;
top : 20px;
width: 100%;
z-index: 999;
}
header::after {
content: '';
display: table;
clear: both;
}
.logo {
float: left;
margin-left: 10%;
padding: 10px 0;
}
.logo img{
height: 60px;
}
nav {
float: right;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
margin-left: 60px;
padding-top: 30px;
position: relative;
}
nav a {
color: #444;
text-decoration: none;
text-transform: uppercase;
font-size: 14px;
}
nav a:hover {
color: #000;
}
nav a::before {
content: '';
display: block;
height: 5px;
background-color: #444;
position: absolute;
top: 0;
width: 0%;
transition: all ease-in-out 250ms;
}
nav a:hover::before {
width: 100%;
}
<header>
<div class="logo">
<img src="img/logo.png">
</div>
<div class="container">
<nav>
<ul>
<li>Home</li>
<li>Services</li>
<li>About Us</li>
<li>Contacts</li>
<li>Partners</li>
</ul>
</nav>
</div>
</header>
Here's a solution for you. I changed only the last two CSS rules, everything else is like in your code.
#navbar {
width: 100%;
height: 75px;
top: 20px;
position: absolute;
z-index: 999;
background-color: #fff;
opacity: 0.8;
}
.logo img {
height: 75px;
}
.navigation {
width: 100%;
height: 75px;
top: 10px;
position: absolute;
z-index: 999;
}
ul {
list-style-type: none;
text-decoration: none;
}
li {
display: inline-block;
margin-left: 50px;
}
li:first-child {
margin-left: 100px;
}
ul li a {
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div id="navbar">
<div class="logo">
<img src="img/logo.png">
</div>
<div class="navigation">
<ul>
<li><a class="active" href="#home">Home</a></li>
<li>Services</li>
<li>About Us</li>
<li>Contacts</li>
<li>Partners</li>
</ul>
</div>
</div>
Related
I'm recreating the navigation from this website but can't get the animations quite the same. It's all working but seems to be a little off.
so far I've tried to increase and decrease the transition timing but it didn't get it anywhere near the example.
const styleParent = (event) => {
let ancestor = document.querySelector('div.nav');
ancestor.classList[event.type === 'mouseenter' ? 'add' : 'remove']('servicesIsHovered');
};
let child = document.querySelector('li.three');
child.addEventListener('mouseenter', styleParent);
child.addEventListener('mouseleave', styleParent);
body {
font-family: acumin-pro, sans-serif;
font-size: 16px;
letter-spacing: .25px;
margin: 0;
}
a {
text-decoration: none;
}
.main {
width: 100%;
}
.section {
width: 100%;
background: #ededed;
}
.header {
position: relative;
display: flex;
width: 100%;
}
.nav {
width: 1100px;
margin: auto;
position: relative;
padding: 0 40;
transition: background-color 0.3s ease;
}
.nav li {
color: #000;
}
.nav li a {
cursor: pointer
}
.nav ul {
list-style: none;
padding: 0;
margin-bottom: 0;
width: fit-content;
}
.nav ul:hover li {
color: #6C6C6C;
padding-bottom: 20px;
}
.nav ul li:hover {
color: #000;
padding-bottom: 20px;
}
.nav li:last-child {
margin: 0;
}
.nav ul li {
display: inline-block;
padding: 0 35px 20px 0;
}
li:hover>.sub-menu {
height: 200px;
}
.sub-menu {
height: 0px;
overflow: hidden;
display: flex;
flex-direction: row;
position: absolute;
top: 100%;
background: #2E2E2E;
left: 0;
right: 0;
transition: height 0.5s ease;
}
.col-1-4 {
height: 100%;
width: 25%;
position: relative;
}
.service {
padding: 20%;
}
.nav.servicesIsHovered {
background-color: #272727;
}
<div class="header">
<div class="nav">
<ul>
<li>
<a class="one">Home</a>
</li>
<li>
<a class="two">About</a>
</li>
<li class="three">
<a class="">Services</a>
<div class="sub-menu">
<div class="col-1-4"></div>
<div class="col-1-4"></div>
<div class="col-1-4"></div>
<div class="col-1-4"></div>
</div>
</li>
<li>
<a class="four">Contact</a>
</li>
</ul>
</div>
</div>
The animation doesn't seem to be as smooth as from the website. Also, they don't seem to be as in sync.
How to put the picture in the left side of my navbar?
I can't seem to understand how it works- the picture is going up and the navbar is outside the div.
body {
margin: 0;
}
#navbar {
background-color: gray;
width: 100%;
height: 160px;
}
#logo {
width: 50%;
height: 50%;
}
ul {
list-style: none;
background-color: red;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
}
#navbar li {
display: inline;
}
#navbar li a {
display: inline-block;
padding: 10px;
font-size: 20px;
text-decoration: none;
}
<div class="container">
<div id="navbar"> <img class="logo" src="logo.gif">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
use this code
#navbar{
position: absolute;
right: 20px;
display: flex;
flex-direction: row;
justify-content: space-between;
}
In the case you want to use flexbox, you may try this:
favorite body {
margin: 0;
}
#navbar {
background-color: gray;
width: 100%;
height: 160px;
/*****************/
display:flex;
justify-content:space-between;
align-items:center;
/*****************/
}
#logo {
width: 50%;
height: 50%;
}
ul {
list-style: none;
background-color: red;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
}
#navbar li {
display: inline;
}
#navbar li a {
display: inline-block;
padding: 10px;
font-size: 20px;
text-decoration: none;
}
<div class="container">
<div id="navbar"> <img width="40" class="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/apple.png">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
1-Access class logo by '.'
2-apply positioning to class logo as i applied and set height and width of class
3- set width of also
heres my code
favorite body {
margin: 0;
}
#navbar {
background-color: gray;
width: 100%;
height: 160px;
/*****************/
display:flex;
justify-content:space-between;
align-items:center;
/*****************/
}
.logo {
position :relative;
top: 0px;
width: 10%;
height: 27%;
}
ul {
list-style: none;
background-color: red;
width: 90%;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
}
#navbar li {
display: inline;
}
#navbar li a {
display: inline-block;
padding: 10px;
font-size: 20px;
text-decoration: none;
}
<div class="container">
<div id="navbar"> <img width="40" class="logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/apple.png">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
down vote favorite body {
margin: 0;
}
#navbar {
background-color: gray;
width: 100%;
height: 160px;
}
#logo {
width: 50%;
height: 50%;
}
ul {
list-style: none;
background-color: red;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
}
#navbar li {
display: inline;
}
#navbar li a {
display: inline-block;
padding: 10px;
font-size: 20px;
text-decoration: none;
}
<div class="container">
<div id="navbar"> <img class="logo" src="logo.gif">
<ul>
<li>Home</li>
<li>Game Info</li>
<li>Gameplay</li>
<li>Media</li>
</ul>
</div>
</div>
use this css
ul {
list-style: none;
background-color: red;
margin: 0;
padding: 0;
text-align: center;
overflow: hidden;
display: inline-block;
}
I'm trying to center the text in my navbar and my social links too, but I just can't. I've searched on google, tried everything, it doesn't work. I'm a beginner btw. I've tried every solution I've found on google for about 1hr and all I did is getting mad. damn
I don't get it. In the snippet everything works fine, it is centered as I want. But in my PC, it looks like this: pic
Can you explain to me why does it happen?
//Header
#header {
position: absolute;
top: 0;
}
//bara navigatie
#bara {
width: 100%;
margin: 0;
}
#bara-wrap {
position: absolute;
top: 0;
width: 100%;
background: #111111;
}
.butoane ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.butoane li {
float: left;
font-weight: bold;
margin-right: 4em;
font-size: 1em;
}
.butoane li a {
display: block;
color: white;
text-decoration: none;
}
.logo {
width: 11em;
margin-left: 45em;
float: left;
}
.social {
color: white;
float: right;
display: inline-block;
font-weight: bold;
}
<header id="header" style="opacity: 1; top: 0px;">
<div id="bara-wrap">
<img src="img/logo.png" alt="LOGO" class="logo" />
<nav id="bara">
<ul class="butoane">
<li>home</li>
<li>about</li>
<li>skills</li>
<li>contact</li>
</ul>
</nav>
<ul class="social">
<li class="facebook">facebook</li>
</ul>
</div>
</header>
Remove the butoane class and copy the posted right now css file and paste it into your css file....
//Header
#header {
position: absolute;
top: 0;
}
//bara navigatie
#bara {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
#bara-wrap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 70px;
background: #111111;
}
img{
margin-top: 25px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
ul li {
margin-top: 25px;
float: left;
font-weight: bold;
margin-right: 4em;
font-size: 1em;
}
li a {
display: block;
color: white;
text-decoration: none;
}
.logo {
width: 11em;
margin-left: 100px;
float: left;
}
.social {
position: absolute;
right: 20%;
top: 0;
color: white;
float: right;
display: inline-block;
font-weight: bold;
}
use this one i made some changes in your html and css.
html
<header id="header" style="opacity: 1; top: 0px;">
<div id="bara-wrap">
<img src="img/logo.png" alt="LOGO" class="logo" />
<nav id="bara">
<ul class="butoane">
<li>home</li>
<li>about</li>
<li>skills</li>
<li>contact</li>
</ul>
<ul class="social">
<li class="facebook">facebook</li>
</ul>
</nav>
</div>
</header>
css
#header {
position: absolute;
top: 0;
}
//bara navigatie
#bara {
padding-right: 15px;
padding-left: 15px;
margin-right: auto;
margin-left: auto;
}
#bara-wrap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 70px;
background: #111111;
}
.butoane ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.butoane li {
float: left;
font-weight: bold;
margin-right: 4em;
font-size: 1em;
}
.butoane li a {
display: block;
color: white;
text-decoration: none;
}
.logo {
width: 11em;
margin-left: 100px;
float: left;
}
.social {
position: absolute;
right: 20%;
top: 0;
color: white;
float: right;
display: inline-block;
font-weight: bold;
}
Is it possible to overlap images in the navigation bar, without getting the background color and some stuffs? The image or the logo itself shouldn't have any background-color (that is inherited) and should have overlapped the navigation bar. I'm looking for an output like this.
This is the CodePen link, try it out
HTML Codes:
<nav>
<ul>
<li>
<span class="logo">
<img src="https://static.wixstatic.com/media/c86d4e_46042d8a0d99473f82209f03ab4dd146~mv2.gif" alt="Star of Hope" title="Star of Hope" id="logo">
</span>
</li>
<li>Home</li>
<li>Our School</li>
<li>Academics</li>
<li>Lesson and Quizzes</li>
<li>Event & News</li>
<li>Grades</li>
</ul>
</nav>
CSS Codes:
* {
margin: 0px;
}
nav {
width: 100%;
height: 100%;
text-align: center;
font-weight: lighter;
font-size: 0.95em;
font-family: Century Gothic;
text-transform: uppercase;
list-style-type: none;
overflow: hidden;
background-color: #343F64;
}
ul {
margin: 0;
padding: 0;
width: 100%;
}
li {
display: inline;
float: left;
}
li a {
display: block;
padding: 14px 16px;
background-color: #343F64;
color: white;
text-decoration: none;
padding-top: 25px;
padding-bottom: 25px;
}
.active {
color: #E9DB89;
}
li img {
float: left;
}
img {
margin-left: 75px;
}
#logo {
float:left;
z-index: 1000;
}
I have made an edit to your code to get the results
* {
margin: 0px;
}
nav {
width: 100%;
height: 70px;
text-align: center;
font-weight: lighter;
font-size: 0.95em;
font-family: Century Gothic;
text-transform: uppercase;
list-style-type: none;
overflow: hidden;
background-color: #343F64;
position: relative;/*change here*/
}
ul {
margin: 0;
padding: 0;
width: 100%;
position: absolute;/*change here*/
right: -25%;/*change here*/
}
li {
display: inline;
float: left;
}
li a {
display: block;
padding: 14px 16px;
background-color: #343F64;
color: white;
text-decoration: none;
padding-top: 25px;
padding-bottom: 25px;
}
.active {
color: #E9DB89;
}
li img {
float: left;
}
img {
margin-left: 75px;
}
.line {
width: 100%;
height: 50px;
border-bottom: 1px solid #111;
}
#logo {
float:left;
z-index: 1000;
position: absolute;/*change here*/
}
<!--move logo outside nav-->
<span class="logo">
<img src="https://static.wixstatic.com/media/c86d4e_46042d8a0d99473f82209f03ab4dd146~mv2.gif" alt="Star of Hope" title="Star of Hope" id="logo">
</span>
<nav>
<ul>
<li>Home</li>
<li>Our School</li>
<li>Academics</li>
<li>Lesson and Quizzes</li>
<li>Event & News</li>
<li>Grades</li>
</ul>
</nav>
<div class="line"></div>
Here's another variation, not using absolute positioning:
HTML:
<div id="header_container">
<div id="header">
<div class="logo">
<img src="https://static.wixstatic.com/media/c86d4e_46042d8a0d99473f82209f03ab4dd146~mv2.gif" alt="Star of Hope" title="Star of Hope" id="logo">
</div>
<div class="nav">
<ul>
<li>Home</li>
<li>Our School</li>
<li>Academics</li>
<li>Lesson and Quizzes</li>
<li>Event & News</li>
<li>Grades</li>
</ul>
</div>
</div>
</div>
CSS:
* {
margin: 0px;
}
#header_container {
width: 100%;
height: 100px;
background-color: #343F64;
}
#header {
margin: 0 auto;
width: 1200px;
}
.nav {
float: left;
margin-top: -100px;
margin-left: 350px;
height: 100px;
text-align: center;
font-weight: lighter;
font-size: 0.95em;
font-family: Century Gothic;
text-transform: uppercase;
list-style-type: none;
overflow: hidden;
}
ul {
margin: 0;
padding: 0;
width: 100%;
}
li {
display: inline;
float: left;
}
li a {
display: block;
padding: 14px 16px;
background-color: #343F64;
color: white;
text-decoration: none;
padding-top: 25px;
padding-bottom: 25px;
}
.active {
color: #E9DB89;
}
li img {
float: left;
}
img {
margin-left: 75px;
}
.logo {
float:left;
z-index: 1000;
}
I want to create a dropdown menu, that works with mobile (i'm using media queries) platforms.
I am able to create the media query to make it work only on 320/480/720px but I am not able to create this sub-menu class, has dropdown menu.
Any tips or tutorials, I could see? Any help would be appreciated...
HTML
<div class="header">
<div class="menu">
<ul>
<li><img src="www.wemadeyou.pt/img/menu.png" alt="Menu" width="22" height="17"/>
<ul class="sub-menu">
<li>Home</li>
<li>Portfolio</li>
<li>Services</li>
<li>About</li>
<li>Contacts</li>
</ul>
</li>
</ul>
</div>
</div>
CSS
.header{
position: relative;
width: 100%;
height: 50px;
margin: 0 auto;
padding: 0;
display: block;
text-align: center;
margin-bottom: 25px;
background-color: rgba(0, 0, 0, 0.2);
}
.menu{}
Maybe not the best solution for you but I did my best.
https://codepen.io/leobezr/pen/VweOELv
Note: Use devTools to change window size.
Note: You might need to use the following code
<body>
<div class="header">
<div class="logo">LOGO</div>
<div class="navigation">
<ul class="sub-menu">
<li>Home</li>
<li>Portfolio</li>
<li>Services</li>
<li>About</li>
<li>Contacts</li>
</ul>
</div>
<div class="mobileController" style="display: none;">
<a href="#" role="button" action="openMenu">
<span class="sandwich">
<span></span>
</span>
</a>
</div>
</div>
<div class="content">
Hello world
</div>
</body>
#import url('https://fonts.googleapis.com/css2?family=Montserrat:wght#300;500&display=swap');
body {
font-family: 'Montserrat', sans-serif;
font-size: 15px;
min-height: calc(100vh * 2);
}
.header {
display: flex;
flex: 1;
flex-direction: row;
justify-content: space-around;
align-items: center;
z-index: 1000;
height: 40px;
background: #ecf5ff;
}
.header:not(.fixed) {
position: relative;
}
.header.fixed {
position: fixed;
left: 0;
top: 0;
width: 100%;
animation: fadeDown 400ms 1 ease-in;
animation-fill-mode: forwards;
}
.header .navigation ul {
padding: 0;
margin: 0;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center
}
.header .navigation li {
display: flex;
padding: 12px 6px;
}
.header .navigation li a {
text-decoration: none;
font-weight: 600;
position: relative;
color: #222;
}
.header .navigation li a:before {
content: "";
position: absolute;
left: 0;
bottom: 5px;
opacity: 0;
height: 2px;
width: 100%;
display: block;
background: #222;
}
.header .navigation li a:hover {
filter: brightness(1.1);
transition: all 200ms ease-in;
}
.header .navigation li a:hover:before {
opacity: 1;
transform: translateY(7px);
transition: all 200ms ease-in;
}
.mobileController .sandwich span {
display: block;
width: 35px;
height: 2px;
background: #222;
position: relative;
}
.mobileController .sandwich span:before {
content: "";
width: inherit;
height: inherit;
position: absolute;
left: 0;
top: -6px;
background: inherit;
}
.mobileController .sandwich span:after {
content: "";
width: inherit;
height: inherit;
position: absolute;
left: 0;
top: 6px;
background: inherit;
}
.mobileController>a {
display: flex;
height: 20px;
align-content: center;
align-items: center;
cursor: pointer;
}
.mobileController>a:hover {
transform: scale(.9);
transition: all 200ms ease-in;
}
#media (max-width: 992px) {
.navigation {
display: none;
position: absolute;
left: 0;
top: 40px;
background: #fff;
width: 100%;
z-index: -1;
border-bottom: solid 1px #ebebeb;
}
.navigation.view {
display: block !important;
animation: slideIn 400ms ease-in 1;
animation-fill-mode: forwards;
}
.navigation ul {
flex-direction: column !important;
}
.mobileController {
display: block !important;
}
}
#keyframes fadeDown {
0% {
opacity: 0;
transform: translateY(-100%);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
#keyframes slideIn {
0% {
opacity: 0;
display: block !important;
transform: translateX(-100%);
}
100% {
opacity: 1;
display: block !important;
transform: translateX(0);
}
}
window.addEventListener("scroll", () => {
const $header = document.querySelector(".header");
const headerHeight = $header.offsetHeight;
if (window.pageYOffset >= Math.round(headerHeight * 2)) {
$header.classList.add("fixed");
} else {
$header.classList.remove("fixed");
}
})
!function(){
window.addEventListener("load", init);
}()
function init() {
const $button = document.querySelector(".mobileController");
const $navigation = document.querySelector(".navigation");
$button.addEventListener("click", () => $navigation.classList.toggle("view"));
}
Ok #uniqezor I do smth^^
Look:
<div class="header">
<div class="menu">
<ul>
<li><img src="www.wemadeyou.pt/img/menu.png" alt="Menu" width="22" height="17"/>
<ul class="sub-menu">
<li>Home</li>
<li>Portfolio</li>
<li>Services</li>
<li>About</li>
<li>Contacts</li>
</ul>
</li>
</ul>
</div>
<div class="topmenu container clearfix">
<div class="top">
<a href="#" class="logo">
<img src="http://wemadeyou.pt/img/logo.png" alt="WeMadeYou - Future Together" class="logo" width="65"
height="21" itemprop="image"/>
</a>
<span class="textbox">This is what we made of you!</span>
<div class="clear"></div>
<div class="nav">
<ul>
<li>Home</li>
<li>Portfolio</li>
<li>Services</li>
<li>About</li>
<li>Contacts</li>
</ul>
</div>
</div>
</div>
</div>
.header{
position: relative;
width: 100%;
height: 50px;
margin: 0 auto;
padding: 0;
display: block;
text-align: center;
margin-bottom: 25px;
background-color: rgba(0, 0, 0, 0.2);
}
.logo{
float: left;
margin-top: 6px;
margin-right: 10px;
margin-left: 5px;
}
.topmenu{
text-align: center;
height: 50px;
margin: 0 auto;
}
.top{
display: inline;
padding: 0;
}
span.textbox{
display: inline;
float: left;
font-size: 13px;
margin-top: 14px;
color: white;
font-weight: bold;
}
.nav{
float: right;
display: inline;
margin: 0;
padding: 0;
margin-left: auto;
margin-right: auto;
}
.nav ul{margin: 0;}
.nav li{
width: 100px;
height: 50px;
display: inline-block;
float: right;
margin-right: 5px;
}
.nav li a{
height: 40px;
color: white;
font-size: 12px;
font-weight: bold;
text-decoration: none;
text-transform: uppercase;
line-height: 48px;
padding: 16px 20px 14px 20px;
}
.nav li a#home{
height: 40px;
padding: 16px 30px 14px 30px;
}
.nav li a:hover{border-bottom:thick solid #fff;}
.menu{display: none; }
#media screen and (max-width: 294px) {
span.textbox {
font-size: 10px;
}}
#media screen and (max-width: 859px) {
.clear{clear: both}
.nav{float: left;max-width: 100%;width: 100%;}
.nav li {display: block;width: 100%;
float: none;margin: 0 auto;}
.nav ul{padding: 0}
.nav li a{color:black}
}