how to make navigation buttons next to each other horizontally - html

I'm trying to get my navigation buttons to be next to each other, like in this example: https://codepen.io/freeCodeCamp/pen/RKRbwL
Here is my code:
<header id="header">
<img id="header-img" src="https://www.logobee.com/uploads/tesla-logo.png"/>
<nav id="nav-bar">
<ul>
<li>
<a class="nav-link" href="#Features">Features</a>
</li>
<li>
<a class="nav-link" href="#Demo">Demo</a>
</li>
<li>
<a class="nav-link" href="#Pricing">Pricing</a>
</li>
</ul>
</nav>
</header>
<section id="Features">
<h3>EXOSKELETON</h3>
<p>Cybertruck is built with an exterior shell made for ultimate durability and passenger protection. Starting with a nearly impenetrable exoskeleton, every component is designed for superior strength and endurance, from Ultra-Hard 30X Cold-Rolled stainless-steel structural skin to Tesla armor glass.</p>
<h3>ULTRA-HARD 30X COLD-ROLLED STAINLESS STEEL</h3>
<p>If there was something better, we’d use it. Help eliminate dents, damage and long-term corrosion with a smooth monochrome exoskeleton that puts the shell on the outside of the car and provides you and your passengers maximum protection.</p>
<h3>TESLA ARMOR GLASS</h3>
<p>Ultra-strong glass and polymer-layered composite can absorb and redirect impact force for improved performance and damage tolerance.</p>
</section>
<section id="Demo">
<iframe id="video" src="https://www.youtube.com/embed/m7atGkba-Z8" allowfullscreen></iframe>
</section>
<section id="Pricing">
<h3>Single-Motor Cybertruck</h3>
<ul>
<li>$39,900</li>
<li>250+ miles of range</li>
<li>0-60 moh in 6.5 seconds</li>
<li>top speed of 110 mph</li>
</ul>
<h3>Dual-Motor Cybertruck</h3>
<ul>
<li>$49,900</li>
<li>300+ miles of range</li>
<li>0-60 moh in 4.5 seconds</li>
<li>top speed of 120 mph</li>
</ul>
<h3>Tri-Motor Cybertruck</h3>
<ul>
<li>$69,900</li>
<li>500+ miles of range</li>
<li>0-60 moh in 2.9 seconds</li>
<li>top speed of 130 mph</li>
</ul>
</section>
<form id="form" action="https://www.freecodecamp.com/email-submit">
<input id="email" placeholder="Enter your email" type="email" name="email"></input>
<input id="submit" type="submit"></input>
</form>
CSS:
header {
position: fixed;
left: 480px;
top: 0px;
}
#media (max-width: 800px){
position: fixed;
left: 200px;
}
#header-img {
height: 80px;
}
header {
display: flex;
}
li {
display: flex;
}
How do I do this? thank you!
also, I copy and paste my code from codepen into stack overflow but I have to manually space out my code so it is formatted correctly. How do I make it so I can just copy and paste code and have it automatically formatted? I used the code toolbar but it only makes the first line of code formatted.

If you want the nav items to be placed horizontally, you should apply display: flex property to the parent container, i.e, ul in your case.
nav ul {
display: flex;
}
My bad, there should be a space between nav and ul. I've updated my answer. Now it will target only the nav elements

Related

why display-inline block does not affect the block?

I am newbie with html css and here is my problem.
I code a nav and subnav at html file as this one
<div id="header">
<!-- begin nav -->
<ul id="nav">
<li>Home</li>
<li>Bane</li>
<li>Tour</li>
<li>Contact</li>
<li>
<a href="">More
<i class="nav-arrow-down ti-arrow-circle-down"></i>
</a>
<ul class="subnav">
<li>Merchandise</li>
<li>Extras</li>
<li>Media</li>
</ul>
</li>
</ul>
<!-- end nav -->
<!-- begin search-->
<div class="search-btn">
<i class="search-icon ti-search"></i>
</div>
<!-- end search-->
</div>
And I want to make a block with color grey at block Merchandise, Extras, Media.
Here is my code at styles.css
#nav .subnav {
/*display: none;*/
position: absolute;
background-color: #fff;
min-width: 160px;
top: 100%;
left: 0;
}
My problem is, when I click to Merchandise, for example, the grey is not display fully all the block as I want. Here is the design
But here is what I got
As you can see in the second picture, the block become fell in.
I thought that I can use display: inline-block; to solve this problem , but when I add this command to #nav .subnav, it does not solve this problem.
They said that, I can use at #nav .subnav this command min-width: 160px;, but it still not well.
Could you please give me some ideas for this problem?
Thank you very much for your time.
I think you should give width:100% of ul tag.
<ul class="subnav" style="width:100%;">
<li>Merchandise</li>
<li>Extras</li>
<li>Media</li>
</ul>

How to align a li tag vertically

How i can align to center my "li" tag?
const succes = <a href="#" className='succes'>✓</a>
const fail =
<div className="goals">
<li>Collect 5 thousand subscribers</li>
<li>Learn ReactJS </li>
<li>{succes} Move to apartment</li>
<li>Start speaking english fluently</li>
</div>
I need something like this
https://imgur.com/S3HVo0h
Try wrapping all of your list items in a UL element:
<div className="goals">
<ul>
<li>Collect 5 thousand subscribers</li>
<li>Learn ReactJS </li>
<li>{succes} Move to apartment</li>
<li>Start speaking english fluently</li>
</ul>
</div>
Generally speaking you should always use a list tag to start and close any lists that you are using.
Take a look at this for further clarification:
https://www.w3schools.com/html/html_lists.asp
It also may also depend on your CSS too so double check that as well.
Put li in ul
Check what goals class has. Does it have text-align:center?
.centered {
text-align: center;
}
<ul>
<li>First</li>
<li>second</li>
<li>Third</li>
</ul>
<div class="centered">
<li>First</li>
<li>second</li>
<li>Third</li>
</div>
<!-- UL vs DIV -->
<ul class="centered">
<li>First</li>
<li>second</li>
<li>Third</li>
</ul>
You could just nest another <ul> in between, like
<div className="goals">
<ul>
<li>Collect 5 thousand subscribers</li>
<li style="list-style: none;">
<ul>
<li>Learn ReactJS </li>
<li>{succes} Move to apartment</li>
</ul>
</li>
<li>Start speaking english fluently</li>
</ul>
</div>
I'd like to point out that you can't put a li directly inside a div, because it is not allowed for some reason. You should put it in a ul instead to keep the validators happy. Like this:
<div className="goals">
<ul>
<li>Collect 5 thousand subscribers</li>
<li>Learn ReactJS </li>
<li>{succes} Move to apartment</li>
<li>Start speaking english fluently</li>
</ul>
</div>
We can then use a bit of flexbox to center this ul:
div {
display: flex;
justify-content: center;
}
This should hopefully center it! Hooray!

CSS centered list bullet and numbering

I have an issue with a website I'm making. There are 2 lists inside of boxes all the text seems to be centered with the bullets out on the far left side of the text. I checked this on my local host and no issues were found there. But when I upload it to my web server the issue happens. I would like the text centered but the bullets closer to the text. Attached is the CSS and HTML for the boxes. Also a link to the file with the issue link (It's live but not linked publicly yet)
.centerDivR {
width: 80%;
height: 500px;
margin: 0 auto;
}
.rulesspace {
width: 4%;
height: 300px;
float: left;
}
.news2 {
width: 46%;
height: 300px;
background-color: rgba(192, 192, 192, 0.6);
float: left;
padding: 4px;
}
.rulesa {
width: 46%;
height: auto;
float: left;
padding: 4px;
}
.rulesb {
width: 46%;
height: auto;
float: left;
padding: 4px;
}
<div style="text-align: center; font size:12pt;"><span class="body">Server Rules||Route Specific Rules
||Local Information
||Train & Destination Tags<br></div></span>
<hr>
<div class="centerDivR">
<div class="rulesa">
<div style="text-align: center;">
<span class="h2"><i>General Rules:</i></span>
<br>
<br>
</div>
<ul>
<li>No Advertiseing other servers</li>
<li>Four Strike Policy
<ol>
<li>1st Warning</li>
<li>2nd Warning</li>
<li>2 Week Ban</li>
<li>Perminate Suspension</li>
</ol>
</li>
<li>Please keep foul language to a minimum</li>
<li>Be considerate of other players</li>
<li>Discussion or distribution of pirated or illegally acquired software is strictly prohibited</li>
</ul>
</div>
<div class="rulesspace"></div>
<div class="rulesb">
<div style="text-align: center;">
<span class="h2"><i>Multiplayer Server Rules:</i></span>
<br>
<br>
</div>
<ul>
<li>No spanwing trains with out dispatcher permission</li>
<li>No flipping switches while DS is on duty with out proper permission</li>
<li>No passing red signals without G or P plates</li>
<li>If a signal has stop indication but contains a G or P plate, stop, and ask DS to proceed at restricted speed</li>
<li>Flipping switches & dropping signals without proper permission while a train is approaching is strictly prohibited.</li>
<li>Hump Yard tags/settings are not to to be changed except by an Administrator.</li>
<li>For the UP and BN trackage, call signals LOWER than clear.
<br>(Clear Varients may be called)</li>
<li>Obey all Speed limits</li>
<li>Do not leave mainline switches open</li>
<li>Special trains (circus trains, OCS trains, etc. may be run only with administrator permission)</li>
<li>Running a track intended for traffic moving opposite your direction may be run ONLY with track warrant accompanying.</li>
<li>If you need to leave with other players on the same trackage, you may step away and hold the main for 15 minutes.
<br>If the limit is reached, your train will be saved and deleted for you to resume later.</li>
</ul>
</b>
</div>
</div>
You might have some mis-matched <div> elements or other markup errors, please valid your HTML and fix them.
If you do set the list items to be center aligned (or inherited from the containers). Try this:
li {
list-style-position: inside;
}
jsFiddle
body {
text-align: center;
}
li {
list-style-position: inside;
}
<ul>
<li>No Advertiseing other servers</li>
<li>Four Strike Policy
<ol>
<li>1st Warning</li>
<li>2nd Warning</li>
<li>2 Week Ban</li>
<li>Perminate Suspension</li>
</ol>
</li>
<li>Please keep foul language to a minimum</li>
<li>Be considerate of other players</li>
<li>Discussion or distribution of pirated or illegally acquired software is strictly prohibited</li>
</ul>

CSS Hover will not work on Navigation Bar

Hey guys this is my second question so far on a website i'm re-designing for my boss. I'm trying have it where if the user hovers over "4-Color Offset Printing" the background of the div ID will change to another background-color. (Example blue). I've tried adding #4_color_offset_printing:hover to see if that will just simply change the background color. This usually works but on this navigation bar it seems to not be working. Right now the default background is green. I'd like it to turn blue when i hover over it. I'm trying to apply this affect to every link but if i could get one working i could figure out the rest.
The older style of the navigation bar is the Gray with the blue link hover affect. The last developer that designed the site decided to use inline CSS. I'm not a fan of inline, but even if i try to simply copy and paste his inline code to the main.css it does not take affect. I have no idea why that would be happening. If anybody has any advice that would be great!
Here is my Demo
<style type="text/css"></style></head>
<body class="desktop webkit webkit_525">
<div id="header">
<div class="content_width rel">
<a href="./Welcome to our site!_files/Welcome to our site!.html">
<div id="header_logo"></div>
</a>
<ul id="top_nav">
<li><a class="home_icon" href="./Welcome to our site!_files/Welcome to our site!.html">Home</a></li>
<li>Contact</li>
<li>Estimates</li>
<li>Help Center</li>
<li>Samples</li>
<li>Shopping Cart</li>
<li class="last-child">My Account</li>
</ul>
<ul id="loginbar" class="rounded">
<li>New Account</li>
<li class="last-child">Login</li>
</ul>
<div id="header_products"></div>
<div id="header_phone">Customer Service: (949) 215-9060</div>
<div id="product_search">
<input id="product_ti" class="default" type="text" value="Find A Product">
<input id="product_btn" type="button" value="Search">
<input id="product_default" type="hidden" value="Find A Product">
</div>
</div>
</div>
<div id="nav">
<ul id="nav_links" class="content_width_adjust">
<li id="4_color_offset_printing" style="width:183px; height:44px; background-color:#0C0; border-top: 4px solid #009ad6; -webkit-box-sizing: border-box; -moz-box-sizing: border-box;box-sizing: border-box;" class=""><a class="nav_parent narrow" href=""><span>4-Color Offset Printing</span></a></li>
<li id="large_format" style="width:139px" class=""><a class="nav_parent wide" href=""><span>Large Format</span></a></li>
<li id="1-2_color_printing" style="width:164px"><a class="nav_parent" href=""><span>1&2 Color Printing</span></a></li>
<li id="4_color_digital_printing" style="width:189px"><a class="nav_parent narrow" href=""><span>4-Color Digital Printing</span></a></li>
<li id="roll_labels" style="width:130px" class=""><a class="nav_parent wide" href=""><span>Roll Labels</span></a></li>
<li id="services" class="last " style="width:133px"><a class="nav_parent services" href=""><span>Services</span></a></li>
</ul>
</div>
An elements ID can't start with a number, only classes can. Removing the 4_ from '4_color_offset_printing' so you just have a ID of 'color_offset_printing' will allow you to target it in CSS.
If you really don't want to change your ID's, you can target ID's that begin with a number like this:
[id='4_color_offset_printing'] {
background: blue;
}
But I wouldn't recommend using that, it may not work well in all browsers. Best to do things the right way and not use numbers to start your ID's.
Need to add to the #nav_links li a:hover class
#nav_links li a:hover
{
background-color: blue;
}
https://jsfiddle.net/akdz7udj/7/

HTML/CSS a <div> won't go below another one

I have this page where all the div's seem to work and then all of the sudden my last one breaks. I have two divs in my CSS, one being centeredRight and one centeredLeft. They are lined up down the page. But my last div on the left seems to get pushed to the right.
Here is my CSS.
.centeredlistleft {
width: 300px;
margin: 0 auto;
text-align: left;
border: 2px solid;
float: left;
margin-bottom: 25px;
padding-right: 10px;
}
.centeredlistright {
width: 300px;
margin: 0 auto;
text-align: left;
border: 2px solid;
float: right;
margin-bottom: 25px;
padding-right: 10px;
}
.body {
margin: 0 auto;
padding: 0;
text-align: center;
color: purple;
background-color: pink;
}
And here is my HTML.
<div id="sandrcontainer" class="body" style="width:700px">
<div id="onsieforbaby" class="centeredlistleft" >
<h3> Onesie for Baby </h3>
<ul>
<li>
Price
<ul>
<li>$10.00</li>
</ul>
</li>
<li>
Description
<ul>
<li>It's a boy onesie for a new baby boy. Carter onesies are used. Can ask for specific size. Can also make one for girls using pink.</li>
</ul>
</li>
</ul>
</div>
<div id="largetennistowel" class="centeredlistright">
<h3> Large Tennis Towel </h3>
<ul>
<li>
Price
<ul>
<li>$14.00</li>
</ul>
</li>
<li>
Size
<ul>
<li>16 x 26 (Inches)</li>
</ul>
</li>
<li>
Description
<ul>
<li> Cotton fleece. Very soft. Washes Well. Can be personalized. Check out the photo gallery for examples. Ask seller what color towels are available at time of order.</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="sandrcontainer2" class="body" style="width:700px">
<div id="largegolftowel" class="centeredlistleft">
<h3> Large Golf Towel </h3>
<ul>
<li>
Price
<ul>
<li>$14.00</li>
</ul>
</li>
<li>
Size
<ul>
<li>16 x 26 (Inches)</li>
</ul>
</li>
<li>
Description
<ul>
<li> Golf towel. Elegant. Large white towel. Cotton fleece. Very soft. Can be personalized. Check out photo gallery for examples. Ask seller what color towels are avaiable at time of order. This towel has a grommet and can be hung on golf bags. Could also make this on fingertipe towel for guest bath or on linen towel for that elegant look.</li>
</ul>
</li>
</ul>
</div>
<div id="terrysmalltowel" class="centeredlistright">
<h3> Terry Small Towel </h3>
<ul>
<li>
Price
<ul>
<li>$11.00</li>
</ul>
</li>
<li>
Size
<ul>
<li>11 x 18 (Inches)</li>
</ul>
</li>
<li>
Description
<ul>
<li> With fringe. Made of 100% cotton loop terry. Can be personalized. Check out photo gallery for examples. Ask seller what color towels are avaiable at time of order.</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="sandrcontainer3" class="body" style="width:700px">
<div id="contactmerands" class="centeredlistleft" >
<p> Please make sure to send me an email before any orders. I may not have the color towel you want but can always order more </p>
</div>
<div id="smallfingertip" class="centeredlistright" >
<h3> Small Fintertip Holiday Towel </h3>
<ul>
<li>
Price
<ul>
<li>$11.00</li>
</ul>
</li>
<li>
Size
<ul>
<li>11 x 18 (Inches)</li>
</ul>
</li>
<li>
Description
<ul>
<li> Terry small towel with decorated cat for xmas. Made of 100% cotton loop terry. Can be personalized. Check out photo gallery for examples. Ask seller what color towels are available at time of order.</li>
</ul>
</li>
</ul>
</div>
</div>
TLDR - ctrl f for "Contactmerands" and please explain to me why this box is getting pushed to the bottom RIGHT of the large golf towel box. It should appear under the large golf towel box just like the rest of the divs.
If you would like to see what I mean you can go to my school web portal where I have the page posted HERE.
When an element is floated, it is essentially removed from the flow of the document. Thus, when a parent element's children are all floated, the parent collapses upon itself as it doesn't have any defined dimensions.
To solve this, you could set either overflow:hidden or overflow:auto on the parent elements. This essentially forces it to contain the children elements, therefore preventing it from collapsing.
Add the following CSS and your problem is solved:
#sandrcontainer,
#sandrcontainer2,
#sandrcontainer3 {
overflow: hidden;
}
Sometimes changing the overflow property will conflict with existing CSS. You could alternatively use the pseudo element clearfix:
.clearfix:after {
content: '';
clear: both;
display: table;
}
You must clear your floats in order to achieve the desired effect.
I suggest using a valid clearfix for this.
You need to declare this in CSS:
.clearfix:after {
clear:both;
content:".";
display:block;
font-size:0;
height:0;
visibility:hidden;
}
.clearfix { display:block; }
Now wrap all your elements that should float next to each other in a DIV and apply the clearfix class:
<div class="clearfix">
<!-- put your divs here //-->
</div>
<!--put your last div here //-->