How do I remove the horizontal scroll bar from my Navbar - html

I'm trying to make a responsive site, in which when the width decreases, my nav-links go out of sight, but there is a ***Horizontal Scroll Bar***, that I want to get rid of. I've viewed other question for this, but none of them helped me.
Any Suggestions?
Thank in advance
HTML
<header class="head">
<nav class="navbar">
<div class="logo">
Krishang Sharma
</div>
<ul class="nav-items">
<li>Work</li>
<li>About</li>
<li>Contact</li>
</ul>
<div class="crossMenu">
<div class="line1"></div>
<div class="line2"></div>
</div>
<!-- Theme Toggle Switch -->
<div class="switch">
<div class="bg">
<div class="circle"></div>
</div>
</div>
</nav>
</header>
CSS
.navbar{
width: 100vw;
height: 10vh;
display: flex;
align-items: center;
font-family: 'Poppins', serif;
justify-content: space-evenly;
box-shadow: 0px 15px 20px #1e1e1e;
}
.logo{
width: 40%;
}
.logo a{
color: white;
transition: 0.3s;
font-size: 1.5rem;
text-decoration: none;
}
.logo a:hover{
transition: 0.3s;
color: #639FAB;
}
.nav-items{
width: 40%;
display: flex;
justify-content: space-around;
}
.nav-items, li a{
align-items: center;
height: 100%;
font-size: 18px;
color: white;
list-style: none;
transition: 0.3s;
text-decoration: none;
}
.nav-items a:hover{
transition: 0.3s;
color: #639FAB;
}
.crossMenu{
cursor: pointer;
display: none;
margin-right: 2%;
}
.line1, .line2{
margin: 4px;
height: 4px;
width: 35px;
transition: 0.5s ease;
border-radius: 25px;
background: #639FAB;
}
.switch{
cursor: pointer;
align-items: center;
}
.bg{
height: 20px;
width: 60px;
background: white;
border-radius: 10px;
transition: 0.5s ease;
}
.circle{
right: 5px;
top: -5px;
width: 30px;
height: 30px;
position: relative;
border-radius: 50%;
transition: 0.5s ease;
background: #639FAB;
}
.circleOn{
background: white;
right: -35px;
transition: 0.5s ease;
}
.bgOn{
transition: 0.5s ease;
background: #639FAB;
}
For Lower Resoultion
.nav-items{
right: 15%;
position: absolute;
transition: 0.5s ease;
transform: translateX(200%);
}

Add overflow-x: hidden; to the style= attribute of your navbar.

Why You have used transform: translateX(200%); on .nav-items element?. You should remove/add transform: translateX(0); on .nav-items this element. Then Horizontal Scroll Bar will not show

Related

How to set up media queries in my navbar to make it mobile responsive?

I am trying to get my navbar with my logo on the left and the tabs on the right to be mobile responsive. The viewpoint meta tag drops my logo down below the nav tabs when in mobile view. It also has a scrolling function in javascript. Is it too late for me to go back in and add breakpoints with media queries? Is there an easy fix to this solution? I've tried everything and can not seem to make it work.
.nav_bar {
align-items: center;
position: relative;
height: 80px;
width: 100%;
transition: 0.2s ease;
color: rgb(78, 78, 78);
}
.nav_bar ul li a.active-page {
border-bottom: 1px solid;
}
.nav_bar .nav_ {
margin: 0;
padding: 0;
display: inline-block;
float: right;
margin-right: 5%;
}
.nav_bar .nav_ .item {
list-style: none;
display: inline-block;
font-size: 18px;
padding: 5px;
font-weight: 300;
line-height: 80px;
margin-right: 20px;
transition: 0.5s ease;
}
.nav_bar .nav_ .item a {
text-decoration: none;
color: inherit;
}
.nav_bar .logo {
color: rgb(50, 50, 50);
float: left;
display: inline-block;
margin-top: 10px;
margin-left: 5%;
width: 40px;
height: 40px;
transition: 0.5s ease;
}
.nav_bar img {
height: 40px;
width: 40px;
float: left;
:
}
.scrolled {
background-color: rgba(62, 62, 62, 0.4);
color: white;
transition: 0.5s ease;
}
.scrolled.nav_bar {
height: 50px;
background-color: rgba(62, 62, 62, 0.8);
transition: 0.5s ease;
}
.scrolled.nav_bar .nav_ .item {
line-height: 40px;
transition: 0.5s ease;
}
.scrolled.nav_bar .logo {
float: left;
display: inline-block;
margin-top: 5px;
margin-left: 5%;
width: 40px;
height: 40px;
] transition: 0.5s ease;
}
<div class="nav_bar">
<ul class="nav_">
<li class="item">
<a href="index.html" class='active-page'>Home</a>
</li>
<li class="item">
About
</li>
<li class="item">
Work
</li>
<li class="item">
Contact
</li>
</ul>
<div class="logo">
<img class="logo" src="jhlogogrey.png" alt="">
</div>
</div>
code a specific screen ratio in CSS, and within that block adjust your container’s position, padding and with.

expanding button in css without needing absolute positioning

I am trying to create an expanding css button. I have made some progress but can't seem to get it to work unless I use absolute positioning. Is there a way to make this type of button without needing it to be absolute positioned on a page. Thanks for any help. Below is what I have so far.
I want it to work without needing to be absolutely positioned on the page.
.add-new-button {
right: 250px;
position: fixed;
width: 40px;
height: 40px;
background-color: #1BA1FC;
border-radius: 40px;
transition: width 0.3s;
overflow: hidden;
cursor: pointer;
}
.add-new-button-icon {
top: 0;
right: 0;
z-index: 4;
position: absolute;
color: #fff;
transition: transform 0.2s;
width: 40px;
height: 40px;
}
.add-new-button-icon i {
top: 12px;
height: 100%;
margin-left: 14px;
position: relative;
}
.add-new-button:hover {
width: 110px;
}
.add-new-button:hover .add-new-button-icon {
transform: rotate(90deg);
}
.add-new-button-label {
width: 80px;
color: #fff;
text-align: center;
padding: 5px 0;
border-radius: 6px;
text-transform: uppercase;
font-size: 14px;
text-align: center;
font-family: "Source Sans Pro", sans-serif !important;
font-weight: 700;
position: relative;
margin-top: 5px;
padding-left: 10px;
-moz-transition: all 200ms ease-in;
-webkit-transition: all 200ms ease-in;
-o-transition: all 200ms ease-in;
transition: all 200ms ease-in;
opacity: 0;
}
.add-new-button:hover .add-new-button-label {
transition-delay: 0.1s;
visibility: visible;
opacity: 1;
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="add-new-button">
<div class="add-new-button-label">
Add
</div>
<div class="add-new-button-icon">
<i class="fa fa-plus"></i>
</div>
</div>
It seems (to me) that your button doesn't need to have position: fixed;. All it need is some sufficient space to roll out.
#container {
border: 2px black solid;
display: flex;
justify-content: flex-end;
width: 200px;
}
.add-new-button {
position: relative;
width: 40px;
height: 40px;
background-color: #1BA1FC;
border-radius: 40px;
transition: width 0.3s;
overflow: hidden;
cursor: pointer;
}
.add-new-button-icon {
top: 0;
right: 0;
z-index: 4;
position: absolute;
color: #fff;
transition: transform 0.2s;
width: 40px;
height: 40px;
}
.add-new-button-icon i {
top: 12px;
height: 100%;
margin-left: 14px;
position: relative;
}
.add-new-button:hover {
width: 110px;
}
.add-new-button:hover .add-new-button-icon {
transform: rotate(90deg);
}
.add-new-button-label {
width: 80px;
color: #fff;
text-align: center;
padding: 5px 0;
border-radius: 6px;
text-transform: uppercase;
font-size: 14px;
text-align: center;
font-family: "Source Sans Pro", sans-serif !important;
font-weight: 700;
position: relative;
margin-top: 5px;
padding-left: 10px;
-moz-transition: all 200ms ease-in;
-webkit-transition: all 200ms ease-in;
-o-transition: all 200ms ease-in;
transition: all 200ms ease-in;
opacity: 0;
}
.add-new-button:hover .add-new-button-label {
transition-delay: 0.1s;
visibility: visible;
opacity: 1;
color: #fff;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div id="container">
<div class="add-new-button">
<div class="add-new-button-label">
Add
</div>
<div class="add-new-button-icon">
<i class="fa fa-plus"></i>
</div>
</div>
</div>

Center Logo and nav bar horizontal

How can i center my logo (img) and menu links horizontal. I want the logo to be at the left and menu at right but horizontal centered.
here's my code!
thanks
<div class="menu-container">
<div class="logo">
<img src=https://app.box.com/representation/file_version_186133299510/image_2048/1.png class="logo">
</div>
<nav class="menu">
Branding
Logos
Illustration
Web
Poster
Letters
All
About
</nav>
</div>
<div class="main-intro">
<h2>Let's create something great together!</h2>
</div>
---CSS---
* {
padding: 0px;
margin: 0px;
}
.menu-container{
background-color: gray;
margin: 30px;
position
}
.logo {
height: 10em;
display: inline-block;
padding: 1em;
transition: all 0.6s ease;
-webkit-transition: all 0.6s ease;
}
.menu {
float: right;
margin: 2em; 2em; 0; 0;
display: inline-block;
vertical-align: center;
}
https://codepen.io/Randomood/pen/KmJpWX?editors=1100
try removing the height of your logo from you css?
.logo {
display: inline-block;
padding: 1em;
transition: all 0.6s ease;
-webkit-transition: all 0.6s ease;
}
EDITED:
* {
padding: 0px;
margin: 0px;
}
.menu-container{
background-color: gray;
margin: 30px;
position: relative;
padding: 1em;
}
.logo {
height:10em;
border: 1px solid red;
display: inline-block;
transition: all 0.6s ease;
-webkit-transition: all 0.6s ease;
}
.menu {
float: right;
margin: 4.5em 0em;
display: inline-block;
vertical-align: center;
}
Just try doing this to your "menu-container"
.menu-container{
display:flex;
flex-direction:row;
justify-content:center;
background-color: gray;
margin: 30px;
}
Codepen

vertical align NAV into HEADER

I have a fixed header with a <nav> into it. The problem is that I tried a lot of things, but my elements don't vertically align on middle. I cannot use line-height because it depends on screen resolution.
CSS
header {
width: 100%;
height: 15%;
background-color: rgba(30, 30, 30, 0.75);
color: white;
font-family: 'Roboto', sans-serif;
font-weight: bold;
text-align: center;
position: fixed;
text-transform: uppercase;
overflow: hidden;
}
header nav {
text-align: center;
display: inline-block;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: 0;
}
header nav a {
/*line-height: 6;*/
color: white;
padding: 14px 16px;
text-align: center;
display: inline;
text-decoration: none;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
HTML
<header>
<div>
<nav>
<a class="active" href="">Home</a>
News
Info
Contact
</nav>
</div>
</header>
Demo: http://jsfiddle.net/JJ8Jc/4082/
You can use display flex method to align elements vertically and/or horizontally
I just added
header nav {
display:flex;
justify-content: center;
align-items: center;
}
so you example now become:
header {
width: 100%;
height: 15%;
background-color: rgba(30, 30, 30, 0.75);
color: white;
font-family: 'Roboto', sans-serif;
font-weight: bold;
text-align: center;
position: fixed;
text-transform: uppercase;
overflow: hidden;
display:flex;
}
header nav {
text-align: center;
display:flex;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
margin: 0;
justify-content: center;
align-items: center;
}
header nav a {
/*line-height: 6;*/
color: white;
padding: 14px 16px;
text-align: center;
display: inline;
text-decoration: none;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
<header>
<div>
<nav>
<a class="active" href="">Home</a>
News
Info
Contact
</nav>
</div>
</header>
on your .nav css, change top: 0; for top: 50%; then add these lines:
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
and remove bottom: 0;
jsfiddle
Alternatively, you could use padding-bottom and padding-top to increase the header size keeping the content on the middle. Or, yet, let it flex like the other answer has already suggested.
header {
width: 100%;
height: 15%;
background-color: rgba(30, 30, 30, 0.75);
color: white;
font-family: 'Roboto', sans-serif;
font-weight: bold;
text-align: center;
position: fixed;
text-transform: uppercase;
overflow: hidden;
}
header nav {
text-align: center;
display: inline-block;
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
right: 0;
left: 0;
margin: 0;
}
header nav a {
/*line-height: 6;*/
color: white;
padding: 14px 16px;
text-align: center;
display: inline;
text-decoration: none;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;
}
<header>
<div>
<nav>
<a class="active" href="">Home</a>
News
Info
Contact
</nav>
</div>
</header>

Text isn't properly centered?

I have my social menu text-aligned:center but it's still is off quite a ways. Here's my code and a jsfiddle to demonstrate the trouble. As you can see it has more open space on the left than right. I want to even it out.
jsfiddle
HTML
<div id="wrapper">
<div id="header">
Erratic Fox
</div>
<div id="social">
<ul>
<li>Facebook</li> —
<li>Deviant Art</li> —
<li>YouTube</li> —
<li>Steam</li>
</ul>
</div>
</div>
CSS
body {
margin-top: 10px;
background-color: #E5E5E5;
}
#header {
color: #404040;
width: 50%;
margin: auto;
background-color: #ffffff;
font-size:100px;
text-align: center;
}
#social {
font-family: Roboto;
font-size: 18px;
line-height: 100px;
text-align: center;
height: 100px;
width: 50%;
background-color: white;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
}
#social a {
text-decoration: none;
color: #404040;
transition: 1s color;
-moz-transition: 1s color;
-webkit-transition: 1s color;
}
#social a:hover {
color: #427FED;
transition: 1s color;
-moz-transition: 1s color;
-webkit-transition: 1s color;
}
#social li {
margin-right: 30px;
margin-left: 30px;
display: inline;
}
Add
#social ul {
padding-left:0;
}
Demo
Try to implement this:
ul { padding: 0; margin: 0; }