I am currently using floats in order to place my logo in the center of my fixed navigation menu. The issue I'm facing currently is that the items I've floated to the right are displaying in reverse order.
How do I use text-align to achieve desired result and still maintain a fixed navigation header?
current code:
<img src="img/logo.png" class="logo" />
<ul class="nav">
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
</ul>
css:
header {
width: 100%;
padding: 0, 100px, 0, 0;
margin: 10px, 100px, 35px, 0 ;
position: fixed;
height: 6em;
background: transparent;
top: 0;
z-index: 1;
}
header .logo {
display: block;
height: 110px;
text-indent: -9999px;
width: auto;
margin: 0 auto;
position: relative;
}
header ul {
margin: -85px auto 0 auto;
height: 10px;
list-style: none;
}
header li:nth-child(1), header li:nth-child(2), header li:nth-child(3){
float: left;
}
header li:nth-child(4), header li:nth-child(5), header li:nth-child(6){
float: right;
}
Most obvious solution, break the menu into two and put the logo in the middle...then float each menu as required.
* {
margin: 0px;
padding: 0;
}
ul {
margin: 0;
list-style: none;
display: inline-block;
}
li {
display: inline-block;
}
a {
background: grey;
color: white;
padding: .5em;
}
nav {
text-align: center;
}
.left {
float: left;
text-align: left;
}
.right {
float: right;
text-align: right;
}
<nav>
<ul class="nav left">
<li>A
</li>
<li>B
</li>
<li>C
</li>
</ul>
Logo
<ul class="nav right">
<li>D
</li>
<li>E
</li>
<li>F
</li>
</ul>
</nav>
Of course, you may want all the items bunched together..in which case you don't need the floats at all
JSFiddle Demo
Then again, there's this one I like (not mine) which is even better : Codepen Demo
Related
I have a logo image on the upper left side of the site and want my nav to show on the upper right side of the site. The nav is showing on the right side of the page but instead of being parallel to the logo it is below it even thought the logo is on the left side. Any idea what I am missing in the code below that is preventing the nav from moving up.
#charset 'UTF-8';
html,
html * {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: arial, sans-serif;
<!-- font-size: 1vw;>
background: white;
}
img {
width: 100%;
max-width: 100%;
height: auto;
vertical-align: middle;
-webkit-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);
}
a, a:visited {
color: inherit;
}
header {
position: fixed;
padding: 1.5em;
top: 0;
left: 0;
width: 100%;
z-index: 1000;
}
.site-logo {
width: 30%;
max-width: 30%;
position: relative;
display: block;
}
.site-logo img {
width: 22em;
}
.logo {
opacity: 1;
}
.site-nav {
position: relative;
float: right;
z-index: 400;
top: 0;
left: 0;
display: block !important;
width: 68%;
padding: .75em 1em 0 0;
opacity: .95;
background: none;
}
.site-nav ul {
list-style-type: none;
margin: 0;
text-align: right;
}
.site-nav ul li {
display: inline-block;
margin-bottom: 0;
margin-left: 1.5em;
}
.site-nav ul li a {
font-size: .85em;
padding-bottom: .5em;
text-decoration: none;
letter-spacing: .15em;
text-transform: uppercase;
color: #000000;
-webkit-transition: color .3s;
transition: color .3s;
}
.site-nav ul li a:hover {
outline: none;
border-bottom: 1px solid black;
}
HTML
<header>
<!-- Logo -->
<a class="site-logo">
<img class="logo" src="images/SBI Logo.png" alt=""/>
</a>
<!-- Navigation Menu -->
<nav class="site-nav">
<ul>
<li>Home</li>
<li>Rooms</li>
<li>Gift Certificates</li>
<li>About Us</li>
<li>Things To Do</li>
<li>Contact Us</li>
<li>Blog</li>
</ul>
</nav>
</header>
enter image description here
You are getting bogged down in the style sheet and using EM too, it would be much easier for you to use PIXELS instead of EM to position your elements.
<style>
.mysitelogo
{
margin-top: 16px;
width: 458px;
height: 114px;
}
.mysitenav
{
float: right;
padding: 8px;
opacity: .95;
}
</style>
<header>
<!-- Logo -->
<img class="mysitelogo" src="logo.gif" alt="" />
<!-- Navigation Menu -->
<nav class="mysitenav">
<ul>
<li>Home</li>
<li>Rooms</li>
<li>Gift Certificates</li>
<li>About Us</li>
<li>Things To Do</li>
<li>Contact Us</li>
<li>Blog</li>
</ul>
</nav>
</header>
Using the code above you can get the layout you desire, THEN fine tune your layout in the stylesheet.
Some times it is easier to break the bigger problem down into basic parts.
Read this page for better understanding of using EM which is relative to FONT SIZE
https://www.w3schools.com/CSSref/css_units.asp
I am trying to make horizontal navigation bar and right now my div navigation bar doesn't use max-width: 1200px which is set on <body> so my unordered list isn't floated to the right of the screen. Adding width: 100% or inherit to navigation does not help, width 100% is way more than my max-width.
body {
margin: 0 auto;
max-width: 1200px;
font-family: Helvetica, Arial;
background-color: #F7F7F7;
}
#wrapper {
position: relative;
z-index: 0;
margin: 1% 4% 2%;
padding: 1rem;
}
#navigation {
position: fixed;
}
#navigation ul {
list-style-type: none;
margin: 0;
padding: 0;
}
#navigation li {
float: right;
}
<div id="wrapper">
<div id="navigation">
<ul>
<li>Home
</li>
<li>Projects
</li>
<li>About
</li>
<li>Contact
</li>
</ul>
</div>
</div>
I moved your max-width to your #navigation element, and set it to 100% width.
Also I moved your padding down to your ul element.
Here's the updated fiddle.
#navigation {
position: fixed;
max-width:1200px;
width:100%;
border: 1px solid red;
}
#navigation ul {
list-style-type: none;
margin: 0;
padding: 0;
padding: 1rem;
}
I think maybe the position fixed makes the div ignore the parent elements max-width
I am wanting to display <li>'s as squares in a horizontal line, and have nested squares within them positioned at the bottom left and bottom right of the containing square.
____________ ____________
| | | |
|___ ___| |___ ___|
|_x_|__|_y_| |_x_|__|_y_| etc
I tried adding span's to the <li> but wasn't able to position them correctly.
I've gotten closer with a nested <ul> and two <li>'s within the nested <ul> but there is undesired space between the top level squares.
How do I get control of the spacing between the top level <li>'s?
jsFiddle
http://jsfiddle.net/rwone/4Hzp6/
HTML
<ul class="images_list">
<li class="style_one"><img src="http://dummyimage.com/50/ccc/fff&text=1.png">
<ul class="nested"><li class="delete_span"></li><li class="crop_span"></li></ul>
</li>
<li class="style_one"><img src="http://dummyimage.com/50/ccc/fff&text=2.png">
<ul class="nested"><li class="delete_span"></li><li class="crop_span"></li></ul>
</li>
<li class="style_one">
<img src="http://dummyimage.com/50/ccc/fff&text=3.png">
<ul class="nested"><li class="delete_span"></li><li class="crop_span"></li></ul>
</li>
<li class="style_one">
<img src="http://dummyimage.com/50/ccc/fff&text=4.png">
<ul class="nested"><li class="delete_span"></li><li class="crop_span"></li></ul>
</li>
<li class="style_one">
<img src="http://dummyimage.com/50/ccc/fff&text=5.png">
<ul class="nested"><li class="delete_span"></li><li class="crop_span"></li></ul>
</li>
</ul>
CSS
ul.images_list {
list-style: none;
margin: 0px !important;
padding: 0px !important;
}
ul.nested {
margin: 0px !important;
padding: 0px !important;
display: inline;
position: relative;
left: -54px;
}
li.style_one {
position:relative;
display:inline-block;
/*width: 50px;
height:50px*/
}
.delete_span {
width: 15px;
height: 15px;
background: red;
display: inline-block;
}
.crop_span {
width: 15px;
height: 15px;
background: green;
display: inline-block;
position: relative;
left: 20px;
}
It seams that the problem come from user agent stylesheet (on chrome). Chrome is adding a rules This SO question is talking about it.
It suggest to add ul { padding:0 } but that is not working on your case..
But It might get you on the direction.
ul, menu, dir {
display: block;
list-style-type: disc;
-webkit-margin-before: 1em;
-webkit-margin-after: 1em;
-webkit-margin-start: 0px;
-webkit-margin-end: 0px;
-webkit-padding-start: 40px;//I guess this one is the problem
}
I have tried to override this rules adding !important but it doesn't work.
This achieves the behaviour of what I wanted, I used div's within <li>'s:
http://jsfiddle.net/rwone/4Hzp6/6/
HTML
<ul class="images_list">
<li class="style_one"><img src="http://dummyimage.com/50/ccc/fff&text=1.png">
<div class="crop_it"></div><div class="delete_it"></div>
</li>
<li class="style_one"><img src="http://dummyimage.com/50/ccc/fff&text=2.png">
<div class="crop_it"></div><div class="delete_it"></div>
</li>
<li class="style_one">
<img src="http://dummyimage.com/50/ccc/fff&text=3.png">
<div class="crop_it"></div><div class="delete_it"></div>
</li>
<li class="style_one">
<img src="http://dummyimage.com/50/ccc/fff&text=4.png">
<div class="crop_it"></div><div class="delete_it"></div>
</li>
<li class="style_one">
<img src="http://dummyimage.com/50/ccc/fff&text=5.png">
<div class="crop_it"></div><div class="delete_it"></div>
</li>
</ul>
CSS
ul.images_list {
list-style: none;
margin: 0px !important;
padding: 0px !important;
}
li.style_one {
display: inline-block;
height: 50px;
margin-left: 15px;
position: relative;
width: 50px;
}
li.style_one:first-child {
margin-left: 0px;
}
.crop_it {
background: none repeat scroll 0 0 #FF0000;
bottom: 0;
display: inline-block;
height: 15px;
left: 0;
position: absolute;
width: 15px;
z-index: 9;
}
.delete_it {
background: none repeat scroll 0 0 #008000;
bottom: 0;
display: inline-block;
height: 15px;
left: 35px;
position: absolute;
width: 15px;
}
Simple just change the class ul.nested position relative to position absolute and little bit changes in left and top or copy paste the code below:
CSS CODE:
ul.images_list {
list-style: none;
margin: 0px !important;
padding: 0px !important;
}
ul.nested {
margin: 0px !important;
padding: 0px !important;
display: inline;
position: absolute;
left: 0px;
top: 34px;
}
li.style_one {
position:relative;
display:inline-block;
/*width: 50px;
height:50px*/
}
.delete_span {
width: 15px;
height: 15px;
background: red;
display: inline-block;
}
.crop_span {
width: 15px;
height: 15px;
background: green;
display: inline-block;
position: relative;
left: 20px;
}
I have a menu and a logo on the header, and I am struggling to make the logo to be at the far edge of the left side of the website and the menu to the edge of the right side.
The problem is, when both of them are displayed as inline-block which means they are going to float to the default orientation which is left, I can't figure out a way to change this, please help.
Here's the CSS code:
/*Header*/
.wrapperHeader{
background-color: #FFFFFF;
border-bottom: 1px solid #DDDDDD;
width: 100%;
padding: 15px 0px;
z-index: 1000;
}
.content{
width: 1000px;
max-width: 100%;
margin: auto;
}
.header-logo, #logoImage{
width: 250px;
max-width: 100%;
display: inline-block;
vertical-align: middle;
}
/*Main Menu*/
.header-menu{
width: 690px;
max-width: 100%;
display: inline-block;
vertical-align: middle;
}
#MainMenu li{
position: relative;
padding: 15px;
display: inline-block;
right: 0px;
}
Note: in the html, the logo is in a section and the menu is in anther section and both of them are inside a divide.
HTML code:
<header>
<div class="wrapperHeader">
<div class="content">
<section class="header-logo">
<img id="logoImage" src="assets/elements/logo.png" alt="LOAI Design Studio Logo"/>
</section>
<section class="header-menu">
<nav id="MainMenu">
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li id="PortfolioMenu"><a id="Portfolio" href="#">Portfolio</a>
<ul class="subMenu">
<li>Web Design</li>
<li>Visual Identity</li>
<li>Photography</li>
</ul>
</li>
<li>Testimonials</li>
<li>About Me</li>
<li>Get In Touch</li>
<li><a class="getStartedButton" href="get-started.html">Get Started</a></li>
</ul>
Menu<p id="SmartMenu-logo">LOAI Design Studio</p>
</nav>
</section>
</div>
</div>
</header>
Here I've edited your CSS code, so you can try this
/*Header*/
.wrapperHeader{
background-color: #FFFFFF;
border-bottom: 1px solid #DDDDDD;
padding: 15px 0px;
z-index: 1000;
overflow: hidden;
}
.content{
width: 1000px;
margin: auto;
}
.header-logo, #logoImage{
width: 250px;
float: left;
}
/*Main Menu*/
.header-menu{
width: 690px;
float: right;
}
#MainMenu ul{
margin: 0;
padding: 0;
list-style: none;
}
#MainMenu li{
position: relative;
padding: 5px 15px;
float: left;
list-style: none;
}
li#PortfolioMenu{
padding: 0;
}
li#PortfolioMenu > a{
padding: 5px 15px;
}
ul.subMenu{
display: none;
position: absolute;
}
li:hover ul.subMenu{
display: block;
}
I've used float:left; for the logo, float:right; for the header-menu, removed display:inline-block; and did some other fixes ...
Hope this will help you ...
I would float logo section left, float menu section right and then clear the wrapper using clear:both. Remove the inline-block for this to work properly.
I feel as if I have tried everything from text-align center to margin:0 auto with a position relative and width of 100%, but they didn't work, I am trying to center my UL inside the div...
Here is my code
<style type="text/css">
.header {
height: 40px;
background: #000;
width: 100%;
}
.header ul {
list-style-type: none;
}
.header li {
float: left;
line-height: 40px;
}
.header li a {
color: #FFF;
padding: 0 18px;
height: 40px;
}
</style>
<div class="header">
<ul>
<li>Home</li>
<li>About</li>
<li>Gallery</li>
<li>Services</li>
<li>Rates</li>
<li>Reviews</li>
<li>FAQ</li>
<li>Contact</li>
</ul>
</div>
This works without having to define a set width.
ul {
display: table;
margin: 0 auto;
}
If you want to get rid of the left-side padding, thus genuinely centering the list, add:
padding-left: 0;
This should fix it for you.
ul {
display: inline-block;
margin: 0 auto;
}
If that doesn't work for you then give the UL a set width i.e.
ul {
width: 300px;
margin: 0 auto;
}