I have this HTML code and CSS for a horizontal menu. It displays the links (boxes) from left to right floated to the left of the page.
What is the best way to make one of the links (boxes) display to float to the right of the page?
I have tried using float right with the below CSS copied as navigation-right and changed the HTML as needed but that did not work.
HTML
<div class="navigation-left">
<ul>
<li>Home</li>
<li>SAF</li>
<li>Acudetox</li>
</ul>
</div>
CSS
.navigation-left {
height:auto;
list-style:none;
margin-right:40px;
display:inline;
}
.navigation-left li{
width:200px;
height:25px;
margin:5px;
padding:5px;
background-color:#666666;
border:none;
text-align:center;
display:inline-block;
}
.navigation-left li:hover{
background-color:#f36f25;
color:#FFFFFF;
}
.navigation-left li a{
font-family:Calibri, Arial;
font-size:18px;
font-weight:bold;
color:#ffffff;
text-decoration:none;
}
.navigation-left li.current {
background-color:#F36F25;
}
.navigation-left li.current a {
color:#FFFFFF;
}
http://jsfiddle.net/W2x5y/
Is this Fiddle what you wanted?
<div class="navigation-left" style="float:left">
<ul>
<li>Home</li>
<li>SAF</li>
</ul>
</div>
<div class="navigation-left">
<ul style="float:right; ">
<li>Acudetox</li>
</ul>
</div>
As you might expect, a simple float: right; does the trick.
<div class="navigation-left">
<ul>
<li>Home</li>
<li style="float: right">SAF</li>
<li>Acudetox</li>
</ul>
</div>
http://jsfiddle.net/W2x5y/1/
I think that you'd have to target some of the li tags with a class if you wanted to do that. Plus you need to max the width of the containing ul in order to give it room to float on the right.
http://jsfiddle.net/W2x5y/2/
<div class="navigation-left">
<ul>
<li>Home</li>
<li>SAF</li>
<li class="right">Acudetox</li>
</ul>
</div>
ul {
width: 100%;
}
.right {
float: right;
}
Interesting questions. I'm hoping this helps.
You should anchor the navigation-left and navigation-right to a navigation box itself.
html:
<div class="nav-box">
<div class="nav-left">
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</div>
<div class="nav-right">
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</div>
</div>
CSS
body .nav-box {
top:0;
width:100%;
height:auto;
background:#eee;
overflow:hidden;
}
.nav-box .nav-left {
display:inline;
left:0;
float:left;
width:auto;
}
.nav-box .nav-right {
display:inline;
right:0;
top:0;
float:right;
width:auto;
}
Working example: http://jsfiddle.net/VA7ya/1/
It seems like the two navs are sufficient different to split them into two elements. Create two elements. Here's a Fiddle: http://jsfiddle.net/q7e3M/1/
<div class="container">
<div class="navigation-left">
<ul>
<li>Home</li>
<li>SAF</li>
</ul>
</div>
<div class="navigation-right">
<ul>
<li>Acudetox</li>
</ul>
</div>
</div>
If you want to keep the same element: http://jsfiddle.net/Afxkt/1/
<ul class="navigation">
<li>Home</li>
<li>SAF</li>
<li class="navigation-right">Acudetox</li>
</ul>
CSS:
.navigation {
display: inline;
list-style: none;
}
.navigation li {
float: left;
}
.navigation-right {
float: right;
}
All at right side
.right_side{ float:right}
<div class="navigation-left right_side">
<ul>
<li>Home</li>
<li>SAF</li>
<li>Acudetox</li>
</ul>
</div>
Last <li> to the right
.navigation-left li:last-child{ float:right}
first <li> to the right
.navigation-left li:first-child{ float:right}
second <li> to the right
.navigation-left li:nth-last-child(2){ float:right}
Related
Here yellow is <li> which is child of <ul> at the moment <li> or <ul> don't have float:left or display:inline as soon as I apply either float or display on <li> or <ul>
pink <li> which is child of nested <ul> changes it's appearance to this
<ul class="top_nav">
<li>name
<ul class="sub_nav">
<li>name1 icnkdn ndkcnks kkncksn </li>
<li>name2</li>
<li>name3</li>
</ul>
</li>
<li>home</li>
</ul>
.top_nav{
list-style-type:none;
padding:0;
}
.top_nav > li {
padding:1em 2em;
background:yellow;
position:relative;
}
.sub_nav{
position:absolute;
z-index:1;
background:green;
}
.sub_nav li{
display:block;
background:pink;
padding:1em 3em;
}
https://codepen.io/labeeb/pen/zRxoOR
Your .sub_nav has position: absolute; that's why your <li> element is collapsed. Remove this property and everything will be ok.
I am styling the navbar my simple side with the following code:
Html:
<div>
<ul class="navbar-brand">
<a href='https://postimg.org/image/ukcombaed/' target='_blank'><img src='https://s10.postimg.org/7vnhmqt0p/IMG_20160804_WA032.jpg' border='0' alt='IMG-20160804-WA032'/><br /><a target='_blank' href='https://postimage.org/'> </a><br /><br />
</ul>
<ul class="navbar-right">
<li>home</li>
<li>about</li>
<li>delivery</li>
<li>services</li>
</ul>
</div>
CSS:
ul{
list-style:none;
display:inline;
}
li{
list-style: none;
display: inline;
width:100%;
padding: 10px;
}
ul.navbar-brand{
float:left;
}
ul.navbar-right{
float:right;
}
As my snippet shows( https://jsfiddle.net/Wosley_Alarico/t3uhg5n1/1/ ). The logo is floated to the left and the menu to the right as I want. But the problem is that the menu went the top and would actually like it to be positioned to the bottom.
How can I actually make the menu go to the bottom instead and keep it floated to the right?
I can see few issues:
For 1st a tag there is no closing of it
You can remove 2nd a if you are not using
ul can't be used with li so, changed it to div or span
Remove float:right from navbar-right class it will come in the bottom of logo.
add a ul class with magin, padding 0
ul{
list-style:none;
display:inline;
margin:0;
padding:0;
}
li{
list-style: none;
display: inline;
width:100%;
padding:10px 10px 10px 0;
}
ul.navbar-brand{
float:left;
}
ul.navbar-right{
}
<div>
<div class="navbar-brand">
<a href='https://postimg.org/image/ukcombaed/' target='_blank'><img src='https://s10.postimg.org/7vnhmqt0p/IMG_20160804_WA032.jpg' border='0' alt='IMG-20160804-WA032'/></a>
</div>
<ul class="navbar-right">
<li>home</li>
<li>about</li>
<li>delivery</li>
<li>services</li>
</ul>
</div>
ul.navbar-right{
float:right;
position:relative;
bottom:0;
}
I'm just barely learning how to code. I know there is more than one way to skin a cat, but what is the most efficient way to create a typical menu with lists, search fields, etc.?
I've been able to create all of the elements. I am having a very hard time getting the CSS correct to look the way I want.
Here is what my current project looks like.
This is what I am trying to achieve.
Thanks for the help! Any tips for a beginner would also be appreciated. Thank you!
Here is my HTML
<!DOCTYPE html>
<html lan="en">
<head>
<meta charset ="UTF-8">
<link href = "racemonster.css" rel="stylesheet" type="text/css">
<title>Home</title>
</head>
<body>
<div class="headerLeft">
<h1>Name</h1>
</div>
<div class="headerRight">
<ul>
<li>Cart</li>
<li>Help</li>
<li>Sign In</li>
<li>Sign Up</li>
</ul>
</div>
<div class="menu">
<ul>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
Here is the css
.headerLeft{color:#C4D82D;font-family:sans-serif;background-color:#323232;width:100%;margin:0;padding:20px;top:0;left:0;}
.headerRight{color:#B1B3B5;font-family:sans-serif;background-color: #323232;width:100%;margin:0;padding:20px;top:0;left:0;}
.headerRight ul {list-style-type: none;}
.headerRight ul li{display: inline;margin-right: 20px}
.headerRight ul li a{text-decoration: none;font-family: sans-serif;color: #898B8E;background-color:#323232;}
.headerRight ul li a:hover{color:#B1B3B5;}
.menu ul {list-style-type: none;width:100%; margin:0; padding-top:40px; padding-bottom:40px; background-color: #C4D82D}
.menu ul li {display:inline;margin-right: 20px;}
.menu ul li a {text-decoration: none;font-family: sans-serif;color:#323232;background-color: #C4D82D;}
.menu ul li a:hover {color:#999B9D;}
Updated Answer
Here is a solution... first check out my code (http://jsfiddle.net/ProgrammerKid/s01yuzm1/)
HTML
<div class="headers">
<div class="headerLeft">
<h1>Name</h1>
</div>
<div class="headerRight">
<ul>
<li>Cart
</li>
<li>Help
</li>
<li>Sign In
</li>
<li>Sign Up
</li>
</ul>
</div>
<div class="header-padding"> </div>
</div>
<div class="menu">
<ul>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
</div>
CSS
.headers {
width: 100%;
position: static;
}
.headerLeft {
width: 50%;
float: left;
box-sizing: border-box;
height: 120px;
}
.headerRight {
width: 50%;
box-sizing: border-box;
float: right;
height: 120px;
}
.header-padding {
height: 120px;
}
What I like to do is group the two headers into one big <div> so that they both share a common parent (disregarding the <body>)... Then I added a CSS float property, and set their width to 50%. This will align them...
The <div class="header-padding">[...]</div> element is to provide the links sections with enough padding... Since we float the two div's (.headerRight, and .headerLeft) the links sections would appear underneath the headers... therefore by placing the header padding element, we are providing the links section with enough space.
Old Answer
There is no "correct" way to make a header
That being said, it would be really helpful to the people answering your question if you included the HTML/CSS/JS code...
For now I will use a very abstract method of conveying my tips to you...
If we said the element with the word "NAME" inside it was a <div id="1"></div> and the element in which your menu items are in would be <div id="2"></div>, and the links were <div id="3"></div>
Then here is what your CSS should look like:
#1 {
width: 40%;
float: left;
}
#2 {
width: 50%;
float: left;
}
the above will align both the elements together
and below we will reduce the padding to around 10px;
#3 {
padding: 10px;
}
and that's all I can help you with for now until you upload your code
I have created css as you required it is very straightforward and easy to understand.
enter link description here
.container {
background-color:#323232;
}
.title {
color:#C4D82D;
margin-left:40px;
}
.headerLeft {
width:50%;
float:left;
height:100px;
display:inline-block;
}
.headerRight {
width:50%;
height:100px;
display:inline-block;
}
.headerRight ul li {
display:inline;
color:#B1B3B5;
}
.headerRight ul li a {
color:#b1b3b5;
}
.headerRight ul li a:hover {
color:#B1B3B5;
}
.menu {
background-color:#C4D82D;
height:50%;
position:relative;
padding-top:20px;
margin:(auto, auto, 0, 0);
}
.menu ul li {
display:inline;
}
.menu ul li a {
color:#323232;
}
.menu ul li a:hover {
color:#999B9D;
}
<body>
<div class="container">
<div class="headerLeft">
<h1 class="title">Name</h1>
</div>
<div class="headerRight">
<ul>
<li>Cart |
</li>
<li>Help |
</li>
<li>Sign In |
</li>
<li>Sign Up |
</li>
</ul>
</div>
<div class="menu">
<ul>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
</div>
</div>
</body>
I am using five div in my footer content with equal dividing space. But it is going to the next line instead of showing in one line. Check my fiddle here http://jsfiddle.net/7ZAA6/.
HTML
<div class="mainFooterLinks">
<div class="divideFooter">
<div class="fl_title">Test</div>
<div class="fl_links">
<ul>
<li>Solutions</li>
<li>Services</li>
<li>DotNetNuke</li>
<li>Web Design & Development</li>
<li>EDC</li>
</ul>
</div>
</div>
<div class="divideFooter">
<div class="fl_title">Test Sharepoint</div>
<div class="fl_links">
<ul>
<li>Services</li>
<li>Web Parts</li>
<li>Solutions</li>
<li>SharePoint Support</li>
</ul>
</div>
</div>
<div class="divideFooter">
<div class="fl_title">Test CRM</div>
<div class="fl_links">
<ul>
<li>Products</li>
<li>Test Support</li>
<li>Services</li>
<li>Test CRM</li>
</ul>
</div>
</div>
<div class="divideFooter">
<div class="fl_title">Test DNN</div>
<div class="fl_links">
<ul>
<li>Website Development</li>
<li>Skins</li>
<li>Modules</li>
<li>Support & Maintenance</li>
<li>EDC</li>
</ul>
</div>
</div>
<div class="divideFooter">
<div class="fl_title">Test K12 DRM</div>
<div class="fl_links">
<ul>
<li>What is K12DRM?</li>
<li>K12DRM Features</li>
</ul>
</div>
</div>
CSS
.mainFooterLinks
{
max-width:1200px;
background-color:#333;
padding:20px 0px 20px 0px;
margin:0px auto;
box-sizing:border-box;
}
.divideFooter
{
display:inline-block;
width:20%;
vertical-align:top;
padding:0;
margin:0;
}
.fl_title
{
font-family:Arial;
color:#cdcdcd;
font-size:15px;
font-weight:700;
padding-left:15px;
}
.fl_links a, .fl_links a:link, .fl_links a:active, .fl_links a:visited
{
font-family:Arial;
color:#636363;
font-size:12px;
font-weight:400;
text-decoration:none;
}
.fl_links a:hover
{
text-decoration:underline;
}
.fl_links ul
{
list-style-type:none;
list-style-image:url('fbull.jpg');
padding:7px 10px 5px 30px;
margin:0;
}
My Solution: If I add float:left property on divideFooter class and the bottom of the last div, adding one more div with clear:both property is working fine here.
But why the inline-block not working properly? Recent time many people are told like do not use float property, use inline-block property. So that i want to know the reason what is wrong my code?
Add font-size: 0 to your .mainFooterLinks class. With inline-blocks element, whitespace is added between them
It is because using inline-block considers line breaks as whitespace characters. You can overcome this issue by applying font-size=0 in the parent container, like this:
.mainFooterLinks
{
max-width:1200px;
background-color:#333;
padding:20px 0px 20px 0px;
margin:0px auto;
box-sizing:border-box;
font-size: 0;
}
and then reset the font size in inner container (.divideFooter in this case).
The reason it's happening is stated in the answers above..
A good solution you can use is this:
.mainFooterLinks {
white-space:nowrap;
}
.divideFooter {
white-space:normal;
}
This will get everything on the same line.. after that tweak your padding's to make everything fit ;]
EXAMPLE
I have some code that has the property display-inline. Due to this it displays the list horizontally. Now, I placed an image in my code and it appeared after the list. I wanted the image to be displayed below the list so I placed the list into a div but still its getting displayed next to the list. Here is the code,
<ul id="list-nav">
<li>Home</li>
<li>About Book</li>
<li>Contact</li>
</ul>
</div><!--navigation div ends-->
<!--<div>-->
<img src="Book_Cover-465x540.png" />
CSS of list-nav:
ul#list-nav {
margin:40px;
padding:0;
list-style:none;
width:525px;
}
ul#list-nav li {
display:inline
}
ul#list-nav li a {
text-decoration:none;
padding:5px 0;
width:100px;
background:#000000;
color:#eee;
float:left;
}
ul#list-nav li a {
text-align:center;
border-left:15px solid #fff;
}
Please help out. Thanks
Remove the float from a.
Also: what the heck is border-left:15px solid #fff;, didn't you mean left margin?
try this:
<div>
<ul id="list-nav">
<li>Home</li>
<li>About Book</li>
<li>Contact</li>
</ul>
</div><!--navigation div ends-->
<!--<div>-->
<div style="clear:both"></div>
<img src="Book_Cover-465x540.png" />