This question already has answers here:
Does UL have default margin or padding [duplicate]
(2 answers)
Closed 1 year ago.
I was making a navbar using flexbox. By default, shouldn't the justify-content property be set to flex-start; ? But the content inside my container is not begining from the start.
Here's the output and code:
html,
body {
background-color: #ffeead;
margin: 10px;
}
ul {
list-style-type: none;
}
.container {
border: 5px solid #dff124;
display: flex;
justify-content: flex-start;
}
.container li {
padding: 10px;
text-align: center;
font-size: 2em;
color: #ffeead;
background-color: #96ceb4;
}
.search {
flex: 1;
}
<nav>
<ul class="container">
<li>Home</li>
<li>Profile</li>
<li class="search">
<input type="text" class="search-input" placeholder="Search">
</li>
<li>Logout</li>
</ul>
</nav>
That white-space is caused by the default padding of the <ul>. You can remove it by adding: ul { padding-left: 0; }
html,
body {
background-color: #ffeead;
margin: 10px;
}
ul {
list-style-type: none;
padding-left: 0;
}
.container {
border: 5px solid #dff124;
display: flex;
justify-content: flex-start;
}
.container li {
padding: 10px;
text-align: center;
font-size: 2em;
color: #ffeead;
background-color: #96ceb4;
}
.search {
flex: 1;
}
<nav>
<ul class="container">
<li>Home</li>
<li>Profile</li>
<li class="search">
<input type="text" class="search-input" placeholder="Search">
</li>
<li>Logout</li>
</ul>
</nav>
Related
I want to make this header but I stucked
I tried to place it in different ways, but nothing worked. How can I place the text near the logo and make an indent from the edge of the button?
https://codepen.io/Pero-Kairu/pen/mdXvaBV
<header class="header">
<div class="wrap_logo">
<img class="logo" src="icons/logo.svg" alt="Logo">
<p class="name">Travel Portal</p>
</div>
<nav>
<ul class="nav_links">
<li>How It Works</li>
<li>Plan Your Trip</li>
<li>Destinations</li>
<li>Travel Stories</li>
</ul>
</nav>
<form class="login_button">
<input type="button" value="Login">
</form>
</header>
li, a, button {
text-decoration: none;
color: white;
}
li{
list-style-type: none;
}
header {
display: flex;
position: fixed;
justify-content: space-between;
align-items: center;
width: 100%;
height: 90px;
background-color: rgba(242, 120, 92, 0.7);
color: white;
}
.nav_links li {
display: inline-block;
margin: 0 42px;
}
Please use this full HTML markup & CSS code. It's the perfect code for desktop devices. I hope it will help you better.
<header class="header">
<div class="wrap_logo">
<a href="index.html">
<img class="logo" src="https://icon-library.com/images/avatar-png-icon/avatar-png-icon-13.jpg" alt="Logo">
<span class="name">Travel Portal</span>
</a>
</div>
<nav>
<ul class="nav_links">
<li>How It Works</li>
<li>Plan Your Trip</li>
<li>Destinations</li>
<li>Travel Stories</li>
</ul>
</nav>
<form action="#" class="login_button">
<input type="button" value="Login">
</form>
</header>
.header {
top: 0;
left: 0;
right: 0;
z-index: 999;
display: flex;
position: fixed;
padding: 15px 20px;
align-items: center;
justify-content: space-between;
background-color: rgba(242, 120, 92, 0.7);
}
.header .wrap_logo > a {
color: #ffffff;
font-size: 20px;
font-weight: bold;
align-items: center;
display: inline-flex;
}
.header .wrap_logo img {
max-width: 40px;
margin-right: 10px;
}
.header .nav_links {
margin: 0;
padding: 0;
}
.header .nav_links > li {
display: inline-block;
}
.header .nav_links > li:not(:last-child) {
margin: 0 42px 0 0;
}
.header .nav_links > li > a {
color: #ffffff;
font-size: 16px;
font-weight: 500;
}
Let me know if you need any other help.
Thank You.
All you are missing is some styling in your .wrap_logo class:
.wrap_logo {
display: flex;
align-items: center;
}
Also if you want to have some space between the elements and the borders of the page you can just add some padding.
Try it:
.logo{
position: absolute;
margin-top: 15px;
}
.name{
posirion: absolute;
margin-left: 70px;
}
This question already has answers here:
How to Right-align flex item?
(13 answers)
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 1 year ago.
I want to move the NAV bar to the right and I am trying with the justify-content property, but it isn't working.
* {
padding: 0;
margin: 0;
text-decoration: none;
list-style: none;
color: blanchedalmond;
}
.header {
background-color: lightskyblue;
width: 100%;
height: 80px;
}
.innerheader {
height: 100%;
width: 1200px;
margin: auto;
display: flex;
align-items: center;
}
.logo_nav h1 {
font-weight: 200;
}
.logo_nav h1 span {
font-weight: 900;
}
nav {
margin: 0 auto;
display: flex;
justify-content: flex-end;
}
ul {
display: flex;
padding: 0px 100px 0px 240px;
}
ul a li {
display: flex;
color: blanchedalmond;
font-size: 22px;
}
ul a {
padding: 0px 100px 0px 20px;
}
<header class="header">
<div class="innerheader">
<div class="logo_nav">
<h1>My <span>SITE</span></h1>
</div>
<nav class="nav">
<ul>
<a href="#">
<li>Home</li>
</a>
<a href="#">
<li>About</li>
</a>
<a href="#">
<li>Services</li>
</a>
<a href="#">
<li>Hire us</li>
</a>
</ul>
</nav>
</div>
</header>
Thanks in advance for your replies.
I'm a complete beginner in web development so please excuse me if my question seems to be foolish.
After learning about the flexbox concept I tried to apply the concept for developing a simple header. Everything was going perfect but then even after using align-items:center property the items are not looking perfectly centred.
Then I tried to use the border-bottom for the nav-main class to give an underline but I don't understand why the underline is not covering the whole space.
* {
font-family: Arial, Helvetica, sans-serif;
}
html,
body {
margin: 0;
padding: 0;
}
.mainContainer {
display: flex;
flex-direction: column;
border: 1px solid #ccc;
background-color: lemonchiffon;
align-items: center;
}
.heading {
order: 2;
}
.nav-main {
border-bottom: 1px solid red;
order: 1;
}
.nav-main li {
display: inline;
margin: 5px;
}
<div class="mainContainer">
<h1 class="heading">The Peace</h1>
<nav class="nav-main">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
Edit
My first problem is solved by the following code but the underline problem still remains the same.
.nav-main ul{
padding-left: 0;
}
Set .nav-main ul padding to 0:
* {
font-family: Arial, Helvetica, sans-serif;
}
html,
body {
margin: 0;
padding: 0;
}
.mainContainer {
display: flex;
flex-direction: column;
border: 1px solid #ccc;
background-color: lemonchiffon;
align-items: center;
}
.heading {
order: 2;
}
.nav-main {
border-bottom: 1px solid red;
order: 1;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.nav-main ul {
padding: 0;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.nav-main li {
display: inline;
margin: 5px;
}
<body>
<div class="mainContainer">
<h1 class="heading">The Peace</h1>
<nav class="nav-main">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
</body>
For the underline problem you need set the width of nav-main as 100% and those flexbox values
width: 100%;
justify-content: center;
display: flex;
Finally, I solved both the problems by using only one flexbox with text-alignment option as follows:
*{
font-family: Arial, Helvetica, sans-serif;
}
html, body{
margin: 0;
padding: 0;
}
.mainContainer{
display: flex;
flex-direction: column;
border: 1px solid #ccc;
background-color: lemonchiffon;
justify-content: center;
align-items: center;
}
.heading{
order:2;
}
ul{
padding: 0;
}
.nav-main {
width: 100%;
text-align: center;
border-bottom: 1px solid red;
order:1;
}
.nav-main li{
display: inline;
margin: 5px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<link rel="stylesheet" href="trialStyle.css">
</head>
<body>
<div class="mainContainer">
<h1 class="heading">The Peace</h1>
<nav class="nav-main">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
</body>
</html>
Hello Your content properties in the li in the ul doesn't align perfectly because you gave it a margin of 5px and this makes the rightmost li to be shifted by 5px to the right. Try to make your ul also a flexbox and give it a justify-content property of space-evenly...
RESULT:
CSS:
.mainContainer {
display: flex;
flex-direction: column;
background-color: lemonchiffon;
}
.nav-main {
border-bottom: 1px solid red;
order: 1;
}
.heading {
order: 2;
text-align: center;
}
.nav-main li {
display: inline;
margin: 5px;
}
.nav-main ul {
display: flex;
justify-content: center;
}
HTML:
<div class="mainContainer">
<h1 class="heading">The Peace</h1>
<nav class="nav-main">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
</div>
Hey guys I'm not sure what I'm doing wrong, but I want the 3rd li item (input) to go to the end of the container, when I use the justify-content: space-between; - nothing happens, I've tried aligning them, but still nothing.
nav {
width: 100%;
background-color: black;
padding-left: 30px;
padding-right: 10px;
}
.navContact {
margin-left: auto;
}
.navbar {
display: flex;
flex-direction: row;
justify-content: space-between;
}
.mainNav {
display: flex;
}
.navitem a {
color: white;
text-decoration: none;
border-right: 2px solid rgb(255, 123, 0);
padding: 10px 15px;
}
<hr class="hrNav">
<nav class="navbar">
<ul class="mainNav">
<li class="navitem">About me</li>
<li class="navitem">Contact</li>
<li class="navitem"><input type="text" placeholder="Search..."></li>
</ul>
</nav>
You can set flex: 1 in the ul and the last item of the ul, then set margin-left: auto in the last li inside ul as well
*,
*::after,
*::before {
box-sizing: border-box
}
nav {
width: 100%;
background-color: black;
padding-left: 30px;
padding-right: 10px;
display: flex;
justify-content: space-between;
}
.mainNav {
display: flex;
flex: 1;
}
.navitem a {
color: white;
text-decoration: none;
border-right: 2px solid rgb(255, 123, 0);
padding: 10px 15px;
}
.navitem:last-of-type {
margin-left: auto
}
<hr class="hrNav">
<nav class="navbar">
<ul class="mainNav">
<li class="navitem">About me</li>
<li class="navitem">Contact</li>
<li class="navitem"><input type="text" placeholder="Search..."></li>
</ul>
</nav>
I'm having some trouble making a nav menu and its sub menu to display via the pseudo checkbox toggle. I looked at some guides and tried some, but I'm not getting the result I wanted -- the menus does not appear when toggle the checkbox on.
https://codepen.io/UnorthodoxThing/pen/paMBQB
HTML
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>Natural Pasta</title>
<link rel="stylesheet" type="text/css" href="style-index.css">
<link href="https://fonts.googleapis.com/css?family=Amatic+SC|Gloria+Hallelujah|Gorditas|Lobster|Nunito|Shadows+Into+Light|Varela+Round" rel="stylesheet">
<body>
<div class="wrapper">
<!-- Top Menu-->
<img class="top-logo" src="img/NPDesign_full-transparent-bg-1.png" alt="NP full logo" width="220px" height="220px">
<div class="nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>
<div class="dropdown-menu">
<input type="checkbox" id="A">
<label for="A">Menu</label>
<ul>
<li>Pastas To Go</li>
<li>Sauces To Go</li>
<li>
<div class="dropdown-readymeals">
<input type="checkbox" id="A-C">
<label for="A-C" style="font-size:10pt;">Ready Meals...</label>
<ul>
<li>Arancinis</li>
<li style="font-size:10pt;">Garlic Bread</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li>Find Us</li>
</ul>
</div>
</div>
<div class="banner">
<!--
<img src="img/NPDesign_full-transparent-bg-1.png" alt="NP full logo" width="300px" height="300px">
-->
</div>
<div class="body-content">
<div class="specials-title"><h3>- SPECIALISING IN -</h3></div>
<div class="specials-content">
<div class="specials-boxes"><div class="specials-text"><h3>Freshly Hand Made Pastas</h3></div><div class="specials-img"><img src="freshlyhandmadepastas-1.jpg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Gourmet Pasta Meals</h3></div><div class="specials-img"><img src="gourmetpastameals-3.jpg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Traditional Home Made Sauces</h3></div><div class="specials-img"><img src="traditionalhomemadesauces.jpg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Variety of Filled Pastas</h3></div><div class="specials-img"><img src="varietyoffilledpastas-1.jpeg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Home Made Soups</h3></div><div class="specials-img"><img src="homemadesoups-2.jpg"></div></div>
<div class="specials-boxes"><div class="specials-text"><h3>Gourmet Rolls</h3></div><div class="specials-img"><img src="gourmetroles-1.jpg"></div></div>
</div>
</div>
<div class="footer">
<!--<div class="grid">-->
<div class="upper-footer-container">
<div class="footer-container-1">
<h4 style="font-family: 'Gloria Hallelujah', 'cursive';">Follow Us</h4>
<ul class="social-networks">
<li class="flex-items"><img src="fb-icon.png"></img></li>
<li class="flex-items"><img src="instagram-icon.png"></img></div></li>
</ul>
<div class="footer-container-1">
<h4 style="font-family: 'Gloria Hallelujah', 'cursive';">Opening Hours</h4> <br>
<ul class="contact-details">
<li>Monday: 9am-5:30pm</li>
<li>Tuesday: 9am-5:30pm</li>
<li>Wednesday: 9am-5:30pm</li>
<li>Thursday: 9am-9pm</li>
<li>Friday: 9am-5:30pm</li>
<li>Saturday: 9am-5pm</li>
<li>Sunday: 10am-5pm</li>
</ul>
</div>
<div class="footer-container-1">
<h4 style="font-family: 'Gloria Hallelujah', 'cursive';">Contact Us</h4> <br>
<ul class="contact-details">
<li>Add.: 152 Bunnerong Rd, Eastgardens NSW 2036</li>
<li>No.: (02) 8347 1988</li>
<li>Email</li>
<br>
<li>Catering Available</li>
</ul>
</div>
</div>
<div class="lower-footer-container">NaturalPasta © 2018</div>
<!--/div>-->
</div>
</body>
</html>
CSS
* {
padding: 0;
margin: 0;
box-sizing: border-box;
border: 1px solid red;
}
html {
height: 100%;
}
body {
min-height: 100%;
min-width: 100%;
}
.wrapper {
min-height: 100%;
width: 100%;
position: relative;
background: url("img/pasta-food-wallpaper-4.jpg") no-repeat;
background-size: 1350px 670px;
background-position: center;
background-attachment: fixed;
}
body {
height: 100%;
background: #ddd;
}
.nav {
height: 204px;
width: 100%;
margin: 0 auto; /* Centers navigation */
text-align: center;
text-transform: uppercase;
background: black;
display: flex;
justify-content: flex-end;
align-items: flex-end;
font-family: 'Gloria Hallelujah', cursive;
color: #ee6f20;
font-weight: bold;
font-size: 13pt;
}
.nav ul li {
height: 41px;
width: 125px;
background: #000;
}
.nav .dropdown-menu ul, .dropdown-menu .readymeals ul {
background: #000;
}
.nav a {
text-decoration: none;
color: #ee6f20;
}
.dropdown-menu ul li, .dropdown-readymeals ul li {
display: none;
}
.dropdown-menu {
position: relative;
display: inline-block;
}
.dropdown-menu ul {
position: absolute;
display: none;
}
input[type=checkbox] {
display: none;
}
input#A:checked ~ .dropdown-menu ul li {
display: block;
max-height: 100%;
}
input#A-C[type=checkbox]:checked ~ .dropdown-readymeals ul li {
display: block;
}
/*tbc */
.dropdown-menu ul li {
font-size: 11pt;
background: #000;
}
.nav ul {
list-style: none;
display: inherit;
}
.nav ul li, .nav ul ul, .nav ul ul li, .nav label {
cursor: pointer;
}
.top-logo {
margin: auto 0;
position: absolute;
left: 42%;
margin-top: -15px;
}
.body-content {
background-color: #000;
}
.specials-content {
position: relative;
display: flex;
flex-wrap: wrap;
color: orange;
justify-content: center;
}
.specials-title h3 {
width: 100%;
display: block;
margin-top: 0px;
padding-top: 75px;
color: #ee6f20;
}
.specials-boxes {
display: flex;
flex-direction: row;
flex-wrap: wrap;
margin: 35px 75px;
padding: 50px 100px;
/*adjust margin height-width*/
}
.specials-text, .specials-img {
padding: 35px;
display: flex;
align-items: center;
}
.specials-text h3 {
text-align: center;
font-family: 'Gloria Hallelujah', 'cursive';
color: #ee6f20;
}
.specials-img img {
width: 300px;
height: 300px;
border-radius: 25px 5px 25px 5px;
}
h3 {
text-align: center;
font-family: 'Gloria Hallelujah', 'cursive';
color: #eee;
}
.footer {
bottom: 280px;
padding: 150px;
width: 100%;
text-align: center;
background: rgb(0,0,0);
color: white;
font-family: sans-serif;
display: flex;
flex-flow: wrap;
}
.upper-footer-container {
width: 100%;
display: flex;
flex-direction: row;
justify-content: space-around;
display: flex;
flex-wrap: wrap;
}
.footer-container-1 {
width: 250px;
display: block;
margin: 25px;
}
.social-networks {
list-style: none;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.flex-items a img {
width: 50px;
height: 50px;
border-radius: 25px;
margin: 25px;
}
.contact-details {
list-style: none;
font-family: 'ubuntu', sans-serif;
}
.lower-footer-container {
width: 100%;
justify-content: center;
display: flex;
flex-wrap: wrap;
margin-top: 45px;
}
Is it to do with the html? The CSS? What could be interfering from displaying the menu and its submenu? :/
Much appreciated for the long run.
(P.S. I have other source image used in here, though that should not conflict with what I'm trying to resolve.)
In your code the <ul> tag is the sibling of selector input#A
But you have written css code as if .dropdown-menu is the sibling of selector input#A. This is why your code at this particular point doesn't work.
You have to target <ul> when input#A is clicked. <ul> is the sibling of input#A.
Change the css code on line 81 as below
input#A:checked ~ ul li {
display: block;
max-height: 100%;
}
This code change will make your sub-menu visible when you click Menu as shown in below image.
i'm mentioning the fix only for this particular point. In your codepen i can see that you've made this same mistake in few other places. You have to fix it.
Hope this helps.