I'm trying to add a logo to the navigation bar, but the logo I am trying to add is not displayed properly.
I've tried setting width and height, it stretches but it doesn't render properly, and the text written in the image is also not readable.
But when I use another different png image it is visible properly, for example when using this .png file https://www.logomakr.in/img/logo-design2.png, it is displayed properly and is visible.
body {
font-family: "Open Sans", sans-serif;
color: #444444;
}
#header {
background: #fff;
transition: all 0.5s;
z-index: 997;
padding: 15px 0;
box-shadow: 0px 2px 15px rgba(25, 119, 204, 0.1);
}
#header.header-scrolled {
top: 0;
}
#header .logo {
font-size: 30px;
margin: 0;
padding: 0;
line-height: 1;
font-weight: 700;
letter-spacing: 0.5px;
font-family: "Poppins", sans-serif;
}
#header .logo a {
color: #2c4964;
}
#header .logo img {
max-height: 40px;
}
/*--------------------------------------------------------------
# Navigation Menu
--------------------------------------------------------------*/
/**
* Desktop Navigation
*/
.navbar {
padding: 0;
}
.navbar ul {
margin: 0;
padding: 0;
display: flex;
list-style: none;
align-items: center;
}
.navbar li {
position: relative;
}
.navbar>ul>li {
position: relative;
white-space: nowrap;
padding: 8px 0 8px 20px;
}
.navbar a,
.navbar a:focus {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
color: #2c4964;
white-space: nowrap;
transition: 0.3s;
border-bottom: 2px solid #fff;
padding: 5px 2px;
}
.navbar a i,
.navbar a:focus i {
font-size: 12px;
line-height: 0;
margin-left: 5px;
}
.navbar a:hover,
.navbar .active,
.navbar .active:focus,
.navbar li:hover>a {
color: #1977cc;
border-color: #1977cc;
}
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<header id="header" class="fixed-top">
<div class="container d-flex align-items-center">
<a class="logo me-auto" href="#">
<img src="https://toppng.com/uploads/preview/logo-design-concept-for-huebris-sample-logo-image-11563507273imdbiqdnjt.png">
</a>
<nav id="navbar" class="navbar order-last order-lg-0">
<ul>
<li><a class="nav-link scrollto active" href="#hero">Home</a></li>
<li><a class="nav-link scrollto" href="#about">About</a></li>
<li><a class="nav-link scrollto" href="#services">Services</a></li>
<li><a class="nav-link scrollto" href="#departments">Events</a></li>
<li><a class="nav-link scrollto" href="#departments">Contact Us</a></li>
<li><a class="nav-link scrollto" href="#doctors">Careers</a></li>
</ul>
</nav>
<!-- .navbar -->
</div>
</header>
<!-- End Header -->
What is causing this behavior? How to do it properly?
Just make the image rectangular, scale it decently and please erase that grey background so that it'll look good.
Then wrap that up using navbar-brand and img-fluid classe as shown here: https://getbootstrap.com/docs/5.1/components/navbar/#image
Related
I have a menu bar that I am trying to float right, I also have a logo that I would like to keep to the left.
I have been able to get the menu to float to the right and keep the logo on the right however the menu is being pushed down in is not in line with the logo.
How do I get the menu in line with the logo?
If I put float left on the logo it leaves a weird gap at the top and messes up the layout.
Here is my code
.navbar-collapse ul a {
font-family: "Barlow", sans-serif;
color: white;
text-decoration: none;
vertical-align: top;
}
.navbar-collapse ul a:hover {
background-color: white;
color: #23303e;
border-radius: 50px;
text-transform: uppercase;
font-weight: 900;
font-family: "Fraunces", serif;
padding: 10px 30px 10px;
}
}
.navbar-collapse ul {
padding: 0;
margin: 0;
float: right;
display: flex;
}
.navbar-collapse li {
display: inline;
float: left;
}
.logo {
width: 20%;
margin: 0 auto;
padding: 7.5px 10px 7.5px 0;
}
}
<nav>
<div class="container-fluid">
<a class="nav-brand" href="#page-top"><img src="images/logo.svg" class="logo" alt="Sunnyside Logo"></a>
<button class="navbar-toggle" type="button">
<img src="images/icon-hamburger.svg" class="hamburger" alt="hamburger">
</button>
<div class="navbar-collapse">
<ul>
<li class="nav-link text-center">About</li>
<li class="nav-link text-center">Services</li>
<li class="nav-link text-center">Projects</li>
<li class="nav-link text-center">Contact</li>
</ul>
</div>
</div>
</nav>
You need to put display: flex for .container-fluid that helps all your menu items on the same line as logo. To align right for menu items, you should put margin-left: auto for .navbar-collapse
Here is the full code
.navbar-collapse ul a {
font-family: "Barlow", sans-serif;
color: white;
text-decoration: none;
vertical-align: top;
}
.container-fluid {
display: flex;
}
.navbar-collapse {
margin-left: auto;
}
.navbar-collapse ul a:hover {
background-color: white;
color: #23303e;
border-radius: 50px;
text-transform: uppercase;
font-weight: 900;
font-family: "Fraunces", serif;
padding: 10px 30px 10px;
}
}
.navbar-collapse ul {
padding: 0;
margin: 0;
float: right;
display: flex;
}
.navbar-collapse li {
display: inline;
float: left;
}
.logo {
width: 20%;
margin: 0 auto;
padding: 7.5px 10px 7.5px 0;
}
}
<nav>
<div class="container-fluid">
<a class="nav-brand" href="#page-top"><img src="images/logo.svg" class="logo" alt="Sunnyside Logo"></a>
<button class="navbar-toggle" type="button">
<img src="images/icon-hamburger.svg" class="hamburger" alt="hamburger">
</button>
<div class="navbar-collapse">
<ul>
<li class="nav-link text-center">About</li>
<li class="nav-link text-center">Services</li>
<li class="nav-link text-center">Projects</li>
<li class="nav-link text-center">Contact</li>
</ul>
</div>
</div>
</nav>
I want to make a navbar and between my links I have a selectable space. How can I make it non selectable?
This is the code:
.navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.navhome {
font-weight: 600;
color: rgba(255, 255, 255, 0.664);
}
.navlinks {
font-size: 15px;
}
.navlinks a {
font-weight: 570;
margin-top: -40px;
text-align: center;
padding: 15px 10px;
text-decoration: none;
float: right;
color: rgba(255, 255, 255, 0.863);
margin-left: -4px
}
.navlinks>.navlinks a:not(:last-child) {
margin-left: -10px;
}
<nav class="navbar">
<a class="navhome" id="noselect">home</a>
<div class="navlinks">
<li>testlink</li>
</div>
<div class="navlinks">
<li>testlink1</li>
</div>
</nav>
How can I make the space between links non selectable in html?
A simpler way to do this could be as follows.
Put all the links that you have in a div or header tag and make the display of the element flex so that everything inside the div or header tag get positioned in a line. I've used align-items CSS property to centre the links vertically as well. Then for each link declare a left margin or a right margin so that they don't stick to each other.
Note that I have initially set the default margin and padding of all the elements to 0px.
#import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
* {
margin: 0px;
padding: 0px;
}
header {
display: flex;
align-items: center;
background-color: #0D0D0D;
padding: 10px;
}
.Header-Link {
font-family: "Poppins";
text-decoration: none;
color: #FFFFFF;
margin-right: 25px;
}
<html>
<body>
<header>
<a class="Header-Link" href="https://www.stackoverflow.com" target="_blank">Home</a>
<a class="Header-Link" href="https://www.stackoverflow.com" target="_blank">Test Link 1</a>
<a class="Header-Link" href="https://www.stackoverflow.com" target="_blank">Test Link 2</a>
</header>
</body>
</html>
Try this I made few changes in CSS classes and the format of code and syntax and exclude unnecessary CSS and make it the right way and the spaces between the links are non selectable by simply giving .nav-item a margin-right: 10px;
.navbar{
background-color: #303030;
}
.navbar-nav{
list-style: none;
display: inline-flex;
}
.nav-item{
margin-right: 10px;
}
.nav-item a{
text-decoration: none;
font-weight: normal;
text-align: center;
float: right;
color: #ffffffdc;
font-size: 15px;
font-family: Arial, Helvetica, sans-serif;
}
.nav-item a.active{
font-weight: bold;
color: #daa520;
}
<nav class="navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" href="#" active>Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">testlink</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">testlink1</a>
</li>
</ul>
</nav>
I am creating a Menu bar for my website, this includes a left side logo image and right side menu items. The logo is an inline element of anchor tag as I need a feature where if somebody clicks on a logo, then it should go to index.html (home page).
This anchor tag is adding extra space after image which is creating two problems 1) hyperlink work far right of the image and last menu items comes on the second line.
I already tried every possible way, for example, removing space between a>img>/a> or using style="display: block;", and many more. How can I properly align the menu items and remove the extra right size hyperlink area after the logo image?
.header_top {
width: auto;
max-width: 72em;
float: none;
display: block;
margin-right: auto;
margin-left: auto;
padding-left: 20px;
padding-right: 20px;
margin: 0 auto;
}
.navbar {
position: relative;
display: flex;
}
.navbar-toggleable-md {
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
flex-direction: row;
flex-wrap: nowrap;
-webkit-box-align: center;
align-items: center;
margin-top: .1rem;
margin-bottom: .1rem;
}
.bg-faded {
background-color: #fff;
/* padding: 1.1em 1em; */
padding: 21px 0px;
}
.navbar-brand {
display: inline-block;
float: left;
font-size: 1.25rem;
line-height: inherit;
white-space: nowrap;
}
.navbar-nav {
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
padding-left: 0;
flex-direction: row;
margin-bottom: 0;
list-style: none;
}
.mx-auto {
margin-right: auto !important;
margin-left: auto !important;
}
li.nav-item.active {
border-bottom: 3px solid #C19506;
background: #F5F5F5;
}
ul.navbar-nav li {
margin: 0 6px;
}
.navbar-toggleable-md .navbar-nav .nav-link {
padding-right: 1.1em;
padding-left: 1.1em;
letter-spacing: 1px;
}
.nav-link {
display: block;
padding: 0.5em 1em;
}
.navbar-toggleable-md .navbar-nav .nav-link {
padding-right: 1.1em;
padding-left: 1.1em;
letter-spacing: 1px;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
</head>
<body>
<header>
<div class="header_top" id="home">
<nav class="navbar navbar-toggleable-md bg-faded">
<a class="navbar-brand" href="index.html">
<img width="37%" height="37%" src="images/Logo.png"></a>
<ul class="navbar-nav mx-auto">
<li><a class="nav-link" href="index.html">Home</a></li>
<li><a class="nav-link" href="about.html">About</a></li>
<li><a class="nav-link" href="about.html">Contac</a></li>
<li><a class="nav-link" href="index.html">Home</a></li>
<li><a class="nav-link" href="about.html">About</a></li>
<li><a class="nav-link" href="about.html">Contac</a></li>
<li><a class="nav-link" href="index.html">Home</a></li>
</ul>
</nav>
</div>
</header>
</body>
</html>
Please use any 1285px x 249px image for logo or download it from https://www.filedropper.com/logo_9 as I am unable to upload image.
you will notice between the logo image and first menu item 'Home' the Anchor tag occupies more width than the image.
If possible, is there any other way to add a link with tag.
Just change the width of <img> from any percentage to some fixed values like 100px.
This will solve your extra space problem added by anchor tag but for responsiveness, you have to adjust the width as per different screen sizes.
.header_top {
width: auto;
max-width: 72em;
float: none;
display: block;
margin-right: auto;
margin-left: auto;
padding-left: 20px;
padding-right: 20px;
margin: 0 auto;
}
.navbar {
position: relative;
display: flex;
}
.navbar-toggleable-md {
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
flex-direction: row;
flex-wrap: nowrap;
-webkit-box-align: center;
align-items: center;
margin-top: .1rem;
margin-bottom: .1rem;
}
.bg-faded {
background-color: #fff;
/* padding: 1.1em 1em; */
padding: 21px 0px;
}
.navbar-brand {
display: inline-block;
float: left;
font-size: 1.25rem;
line-height: inherit;
white-space: nowrap;
}
.navbar-nav {
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
padding-left: 0;
flex-direction: row;
margin-bottom: 0;
list-style: none;
}
.mx-auto {
margin-right: auto !important;
margin-left: auto !important;
}
li.nav-item.active {
border-bottom: 3px solid #C19506;
background: #F5F5F5;
}
ul.navbar-nav li {
margin: 0 6px;
}
.navbar-toggleable-md .navbar-nav .nav-link {
padding-right: 1.1em;
padding-left: 1.1em;
letter-spacing: 1px;
}
.nav-link {
display: block;
padding: 0.5em 1em;
}
.navbar-toggleable-md .navbar-nav .nav-link {
padding-right: 1.1em;
padding-left: 1.1em;
letter-spacing: 1px;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
</head>
<body>
<header>
<div class="header_top" id="home">
<nav class="navbar navbar-toggleable-md bg-faded">
<a class="navbar-brand" href="index.html">
<img width="100px" height="auto" src="https://media.licdn.com/dms/image/C4D12AQG20nwV6xq8lQ/article-cover_image-shrink_600_2000/0?e=1565222400&v=beta&t=-kqjXSTS6VCDVj8UX6ORuqrxKCDTR9BQwDAsycIfUio"></a>
<ul class="navbar-nav mx-auto">
<li><a class="nav-link" href="index.html">Home</a></li>
<li><a class="nav-link" href="about.html">About</a></li>
<li><a class="nav-link" href="about.html">Contac</a></li>
<li><a class="nav-link" href="index.html">Home</a></li>
<li><a class="nav-link" href="about.html">About</a></li>
<li><a class="nav-link" href="about.html">Contac</a></li>
<li><a class="nav-link" href="index.html">Home</a></li>
</ul>
</nav>
</div>
</header>
</body>
</html>
How can I align the navigation links and brand name using pure CSS?
It disaligns after I include a float on the brand container and link container.
Screenshot image here:
HTML
<!DOCTYPE html>
<hmtl>
<head>
<title>My Portfolio</title>
<meta name="author" content="Rocky">
<meta name="description" content="Sample Portfolio">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans|Poppins">
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<header class="header">
<nav class="nav-bar">
<section class="nav-container">
<section class="brand-container">
<h2 class="brand-name">Rocky</h2>
</section>
<ul class="link-container">
<li><a class="nav-link" href="#">Home</a></li>
<li><a class="nav-link" href="#">About Me</a></li>
<li><a class="nav-link" href="#">My Works</a></li>
<li><a class="nav-link" href="#">My Challenge</a></li>
<li><a class="nav-link" href="#">Contact Me</a></li>
</ul>
</section>
</nav>
</header>
CSS
* {
margin: 0; padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Open Sans';
overflow-x: hidden;
}
a {
text-decoration: none;
}
.header {
height: 100vh; width: 100vw;
background: url('../img/header_img.jpg') top center / cover fixed no-repeat;
z-index: 1030;
}
.nav-bar {
position: fixed;
width: 100%;
border-bottom: 1px solid #EEE;
z-index: 1031;
}
.nav-container {
width: 90%;
margin: 0 auto;
overflow: hidden;
}
.brand-container {
float: left;
display: inline-block;
}
.brand-name {
position: relative;
padding: 5px 10px;
border-radius: 4px;
font-family: 'Poppins';
color: #444;
background: #EEE;
cursor: pointer;
-webkit-tap-highlight-color: transparent;
}
.link-container {
position: relative;
list-style-type: none;
float: right;
}
.link-container li {
padding: 20px 15px;
display: inline-block;
}
.link-container li a {
font-family: 'Poppins';
color: #EEE;
transition: color 150ms linear;
}
.link-container li a:hover {
color: #CCC;
}
How can I fix this to align them? I tried everything like separating them and used several CSS properties to do the job it didn't worked.
So floats are a pretty 'hacky' solution to setting elements to the right or left, and generally should be avoided if at all possible. Using different display settings should get the look you're going.
display: grid;
for example, will allow you to divide your nav into columns and place elements into whichever column you'd like. I made a codepen that shows what I believe is the look you're going for placement wise. If you have any questions or anything feel free to ask! I hope this helped!
Here's the problem: the navbar looks like it's floating down the page.
Why does the nav-bar look like this? I'm still new to css and I've tried everything but nothing works. I've re-written the code again but the issue wasn't resolved. Here's what the nav should look like.
this tutorial is from this udemy course
https://www.udemy.com/design-and-develop-a-killer-website-with-html5-and-css3/#%2F
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
background-color: #fff;
color: #555;
font-family: 'Lato', 'Arial', sans-serif;
font-weight: 300;
font-size: 20px;%);
text-rendering: optimizeLegibility;
overflow-x: hidden;
}
/*-------------------------------------------------*/
/*reusable componment*/
/*-------------------------------------------------*/%);
.row {
max-width: 1140px;
margin: 0 auto;
}
/*-----------*/
/*headings*/
/*-----------*/
h1 {
margin: 0;
margin-bottom: 20px;
margin-top: 0;
color: #fff;
font-size: 240%;
font-weight: 300;
text-transform: uppercase;
letter-spacing: 1px;
word-spacing: 4px;
}
/*-----------*/
/*buttons*/
/*-----------*/
.btn:link,
.btn:visited {
display: inline-block;
padding: 10px 30px;
font-weight: 300;
text-decoration: none;
border-radius: 200px;
transition: background-color 0.2s,border 0.2s ,color 0.2s;
}
.btn-1:link,
.btn-1:visited {
background-color: #e67e22;
color: #fff;
margin-right: 15px;
}
.btn-2:link,
.btn-2:visited {
border: 1px solid #e67e22;
color: #e67e22
}
.btn-1:hover,
.btn-1:active {
background-color: #b05d14;
}
.btn-2:hover,
.btn-2:active {
background-color: #b05d14;
color: #fff;
}
/*-------------------------------------------------*/
/*HEADER*/
/*-------------------------------------------------*/
.hero-text-box{
position: absolute;
width: 1140px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
header {
background-image: -webkit%);-linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)), url(assets/images/hero.jpg);
background-size: cover;
background-position: center;
height: 100vh;
background-attachment: fixed;
}
.logo{
height: 100px;
width: auto;
float: left;
margin-top: 20px;
}
.main-nav {
float: right;
list-style: none;
margin-top: 55px;
}
.main-nav li {
display: inline-block;
margin-left: 40px;
}
.main-nav li a:link,
.main-nav li a:visited {
padding: 8px 0;
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 90%;
border-bottom: 2px solid transparent;
-webkit-transition: border-bottom 0.3s, color 0.3s;
transition: border-bottom 0.3s, color 0.3s;
}
.main-nav li a:hover,
.main-nav li a:active {
border-bottom: 2px solid #BF55EC;
<!DOCTYPE html>
<html>
<head>
<title>omni food</title>
<link rel="stylesheet" type="text/css" href="normalize.css">
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="grid.css">
<link href="https://fonts.googleapis.com/css?family=Lato:100,300,300i,400" rel="stylesheet">
</head>
<body>
<header>
<nav>
<div class="row">
<img src="assets/images/logo-white.png" alt="omni-food" class="logo">
</div>
<div class="main-nav">
<ul>
<li> Food delivery </li>
<li> How it works </li>
<li> Our cities </li>
<li> Sign up </li>
</ul>
</div>
</nav>
<div class="hero-text-box">
<h1>Goodbye junk food.<br>hello super healthy meals</h1>
<a class="btn btn-1" href="#">I'm hungry</a>
<a class="btn btn-2" href="#">show me more</a>
</div>
</header>
</body>
</html>
please help me
The is defined so that it takes up the entire row on screen. This forces onto a new row making it appear lower. If you still want the functionality of the row class, it should enclose both the img & UL. You can get rid of that div entirely and apply the class row to the Nav element.
<nav class="row">
<img src="assets/images/logo-white.png" alt="omni-food" class="logo">
<div class="main-nav">
<ul>
<li> Food delivery </li>
<li> How it works </li>
<li> Our cities </li>
<li> Sign up </li>
</ul>
</div>
</nav>
Don't use entire row for only logo . you have used
.row{ max.width: 1180px; }
put this .row class in nav element or
remove row class from div for logo .
<nav class("row")>