I'm new to coding and trying to figure out why my nav li's will not display horizontally? I've tried a few things which I've noted in the code below.
The catch here is, I must use floats instead of flexbox.
header nav>* {
float: left;
width: 7%;
margin: 0 5%;
padding-bottom: 30px;
list-style: none;
text-decoration: none;
}
header nav ul li {
width: 100px;
float: right;
display: block;
text-decoration: none;
/*margin-left: 2px;
display: inline; not working*/
}
<header>
<nav>
Courses
<form action="">
<input type="text" placeholder="Search">
</form>
<img class="icon" src="#">
<h2>Tech Academy</h2>
<ul id="SideBar">
<li>Donate</li>
<li>Login</li>
<li>Sign up</li>
</ul>
</nav>
</header>
I have tried changing the specificity to a class or id and that hasn't fixed anything. I should also note that 'text-decoration' is not working for the li but is working for the a 'courses'? * border: box-sizing is also at the top of the css sheet.
This is what it looks like on the browser
I am very new to coding and this one has had me stumped for hours. T
First of all, spacings between attributes in html files have no effect at all on the browser display, and same for spacing in css files.
The second thing, I'm not sure why you don't want to use flex (it's handy here - you set the display of the parent attribute (ul) to display: flex; flex-direction: row; and it will do the trick).
But if you don't want to use it, there are 2 other tricks:
#1
ul {
display: contents; /* this will make the parent act like it doesn't exist - and then do whatever you want with the children*/
}
li {
display: inline-block;
}
<ul id="SideBar">
<li>Donate</li>
<li>Login</li>
<li>Sign up</li>
</ul>
#2 grid
ul {
display: grid;
grid-template-columns: max-content max-content max-content; /*instaed of max-content, you can assign the width you want for each li*/
}
li {
margin : 5px;
list-style: none;
}
<ul id="SideBar">
<li>Donate</li>
<li>Login</li>
<li>Sign up</li>
</ul>
You can use flexbox to arrange them either column or row. Declaring display: flex; should apply what you're trying to do. See the snippet below:
header nav>* {
float: left;
width: 7%;
margin: 0 5%;
padding-bottom: 30px;
list-style: none;
text-decoration: none;
}
header nav ul li {
width: 100px;
float: right;
display: block;
text-decoration: none;
/*margin-left: 2px;
display: inline; not working*/
}
#SideBar{
display: flex;
gap: 5px;
}
<header>
<nav>
Courses
<form action="">
<input type="text" placeholder="Search">
</form>
<img class="icon" src="#">
<h2>Tech Academy</h2>
<ul id="SideBar">
<li>Donate</li>
<li>Login</li>
<li>Sign up</li>
</ul>
</nav>
</header>
More on flexbox here.
Use this on css.....
#SideBar{
display: flex;
}
header nav>* {
float: left;
/*width: 7%;*/
margin: 0 5%;
padding-bottom: 30px;
list-style: none;
text-decoration: none;
}
header nav ul li{
width: 100px;
float: right;
/*display: block;*/
text-decoration: none;
margin-left: 2px;
display: inline;
}
<header>
<nav>
<h2>Tech Academy</h2>
<ul id="SideBar">
<li>Donate</li>
<li>Login</li>
<li>Sign up</li>
</ul>
</nav>
</header>
The problem
is you have used width: 7%; to header nav>*
Weird one
its weird that you have used display: block; along with display: inline;
Solution
I have commented the The problem and Weird one,run the snippet it should work
Related
I need to have image on left side and navbar on right side... but the navbar must be vertically centered with image.. On jsfiddle I made it up to set navbar vertically to center but I am not able to put it on the right side... I will be glad for any help.
JSFiddle: https://jsfiddle.net/polluxik/0Lqubpe6/20/
ul {
display: flex;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
align-items: center;
}
ul img {
height: 100px;
}
li a {
display: block;
color: #262353;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
<ul>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Google_Images_2015_logo.svg/640px-Google_Images_2015_logo.svg.png">
<li><a class="active" href="#">test</a></li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
*in jsfiddle I used random image from google as a placeholder
One approach is below, with corrected HTML (the only valid child of a <ul> or <ol> is an <li>, so the <img> is now appropriately wrapped):
ul {
display: flex;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
align-items: center;
/* aligning the content of the <ul> to the end
of the inline axis: */
justify-content: end;
}
ul img {
height: 100px;
}
li a {
display: block;
color: #262353;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li:first-child {
/* setting the margin of the inline-end of the
first-child <li> element to 'auto', in order
to push the first-child away from the rest of
the content: */
margin-inline-end: auto;
}
<ul>
<!-- wrapped the <img> in another <li> element for validity: -->
<li><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Google_Images_2015_logo.svg/640px-Google_Images_2015_logo.svg.png"></li>
<li><a class="active" href="#">test</a></li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
</ul>
JS Fiddle demo.
References:
justify-content.
margin-inline-end.
We can define the image and navbar items in different div and then using flexbox we can align the two div horizontally using justify-content:space-between.
ul {
display: flex;
justify-content: space-between;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
align-items: center;
}
.nav {
display: flex;
gap: 10px;
}
ul img {
height: 50px;
}
<ul>
<div class='logo'>
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/77/Google_Images_2015_logo.svg/640px-Google_Images_2015_logo.svg.png">
</div>
<div class='nav'>
<li><a class="active" href="#">test</a></li>
<li>test2</li>
<li>test3</li>
<li>test4</li>
</div>
</ul>
I am fairly new to css and while working on a project I couldn't get the Inline-block code to work, and I cant understand why. I want to arrange the links in my navbar menu horizontally rather than vertically.
<nav class="navbar">
<div class="max-width">
<div class="logo">Roulathul <span>Uloom.</span></div>
<ul class="menu">
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Skills</li>
<li>Teams</li>
<li>Contact</li>
</ul>
</div>
</nav>
This is my navbar HTML code.
.navbar .menu .li{
list-style: none;
display: inline-block;
}
And this is where I used the inline block. Any Tips?
Use:
.menu {
display: flex;
}
This is how I mainly center my navbars, just use the display: flex and justify-content: to either space out the elements or center them.
More info on the flex property
.menu{
list-style: none;
display: flex;
justify-content: space-evenly;
}
I added padding for space and removed the default list styling, hope this helps:-
.navbar {
display: flex;
align-items: center;
top: 0px;
}
.navbar ul {
display: flex;
}
.navbar ul li {
list-style: none;
}
.navbar ul li a {
display: block;
padding: 5px 22px;
text-decoration: none;
}
<nav class="navbar">
<div class="logo">
<a href="#">Roulathul <span>Uloom.</span>
</a>
</div>
<ul>
<li class="item">About</li>
<li class="item">Services</li>
<li class="item">Skills</li>
<li class="item">Teams</li>
<li class="item">Contacts</li>
</ul>
</nav>
I got 2 lists with different class but they dont work independent, both lists are unordered, class "menu" list is : list-style-type: none; which is fine as it is my nav bar, but my second list which is "habilidades" doesnt show the little dots to the left, the only one that changed is the font family on my "Habilidades" class but I cant make the dots to appear
PS: Im starting to learn
.menu {
display: flex;
list-style-type: none;
justify-content: space-around;
width: 50%;
text-align: center;
align-items: center;
margin-left: auto;
height: 20%;
margin-top: 20px;
}
.menu li a {
color: black;
text-decoration: none;
font-size: 20px;
}
.habilidades li {
font-family: cursive;
list-style-type: disc;
}
<nav>
<ul class="menu">
<li>Home</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</nav>
<section>
<ul class="habilidades">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</section>
I tried placing two nav bars under each other but I am facing difficulty in aligning the second nav bar in respect to the first one. I didn't quite understand why the second nav bar does'nt float right.
Below are my html and css codes.
.header_nav1 {
display: block;
float: right;
color: #000;
font-family: verdana;
text-transform: uppercase;
max-width: 1024px;
}
.header_nav1 ul li {
padding-top: 10px;
padding-right: 10px;
list-style-type: none;
display: inline;
}
.header_nav2 {
display: block;
padding: 50px;
}
.header_nav2 ul li {
display: inline;
list-style-type: none;
float: right;
padding-right: 15px;
max-width: 1024px;
}
<header class="header_navigation">
<div class="container">
<nav class="header_nav1">
<ul>
<li>Contact</li>
<li>Search</li>
</ul>
</nav>
<nav class="header_nav2">
<ul>
<li>INVESTORS</li>
<li>CAREER</li>
<li>OUR PORTFOLIO</li>
<li>RETAIL SOLUTIONS</li>
</ul>
</nav>
</div>
</header>
Thank you.
I found out that it is caused by the container class.
You can either remove the container or change float: right to display: inline-block
Don't use float:right instead use display:inline
why inline? inline - basically it starts with new line and occupy the whole parent size
I also combine both header_nav1 and header_nav2 on 1 CSS since both of it has the same layout
Here, check the snippet codes below and try seeing it also in full page. Hope it helps.
.header_nav1, .header_nav2 {
display: inline;
color: #000;
font-family: verdana;
text-transform: uppercase;
max-width:1024px;
}
.header_nav1 ul li{
padding-top: 10px;
padding-right:10px;
list-style-type: none;
display: inline;
}
.header_nav2 ul li{
display: inline;
list-style-type: none;
padding-right:15px;
max-width:1024px;
}
<header class="header_navigation">
<div class="container">
<nav class="header_nav1">
<ul>
<li>Contact</li>
<li>Search</li>
</ul>
</nav>
<nav class="header_nav2">
<ul>
<li>INVESTORS</li>
<li>CAREER</li>
<li>OUR PORTFOLIO</li>
<li>RETAIL SOLUTIONS</li>
</ul>
</nav>
</div>
</header>
I've been trying to create a navigation bar which consists of three pieces, a list to the left of the centered logo, the logo itself and a list to the right of the logo. I've tried absolutely positioning the logo and floating the lists however this leads to the logo overlaying the lists when the width of the browser is altered.
Any suggestions would be much appreciated, JSFiddle included below :-).
JSFiddle
HTML
<div class="navigation">
<div class="container-1020">
<ul>
<li>Home</li>
<li>Work</li>
<li>Contact</li>
<li>Blog</li>
</ul>
<div class="nav-logo">
<img src="http://placehold.it/200x60"/>
</div>
<ul>
<li>01234 123456</li>
</ul>
</div>
</div>
CSS
.navigation {
background: #222222;
}
.container-1020 {
max-width: 1020px;
min-width: 500px;
margin: 0 auto;
}
ul {
color: #fff;
margin: 0;
list-style-type: none;
}
li {
display: inline;
margin-right: 10px;
}
li:last-child {
margin-right: 0 !important;
}
.logo-container {
width: 200px;
height: 60px;
}
This might work for youFIDDLE
css:
* {
margin: 0;
}
a {
color: #ffffff;
text-decoration: none;
}
.navigation {
background: #222222;
}
.container-1020 {
max-width: 1020px;
min-width: 500px;
margin: 0 auto;
}
ul {
color: #fff;
list-style-type: none;
display: inline-block;
width: 30%;
}
ul:last-child {
text-align: right;
}
.nav-logo {
display: inline-block;
width: 30%;
}
html:
<div class="navigation">
<div class="container-1020">
<ul class="left">
<li>Home
</li>
<li>Work
</li>
<li>Contact
</li>
<li>Blog
</li>
</ul>
<div class="nav-logo">
<img src="http://placehold.it/200x60" />
</div>
<ul class="right">
<li>01234 123456</li>
</ul>
</div>
</div>
well for one, correct your class name for the logo, is it .nav-logo or .logo-container
then set your ul's and whichever logo container class you decide on to display:inline-block