I am trying to create navbar with image logo, Title, Navigation Links and some social links also. I have created 4 divs for each. Whenever I decrease the screen width using responsive a white color appears in the nav bar and increases to the left as i decrease the screen width.
Here are some pics also:
You can aslo see width on top of the picture
Here the problem as i decreases the screen width
/* Reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#font-face {
font-family: PollerOne;
src: url('../../fonts/Poller_One/PollerOne-Regular.ttf');
}
/* Styling Navigation Bar */
#navbar {
display: flex;
position: relative;
align-items: center;
height: 65px;
width: 100%;
}
#navbar::before {
content: "";
position: absolute;
background-color: #262626;
height: 65px;
width: 100%;
z-index: -2;
}
.navbar {
color: white;
margin: 7px 7px;
}
/* Styling Logo */
#logo {
background-color: black;
height: 45px;
width: 45px;
min-width: 45px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
#logo img {
filter: invert();
width: 25px;
}
/* Styling Title */
#title {
font-family: PollerOne;
min-width: 160.5px;
font-size: 1.4rem;
margin-left: 0px;
}
/* Styling Nav links */
#nav-links {
margin: 0 auto;
}
#nav-links ul {
list-style-type: none;
display: flex;
}
.nav-links {
font-size: 20px;
margin: 0 20px;
/* padding: 5px 10px; */
position: relative;
cursor: pointer;
}
/* Animation Under Nav Links */
.nav-links::after {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: -4px;
background: linear-gradient(white 0 0) center/0% 100% no-repeat;
display: block;
}
:hover.nav-links::after {
animation: pulse 300ms linear;
animation-fill-mode: forwards;
}
#keyframes pulse {
to {
background-size: 100% 100%;
}
}
/* Styling Social Links */
#social-links {
margin-left: auto;
display: flex;
}
.social-links {
width: 30px;
height: 30px;
border-radius: 11px;
display: flex;
align-items: center;
justify-content: center;
margin: 0 5px;
}
.social-links img {
width: 27px;
transition: all 200ms ease;
}
.social-links img:hover {
transform: scale(1.5)
}
/* Utility Class */
<div id="navbar">
<div id="logo" class="navbar">
<img src="./img/bag.png" alt="">
</div>
<div id="title" class="navbar">Meals Point</div>
<div id="nav-links" class="navbar">
<ul>
<li class="nav-links"><a id="link-1">Home</a></li>
<li class="nav-links"><a id="link-2">About</a></li>
<li class="nav-links"><a id="link-3">Services</a></li>
<li class="nav-links"><a id="link-4">Recipes</a></li>
<li class="nav-links"><a id="link-5">Contact</a></li>
</ul>
</div>
<div id="social-links" class="navbar">
<a class="social-links" href="https://www.twitter.com"><img src="./img/twitter.png" id="link-1"></a>
<a class="social-links" href="https://www.facebook.com"><img src="./img/facebook.png" id="link-2"></a>
<a class="social-links" href="https://www.instagram.com"><img src="./img/instagram.png" id="link-3"></a>
</div>
</div>
Try to add to #navbar float: left; :
/* Reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#font-face {
font-family: PollerOne;
src: url('../../fonts/Poller_One/PollerOne-Regular.ttf');
}
/* Styling Navigation Bar */
#navbar {
display: flex;
position: relative;
align-items: center;
height: 65px;
min-width: 100%;
float: left;
}
#navbar::before {
content: "";
position: absolute;
background-color: #262626;
height: 65px;
min-width: 100%;
z-index: -2;
}
.navbar {
color: white;
margin: 7px 7px;
}
/* Styling Logo */
#logo {
background-color: black;
height: 45px;
width: 45px;
min-width: 45px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
#logo img {
filter: invert();
width: 25px;
}
/* Styling Title */
#title {
font-family: PollerOne;
min-width: 160.5px;
font-size: 1.4rem;
margin-left: 0px;
}
/* Styling Nav links */
#nav-links {
margin: 0 auto;
}
#nav-links ul {
list-style-type: none;
display: flex;
}
.nav-links {
font-size: 20px;
margin: 0 20px;
/* padding: 5px 10px; */
position: relative;
cursor: pointer;
}
/* Animation Under Nav Links */
.nav-links::after {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: -4px;
background: linear-gradient(white 0 0) center/0% 100% no-repeat;
display: block;
}
:hover.nav-links::after {
animation: pulse 300ms linear;
animation-fill-mode: forwards;
}
#keyframes pulse {
to {
background-size: 100% 100%;
}
}
/* Styling Social Links */
#social-links {
margin-left: auto;
display: flex;
}
.social-links {
width: 30px;
height: 30px;
border-radius: 11px;
display: flex;
align-items: center;
justify-content: center;
margin: 0 5px;
}
.social-links img {
width: 27px;
transition: all 200ms ease;
}
.social-links img:hover {
transform: scale(1.5)
}
/* Utility Class */
<div id="navbar">
<div id="logo" class="navbar">
<img src="./img/bag.png" alt="">
</div>
<div id="title" class="navbar">Meals Point</div>
<div id="nav-links" class="navbar">
<ul>
<li class="nav-links"><a id="link-1">Home</a></li>
<li class="nav-links"><a id="link-2">About</a></li>
<li class="nav-links"><a id="link-3">Services</a></li>
<li class="nav-links"><a id="link-4">Recipes</a></li>
<li class="nav-links"><a id="link-5">Contact</a></li>
</ul>
</div>
<div id="social-links" class="navbar">
<a class="social-links" href="https://www.twitter.com"><img src="./img/twitter.png" id="link-1"></a>
<a class="social-links" href="https://www.facebook.com"><img src="./img/facebook.png" id="link-2"></a>
<a class="social-links" href="https://www.instagram.com"><img src="./img/instagram.png" id="link-3"></a>
</div>
</div>
Try to add
For Left Align:class = "navbar-nav mr-auto"
For Right Align:class = "navbar-nav ml-auto"
For Center Align:class = "navbar-nav mx-auto"
Related
So basically I am trying to make a search engine page. The hr does not want to align in the center. On top of that when I resize the page in height it sends the text in the middle and the search bar diagonally left. I am unsure what I am doing wrong. I find positioning in CSS so so hard.
I am unsure on if I am positioning correctly. I was trying to lock my content down by using vh and vw. However I have a lot of trouble locking everything down vertically.
Live Preview" https://codepen.io/thanksfortheride136/project/editor/DYaryO
#indexbody {
background-image: url("/school.jpg");
background-size: 100% auto;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
a {
text-decoration: none;
}
/*controls size of logo link box*/
.logo a {
display: block;
height: auto;
}
li {
list-style: none;
}
/* NAVBAR STYLING STARTS */
.navbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px;
background-color: #2f2e2e;
color: #2f2e2e;
font-family: 'Open Sans';
z-index: 1;
}
.navbaratlus {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px;
background-color: transparent;
color: #2f2e2e;
font-family: 'Open Sans';
z-index: 1;
}
.nav-links a {
color: #fff;
}
/* LOGO */
.logo img {
width: 230px;
height: 75px;
}
/* NAVBAR MENU */
.menu {
display: flex;
gap: 1em;
font-size: 20px;
z-index: 1;
}
.menu li:hover {
background-color: #1a1a1a;
transition: 0.1.5s ease;
}
/*everytime i adjust sizing i usually need to adjust sizing on the dropdown menu too*/
.menu li {
padding: 25px 24px;
padding-left: 5px;
border-left: 1px solid white;
display: inline-block;
width: 200px;
z-index: 1;
}
.home {
border-left: 1px solid white;
}
/* DROPDOWN MENU */
.classes {
position: relative;
}
.dropdown {
background-color: #1a1a1a;
padding-top: 1em;
position: absolute;
/*WITH RESPECT TO PARENT*/
display: none;
top: 70px;
}
.dropdown li+li {
margin-top: 10px;
}
.dropdown li {
padding: 0.5em 1em;
width: 8em;
}
.dropdown li:hover {
background-color: #2f2e2e;
width: 100%;
}
.classes:hover .dropdown {
display: block;
}
/*RESPONSIVE NAVBAR MENU STARTS*/
/* CHECKBOX HACK */
input[type=checkbox] {
display: none;
}
/*HAMBURGER MENU*/
.hamburger {
display: none;
font-size: 24px;
user-select: none;
}
/* APPLYING MEDIA QUERIES */
#media (max-width: 768px) {
.menu {
display: none;
position: absolute;
background-color: teal;
right: 0;
left: 0;
text-align: center;
padding: 16px 0;
}
.menu li:hover {
display: inline-block;
background-color: #4c9e9e;
transition: 0.3s ease;
}
.menu li+li {
margin-top: 12px;
}
input[type=checkbox]:checked~.menu {
display: block;
}
.hamburger {
display: block;
}
.dropdown {
left: 50%;
top: 30px;
transform: translateX(35%);
}
.dropdown li:hover {
background-color: #4c9e9e;
}
}
.footercontainer {
position: fixed;
bottom: 0;
width: 100%;
height: 20px;
background-color: #2f2e2e;
border: 5px solid green;
}
.atlasbar[type=text] {
padding: 6px;
font-size: 17px;
font-family: 'open sans';
color: white;
display: block;
position: absolute;
height: 40px;
width: 35%;
z-index: 1;
top: 30vh;
left: 50vh;
right: 50vh;
box-shadow: inset 0 0 50px #000, /* inner color*/
inset 20px 0 80px #000, /* inner left short*/
inset -20px 0 80px #0ff, /* inner right short*/
inset 20px 0 300px #f0f, /* inner left broad*/
inset -20px 0 300px #0ff, /* inner right broad*/
0 0 10px #fff, /* outer color*/
-1px 0 10px #f0f, /* out left color*/
1px 0 10px #0ff; /* outer right color*/
}
::placeholder {
color: white;
}
.atlascontainer {
display: block;
height: 35vh;
width: 100vw;
position: absolute;
border: 1px solid red;
}
.title {
font-family: 'Akshar', sans-serif;
color: white;
font-size: 100px;
text-align: center;
display: block;
position: absolute;
width: 35%;
z-index: 1;
top: 10vh;
left: 50vh;
right: 50vh;
}
hr {
color: white;
display: block;
z-index: 1;
margin-top: 27vh;
margin-left: 50vw;
margin-right: 50vw;
width: 30%;
position: absolute;
}
p {
font-family: 'Open Sans', sans-serif;
color: white;
text-align: center;
display: block;
position: absolute;
width: 35%;
top: 23vh;
left: 50vh;
right: 50vh;
z-index: 1;
}
.atlasimage {
display: block;
position: absolute;
width: 50%;
height: 100%;
right: 0;
top: 0;
z-index: -1;
}
body {
height: 100vh;
}
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght#300&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Akshar&family=Open+Sans:wght#300&display=swap" rel="stylesheet">
<nav class="navbaratlus">
<!-- LOGO -->
<div class="logo">
</div>
<!-- NAVIGATION MENU -->
<ul class="nav-links">
<!-- USING CHECKBOX HACK -->
<input type="checkbox" id="checkbox_toggle" />
<label for="checkbox_toggle" class="hamburger">☰</label>
<!-- NAVIGATION MENUS -->
<div class="menu">
<li class='home'>Home</li>
<li class="classes">Classes
<!-- DROPDOWN MENU -->
<ul class="dropdown">
<li>AP CS</li>
<li>STEM</li>
<li>Media Arts</li>
<li> Physics</li>
<li>Tech 8</li>
</ul>
</li>
<li>Atlas</li>
<li>Curriculum</li>
<li>Contact</li>
</div>
</ul>
</nav>
<div class='atlascontainer'>
<input type="text" placeholder="Search.." class="atlasbar">
<h1 class='title'>ATLAS</h1>
<p>A Technology Learning Aid System</p>
<hr>
</div>
<img src="editedatlas.png" alt="" class='atlasimage'>
<div class='footercontainer'></div>
This page is a grid container with some images as posts-list, header, and left menu:
JSFiddle1
When I hover over images two links: "comments" and "view posts" would appear. I want to use the CSS and when I click on either of these two it leads me to something like this:
JSFiddle
I wanted to use display: none; but I don't know where should I put it.
if I understand your question correctly, this is a possible solution to your problem.
function changeContainer(){
if($('.grid-container-before').css('visibility') === 'visible') {
$('.grid-container-before').css('visibility','hidden');
$('.grid-container-before').css('display','none');
$('.grid-container-after').css('visibility','visible');
$('.grid-container-after').css('display','grid');
}
}
body {
padding-top: 73px;
overflow-y: hidden;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
/* ------------ PAGE SCROLLBAR ------------ */
*::-webkit-scrollbar {
width: 2px;
}
*::-webkit-scrollbar-track {
background: white;
}
*::-webkit-scrollbar-thumb {
background-color: grey;
border-radius: 20px;
height: 2px;
}
/* ------------ navbar ------------ */
.header {
display: flex;
position: fixed;
background-color: white;
width: 100%;
justify-content: space-between;
z-index: 7;
font-family: Libre Franklin;
top: 0;
left: 0;
}
.header-flex-list {
display: flex;
margin-top: 10px;
justify-content: flex-end;
flex: 50%;
}
.header-list {
list-style: none;
display: flex;
}
.header-list a {
text-decoration: none;
color: #000;
font-size: 12px;
padding: 0px 20px 0px 20px;
}
.top-icon-container {
display: flex;
padding: 10px 50px;
flex-wrap: wrap;
}
.icon-column {
width: 10%;
border-radius: 50px;
}
.p-column {
width: 28%;
padding-left: 10px;
}
#top-bar-icon {
display: block;
max-width: 100%;
height: auto;
object-fit: cover;
border-radius: 50px;
border: 2px solid #73AD21;
}
/* ------------ LEFT MENU ------------ */
.container {
display: flex;
justify-content: space-between;
height: 100vh;
}
.left-menu {
width: 18%;
order: 1;
height: 100vh;
/* overflow-y: scroll; */
padding: 0px 0px 10px 45px;
}
.menu-list {
list-style: none;
line-height: 2.5rem;
/* display: flex;
flex-direction: column; */
margin-left: -25px;
}
.menu-list a {
text-decoration: none;
}
/* ------------ MAIN POSTS ------------ */
.main-posts {
width: 100%;
order: 2;
padding: 0px 20px 0px 20px;
overflow-y: auto;
text-align: center;
scrollbar-width: thin;
scrollbar-color: grey white;
}
/* ------------ MAIN POSTS LISTS ------------ */
.grid-container-before {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(480px, 1fr));
grid-gap: 1rem;
width: 100%;
margin: 0 auto;
margin-bottom: 6rem;
visibility: visible;
}
.grid-container-after {
display: grid;
grid-template-columns: 80% 1fr;
grid-gap: 10px;
height: 300px;
visibility: hidden;
display:none;
}
.box {
background-color: #20262e;
color: #fff;
border-radius: 3px;
padding: 20px;
font-size: 14px;
}
.posts {
display: flex;
}
.img__wrap {
position: relative;
}
.posts-image {
height: 350px;
width: 100%;
object-fit: cover;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: white;
color: #000;
visibility: hidden;
opacity: 0;
/* transition effect. not necessary */
transition: opacity 0.2s, visibility 0.2s;
}
.text {
color: white;
font-size: 15px;
position: absolute;
top: 50%;
left: 50%;
width: 100%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.text a {
color: #000;
text-decoration: none;
padding-right: 20px;
}
[data-title]::after {
content: attr(data-title);
background-color: #000;
color: #fff;
font-size: 13px;
;
position: absolute;
padding: 10px;
bottom: -3.6em;
left: 50%;
white-space: nowrap;
box-shadow: 1px 1px 3px #222222;
opacity: 0;
border: 1px solid #111111;
z-index: 99999;
visibility: hidden;
}
[data-title]:hover::after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title] {
position: relative;
}
.img__wrap:hover .overlay {
visibility: visible;
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<head>
<link href="//fonts.googleapis.com/css?family=Karla|Syne|Libre+Franklin|Bai+Jamjuree|Chakra+Petch|Gotu" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<!------------ TOP MENU ------------>
<header id="header" class="header">
<div id="top-container" class="top-icon-container">
<div class="icon-column">
<img id="top-bar-icon" src="https://s4.uupload.ir/files/top-bar-icon_ensh.png" alt="my logo:)">
</div>
<div class="p-column">
<p>Name it what u want!</p>
</div>
</div>
<div class="header-flex-list">
<ul class="header-list">
<li>TERMS OF USE</li>
<li>HAVE A QUESTION</li>
<li>ABOUT ME</li>
</ul>
</div>
</header>
<body>
<div class="container">
<!------------ LEFT MENU ------------>
<nav id="menu" class="left-menu">
<p style="text-decoration: none; color: black;">Filter by:</p>
<ul class="menu-list">
<li><a>Popular pages</a></li>
<li><a>About pages</a></li>
<li><a>Character pages</a></li>
<li><a>Music pages</a></li>
</ul>
</nav>
<!------------ MAIN POSTS ------------>
<section id="main-content" class="main-posts">
<div class="grid-container-before">
<div class="img__wrap">
<img class="posts-image" src="https://www.webdevelopersnotes.com/wp-content/uploads/random-image-display-using-javascript-2.png" alt="project" />
<div class="overlay">
<div class="text">
<button href="#" data-title="comments" onclick="changeContainer()">
<i class="fa fa-comments fa-fw"></i>comment</button>
<button href="#" data-title="view post" onclick="changeContainer()">
<i class="fa fa-external-link fa-fw"></i></button>
</div>
</div>
</div>
</div>
<div class="grid-container-after">
<div class="box a">A</div>
<div class="box b">B</div>
</div>
</section>
</div>
</body>
Here is what I see for my website:
website
As the image is below Navigation Bar, I want this to center vertically in my responsive website, similar to this website: https://www.ownhour.co.kr/#;
I have added width and height as 100% in internal image stylesheet and added margin and block in external CSS. After inspecting with the mobile version, it seems like the image is sitting at the top with a huge gap at the bottom.
Here is what I see for my website:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="monday.css">
<title>J[a]son</title>
</head>
<body>
<nav>
<div class = "logo">
<h4>J[a]son</h4>
</div>
<ul class = "nav-links">
<li>
HOME
</li>
<li>
PHOTOGRAPHY
<ul class="sub-menu">
<li>Colour</li>
<li>Black</li>
</ul>
</li>
<li>
CODING
</li>
<li>
ABOUT
</li>
</ul>
<div class= "burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="testing.js"></script>
<img class="main_car" src="Photos/main_car.jpg" alt="car" width="100%" height="100%"/>
<!--<p>June, 2020. Sunshine Coast, BC, Canada </p>-->
</body>
</html>
CSS
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
nav {
display: flex;
justify-content: space-between;
/*padding-right: 2em;*/
padding-left: 2em;
padding-top: 2em;
padding-bottom: 1.5em;
align-items: center;
min-height: 8vh;
background-color: black;
/*font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;*/
font-family: 'Poppins', sans-serif;
}
.logo {
color: rgb(240, 235, 235);
font-size: 20px;
text-transform: uppercase;
letter-spacing: 5px;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: white;
text-decoration: none;
letter-spacing: 1px;
font-weight: bold;
font-size: 11px;
/*padding: 5px 5px;*/
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: white;
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
#media screen and (max-width:950px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
padding-right: 2em;
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relative;
}
}
.nav-active {
transform: translate(0%);
}
The question is how to center the car image and remain responsive.
As I understand it (and this may need adjustment for your particular case) the requirement is for the car image to fill space but not leave a huge gap underneath before the footers are reached.
To do this in this case I've set the body element to flex so that once it's decided what is needed space-wise for the navbar and footer it can fill the remaining space with the car.
I initially tried to do this with object-fit: contain and object-position: center within a wrapper around the car img. However, I could not make this work and instead I've removed the car image and set it as a background to a div instead and allowed this div to fill up any remaining space on the screen.
Here's the snippet.
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
display: flex;
flex-direction: column;
height: 100vh;
}
nav {
display: flex;
justify-content: space-between;
/*padding-right: 2em;*/
padding-left: 2em;
padding-top: 2em;
padding-bottom: 1.5em;
align-items: center;
min-height: 8vh;
background-color: black;
/*font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;*/
font-family: 'Poppins', sans-serif;
}
.logo {
color: rgb(240, 235, 235);
font-size: 20px;
text-transform: uppercase;
letter-spacing: 5px;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 30%;
}
.nav-links li {
list-style: none;
}
.nav-links a {
color: white;
text-decoration: none;
letter-spacing: 1px;
font-weight: bold;
font-size: 11px;
/*padding: 5px 5px;*/
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
background-color: white;
margin: 5px;
transition: all 0.3s ease;
}
#media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
#media screen and (max-width:950px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
padding-right: 2em;
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relative;
}
}
.nav-active {
transform: translate(0%);https://ahweb.org.uk/car.png
}
.main_car_wrapper {
background-image: url(https://ahweb.org.uk/car.png);
background-repeat: no-repeat no-repeat;
background-position: center center;
background-size: contain;
width: 100%;
flex: 1 1 auto;
}
</style>
<nav>
<div class = "logo">
<h4>J[a]son</h4>
</div>
<ul class = "nav-links">
<li>
HOME
</li>
<li>
PHOTOGRAPHY
<ul class="sub-menu">
<li>Colour</li>
<li>Black</li>
</ul>
</li>
<li>
CODING
</li>
<li>
ABOUT
</li>
</ul>
<div class= "burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<script src="testing.js"></script>
<div class="main_car_wrapper">
</div>
And some more footer stuff here
<p>June, 2020. Sunshine Coast, BC, Canada </p>
UPDATED
Can use with code like
margin-left: -50px;
margin-right: -50px;
width:100px;
in
.main_car img {
position: absolute;
top: 50%;
left: 50%;
margin-left: [-50% of your image's width];
margin-top: [-50% of your image's height];
}
I'm added css like this
.main_car
{
position: relative;
}
.main_car img
{
position: absolute;
top: 50%;
left: 50%;
margin-left: [-50% of your image's width];
margin-top: [-50% of your image's height];
}
Then will get output like this
Centered Image
body {
background-color: black;
/*rgb(241, 233, 233);*/
}
* {
margin: 0px;
padding: 0px;
}
.main_car
{
position: relative;
}
.main_car img
{
position: absolute;
top: 50%;
left: 50%;
margin-left: -50px;
margin-right: -50px;
width:100px;
}
#media screen and (max-width:1430px) {
.nav-links {
width: 40%;
}
}
#media screen and (max-width:950px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0px;
height: 92vh;
top: 8vh;
background-color: black;
display: flex;
flex-direction: column;
align-items: center;
width: 30%;
transform: translateX(100%);
padding-right: 2em;
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
padding-right: 1em;
}
.sub-menu {
position: relaative;
}
}
<div class="main_car">
<img src="https://www.gravatar.com/avatar/efb780ba8c3560a06d4c1a1825b1e800?s=32&d=identicon&r=PG" alt="car">
</div>
I am creating a simple navigation in angular 6, am using bem methodology and flexbox for css.
Here is the navigation markup:
<div class="main-header">
<nav class="main-nav" ng-sticky [offSet]="0" [addClass]="'main-sticky'" appMainNav #ref="appMainNav">
<div class="main-nav__logo " ng-sticky [offSet]="0" [addClass]="'main-sticky__logo'">
<img class="man-nav__logo-green" src="/assets/images/logo-white.png">
</div>
<div class="main-nav__toggle">
<i class="main-nav__bars fa fa-bars" ng-sticky [offSet]="0" [addClass]="'main-bars'"></i>
</div>
<ul class="main-nav__list " ng-sticky [addClass]="'main-sticky-link'" [ngClass]="ref.click === true? 'Navbar__ToggleShow' :''">
<li class="main-nav__item">
<a class="main-nav__link" href="#">Home</a>
</li>
<li class="main-nav__item">
<a class="main-nav__link" href="#">About us</a>
</li>
<li class="main-nav__item">
<a class="main-nav__link" href="#">What we do</a>
</li>
<li class="main-nav__item">
<a class="main-nav__link " href="#">Projects</a>
</li>
<li class="main-nav__item">
<a class="main-nav__link " href="#">Contact</a>
</li>
</ul>
</nav>
<div class="main-banner">
<h2>We are a team of
<strong>experts</strong>.</h2>
<p>Founded in 2014, the BDTS Poland specializes in IT personnel outsourcing for the areas of banking, insurance, telecommunications,
high-tech, pharmacy, logistics and many others</p>
<a href="http://en.astek.pl/about-us/" class="main-banner__green-button main-banner__arrow-right">Read more
<i></i>
</a>
</div>
</div>
Here is the mobile CSS for navbar:
#media only screen and(max-width: 768px) {
.main-nav {
margin: 0;
display: block;
position: inherit;
height: auto;
overflow: auto;
background: white;
}
.main-nav__list {
margin-top: 20px;
display: none;
flex-direction: column;
justify-content: center;
align-items: center;
}
.main-nav__item:after {
content: '';
width: 1px;
}
.Navbar__ToggleShow {
display: flex;
}
.main-nav__logo {
position: relative;
bottom: 49px;
background-repeat: no-repeat;
background-image: url("/assets/images/logo-green.png");
}
.man-nav__logo-green {
visibility: hidden !important;
}
.main-nav__bars {
display: flex;
justify-content: flex-end;
cursor: pointer;
padding: 26px;
font-size: 50px;
color: #00964e;
top: 0;
margin-top: -196px;
}
.main-nav__link {
color: #444;
}
}
In desktop version everything works fine: but in mobile version navbar increase its height on scroll and hamburger menu disappears,
Here is the solution I tried: (removing height in .man-nav)
.main-nav {
margin: 0;
display: block;
position: inherit;
overflow: auto;
background: white;
}
Now navbar height does not increase on scroll but hamburger menu disappear.
UPDATE - Here is the full CSS for navbar component:
#charset "UTF-8";
#font-face {
font-family: "icomoon";
src: url("/assets/fonts/icomoon.ttf");
}
.main-header {
width: 100%;
float: left;
display: block;
min-height: 100vh;
height: 100%;
background-size: cover;
background-position: center;
padding-bottom: 100px;
background-image: url("/assets/images/banner.jpg");
}
.main-sticky {
background-color: white;
height: 100px;
}
.main-sticky__logo {
position: relative !important;
background-repeat: no-repeat;
background-image: url("/assets/images/logo-green.png");
}
.main-sticky-link .main-nav__link {
color: #444 !important;
}
.main-nav {
position: sticky;
align-items: center;
justify-content: space-around;
left: 0;
display: flex;
z-index: 2;
width: 100%;
}
.main-nav__logo {
position: relative;
}
.main-nav__bars {
color: white;
}
.main-nav__list {
list-style: none;
display: flex;
color: white;
position: relative !important;
}
.main-nav__item {
padding: 24px 27px;
position: relative;
}
.main-nav__item:after {
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
content: "";
display: block;
float: left;
background-color: #f5f5f5;
width: 2px;
height: 60px;
-webkit-transform: rotate(20deg);
transform: skew(155deg);
position: absolute;
right: 0;
bottom: 6px;
}
.main-nav__item:last-child::after {
content: "";
width: 0px;
}
.main-nav__item:hover::after {
width: calc(100% + 1px);
}
.main-nav__item:hover .main-nav__link {
color: #444;
position: relative;
z-index: 3;
}
.main-nav__link {
list-style: none;
font-size: 1rem;
color: white;
font-family: "proxima-nova-n6", "proxima-nova";
font-style: normal;
font-weight: 600;
}
.main-nav__bars {
display: none;
}
.main-banner {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.main-banner h2 {
font-size: 3.75rem;
line-height: 5.375rem;
margin-bottom: 1.5rem;
color: #fff;
font-family: "proxima-nova-n4", "proxima-nova";
font-style: normal;
font-weight: 400;
margin-top: 70px;
font-weight: normal;
}
.main-banner p {
font-size: 1.25rem;
font-weight: normal;
color: white;
text-align: center;
max-width: 700px;
margin-bottom: 3.375rem;
margin-right: auto;
margin-left: auto;
}
.main-banner__green-button {
height: 3.4375rem;
background-color: #00964e;
text-decoration: none;
color: #fff;
padding: 11px 13px;
display: inline-block;
box-sizing: border-box;
line-height: 27px;
border-radius: 30px;
border: 3px solid #00964e;
font-size: 1.125rem;
padding-right: 50px;
font-family: "proxima-nova-n6", "proxima-nova";
font-style: normal;
font-weight: 600;
position: relative;
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
}
.main-banner__arrow-right::after {
font-family: "icomoon";
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
content: "" !important;
font-size: 33px;
}
.main-banner__green-button::after {
float: right;
content: "";
display: block;
width: 34px;
height: 34px;
margin-left: 10px;
top: 10px;
position: absolute;
right: 10px;
}
.main-banner__green-button:hover {
background-color: white;
color: green;
}
.main-banner__arrow-down {
transform: rotate(90deg);
width: 34px;
height: 34px;
position: absolute;
bottom: 176px;
margin-left: -17px;
left: 50%;
z-index: 2;
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
background-image: url("/assets/images/icon-arrow-right.png");
}
#main-sticky {
background-color: white;
}
#media only screen and (max-width: 768px) {
.main-nav {
margin: 0;
display: block;
position: inherit;
height: auto;
overflow: auto;
background: white;
}
.main-nav__list {
margin-top: 20px;
display: none;
flex-direction: column;
justify-content: center;
align-items: center;
}
.main-nav__item:after {
content: "";
width: 1px;
}
.Navbar__ToggleShow {
display: flex;
}
.main-nav__logo {
position: relative;
bottom: 49px;
background-repeat: no-repeat;
background-image: url("/assets/images/logo-green.png");
}
.man-nav__logo-green {
visibility: hidden !important;
}
.main-nav__bars {
display: flex;
justify-content: flex-end;
cursor: pointer;
padding: 26px;
font-size: 50px;
color: #00964e;
/* position: absolute; */
top: 0;
/* bottom: 36px; */
/* right: 28px; */
margin-top: -196px;
}
.main-nav__link {
color: #444;
}
.main-banner__arrow-down {
display: block !important;
position: initial;
margin: 0 auto;
margin-top: 50px;
}
.main-banner h2 {
text-align: center;
}
}
Here is a link to the live demo
Here is GitHub repo if interested
What is wrong with my code? please help, any suggestions will be appreciated, thanks.
There is a lot to debug, here is what I spotted:
nav bar (.main-nav):
First of all, you got a script (index.js) that sets main-nav, main-nav__bars and main-nav__list position to fixed on scroll. You don't need to do that for all three components. Just set main-nav and let the children inherit.
Next you're better off changing height: auto to min-height: 125px (enough to fit the logo)
Then you need to set the nav .main-nav) overflow-x: hidden to eliminate the scrollbar on the right when overflow bugs occur.
Or better yet, make your logo itself and it's container (.main-nav__logo) have a fixed height that matches (height: 125px) and let the logo height: inherit. (you will need to crop your image for that to look nice. See reason on next section)
You're also overriding the display: flex to block with your media query. Remove that so you will be able to use the flex properties. Afterwards you can do something like: (append into your mobile media query)
.main-nav {
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-content: stretch;
align-items: stretch;
}
.main-nav__logo {
flex: 2 1 60%;
}
.main-nav__toggle {
flex: 2 1 30%;
}
.main-nav__list {
flex: 0 1 100%;
}
This should give you a result like this:
|-----------------------|----------|
| Logo | Bars |
|-----------------------|----------|
| |
| Nav ul |
| |
|----------------------------------|
Logo (.man-nav__logo-green):
Next your logo is 200x200 with lots of transparent margin, fix your logo by cropping it down using Photoshop or something to element the fixed margin. This will let your logo to fit in without overflowing the nav bar. (and more flexible in regards to margin styling)
a dirty solution is to change the logo's container to (.main-nav__logo) height: 160px and add a margin-top: -35px.
Hopefully that should make your life a bit easier. Regards.
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}
}