Center only the middle <li> - html

My fiddle so far:
https://jsfiddle.net/dzjqor2d/
I just can't get the middle <li> to center, whatever I try.
My Code:
ul {
width: 60%;
overflow: auto;
background-color: #F5FAFF;
padding: 20px;
}
ul li {
list-style: none;
float: left;
padding: 10px 20px;
background-color: #388CD1;
color: #F5FAFF;
position: relative;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
ul li:last-child {
float: right;
}
<ul>
<li>
Empty cart
</li>
<li>
Continue shopping
</li>
<li>
Update cart
</li>
</ul>
Note:
Content is dynamic, so is the width of the container

make first li to left and last to right rest will float as per ul's text-alignment:
ul {
width: 60%;
overflow: auto;
background-color: #F5FAFF;
padding: 20px;
text-align: center;
}
ul li {
list-style: none;
display:inline-block;
padding: 10px 20px;
background-color: #388CD1;
color: #F5FAFF;
position:relative;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
ul li:last-child{
float:right;
}
ul li:first-child{
float: left;
}
demo

You shouldn't need to float the last li right, use margins to get the alignments right:
ul li {
margin: 0 20px;
list-style: none;
float: left;
padding: 10px 20px;
background-color: #388CD1;
color: #F5FAFF;
position:relative;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
https://jsfiddle.net/dzjqor2d/8/

You may try using the CSS3 :nth-child() Selector with your ul and li tag
HTML
<ul>
<li>
Empty cart
</li>
<li>
Continue shopping
</li>
<li>
Update cart
</li>
</ul>
CSS
ul {
width: 60%;
overflow: auto;
background-color: #F5FAFF;
padding: 20px;
text-align:center;
}
ul li {
list-style: none;
display:inline-block;
padding: 10px 20px;
background-color: #388CD1;
color: #F5FAFF;
position: relative;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
ul li:nth-child(1){
float:left;
}
ul li:nth-child(3){
float:Right;
}

These days flexbox is the way to go, in the past floating was great, but now not so much.
for the UL I've added display: flex; and justify-content: space-between; this means; make them all fit in one block and if there is extra space, just put have space between them.
Here have a look:
body {
margin: 0;
}
ul {
display: flex;
justify-content: space-between;
width: calc(100% - 40px);
background-color: #F5FAFF;
padding: 20px;
}
ul li {
list-style: none;
padding: 10px 20px;
background-color: #388CD1;
color: #F5FAFF;
position: relative;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
<ul>
<li>
Empty cart
</li>
<li>
Continue shopping
</li>
<li>
Update cart
</li>
</ul>
I've changed the width to make the example easier to see.
Hope this helps.

Just use below css for ul:
ul {width: 70%;overflow: auto;background-color: #F5FAFF;padding:20px;display: flex;}

Related

How do I center the navigation bar "buttons"?

I'm making a website for fun and want to center my navigation bar but nothing seems to work. I want the navigation bar full the whole width but have the "buttons" in the middle. And also being responsive, I already tried adding in the css (navbar li): margin-left: 50%. But this isn't what I am looking for, margin-left: auto and margin-right: auto also doesnt work. I tried using display: inline-block and text-align: center; but it doesn't work. Do you have any suggestions?
.navbar {
position: relative;
margin-top: -47px;
}
.navbar ul {
width: 99%;
list-style-type: none;
margin: auto;
padding: 0;
overflow: hidden;
background-color: rgba(0, 0, 0, 0.5);
}
.navbar li {}
.navbar li a {
float: left;
color: white;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: rgba(0, 0, 0, 0.8);
}
.dropdown-content {
display: none;
position: absolute;
margin-top: 47px;
background-color: rgba(0, 0, 0, 0.8);
text-align: center;
min-width: 120px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown:hover .dropdown-content {
display: block;
}
.active {
background-color: rgba(0, 0, 0, 0.8);
color: white;
}
<div class="navbar">
<ul>
<li><a class="active" href="index.html">Home</a></li>
<li class="dropdown">Plans
<div class="dropdown-content">
Route
Places I want to go
My budget
</div>
</li>
<li class="dropdown">Journey
<div class="dropdown-content">
South-Africa
Thailand
Country1
Country2
Country3
Country4
</div>
</li>
<li>Photos</li>
<li>Other websites</li>
<li class="dropdown">About</li>
</ul>
</div>
Have you tried setting display: flex; on your <ul>? Then you should be able to add justify-content: center;.
By setting text-align: center; on the .navbar ul and display:inline-block; on .navbar ul, as seen below:
.navbar ul {
width: 99%;
list-style-type: none;
margin: auto;
padding: 0;
overflow: hidden;
background-color: rgba(0,0,0,0.5);
text-align: center;
}
.navbar li {
display: inline-block;
}

Submenu, set position more left

i've a small problem with my slide menu. The slide is fadin in from down to up. This also is working fine.
But now I want to set the position a bit more to the left side, so that i get a line with the main menu.
Maybe someone can help me. This is my sample...
This is my code... [Menu][1] https://jsfiddle.net/Tabes/eb52suo1/15/
Here is your solution
.flex-box {
width: 100%;
min-height: 0;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
align-items: flex-start;
align-content: flex-start;
}
.navigation {
background-image: linear-gradient(#444, #111);
background-color: #111;
width: 100%;
}
/* ******************************************************************************************* */
/* ***** Main Navigation - Main Level ******************************************************* */
/* ******************************************************************************************* */
.nav_main {
background: transparent;
list-style: none;
}
.nav_main ul:before,
.nav_main ul:after {
content: "";
display: table;
}
.nav_main ul {
list-style: none outside none;
position: relative;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
align-content: center;
margin: 0px;
padding: 0px;
min-width: auto;
min-height: auto;
zoom: 1;
}
.nav_main ul li:before,
.nav_main ul li:after {
content: "";
display: inline;
}
.nav_main ul li.icon:before,
.nav_main ul li.icon:after {
display: inline-block;
margin: 2px 15px 0px 0px;
width: 15px;
height: 15px;
}
.nav_main ul li.icon:before {
background: url("../pic/icons/glyphicons-387-log-in.png") no-repeat top right;
background-size: 15px;
float: left;
margin: 2px 15px 0px 0px;
}
.nav_main ul li.icon:after {
background: url("../pic/icons/glyphicons-415-disk-save.png") no-repeat top left;
background-size: 15px;
float: right;
margin: 2px 0px 0px 15px;
}
.nav_main ul li>img.before,
.nav_main ul li>img.after {
display: inline-block;
margin: 2px 15px 0px 0px;
width: 15px;
height: auto;
}
.nav_main ul li>img.before {
float: left;
margin: 2px 15px 0px 0px;
}
.nav_main ul li>img.after {
float: right;
margin: 2px 0px 0px 15px;
}
.nav_main ul li:last-child {
border-right: none;
box-shadow: none;
}
.nav_main ul li:hover {
background: #444;
display: inline-block;
margin: 0px;
padding: 10px 35px;
min-width: auto;
min-height: auto;
}
.nav_main ul li {
border-right: 1px solid #222;
box-shadow: 1px 0 0 #444;
cursor: pointer;
text-align: center;
display: inline-block;
flex: 0 0 auto;
position: relative;
margin: 0px;
padding: 10px 35px;
min-width: auto;
min-height: auto;
}
.nav_main ul li>a:hover {
color: #fafafa;
}
.nav_main ul li>a {
font: bold 12px Arial, Helvetica;
text-transform: uppercase;
text-decoration: none;
text-shadow: 0 1px 0 #000;
color: #999;
}
.nav_main ul li:hover>ul {
visibility: visible;
opacity: 1;
margin: 0;
}
/* ******************************************************************************************* */
/* ***** Main Navigation - Level #1 ******************************************************** */
/* ******************************************************************************************* */
.nav_main ul ul {
list-style: none outside none;
position: absolute;
background: #444;
box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.3);
border-radius: 3px;
flex-direction: column;
align-items: flex-start;
visibility: hidden;
opacity: 0;
top: 40px;
left: 0;
z-index: 5;
transition: all 0.2s ease-in-out;
margin: 10px 0px 0px 0px;
padding: 0px;
min-width: 185px;
min-height: 35px;
width: auto;
}
.nav_main ul ul li:before,
.nav_main ul ul li:after {
content: "";
display: inline;
}
.nav_main ul ul li.icon:before,
.nav_main ul ul li.icon:after {
display: inline-block;
margin: 4px 35px 0px 0px;
width: 15px;
height: 15px;
}
.nav_main ul ul li.icon:before {
background: url("../pic/icons/glyphicons-387-log-in.png") no-repeat top right;
background-size: 15px;
float: left;
margin: 4px 35px 0px 0px;
}
.nav_main ul ul li.icon:after {
background: url("../pic/icons/glyphicons-415-disk-save.png") no-repeat top left;
background-size: 15px;
float: right;
margin: 4px 0px 0px 35px;
}
.nav_main ul ul li>img.before,
.nav_main ul ul li>img.after {
display: inline-block;
margin: 4px 35px 0px 0px;
width: 15px;
height: auto;
}
.nav_main ul ul li>img.before {
float: left;
margin: 4px 35px 0px 0px;
}
.nav_main ul ul li>img.after {
float: right;
margin: 4px 0px 0px 35px;
}
.nav_main ul ul li:hover {
background: #444;
background-image: linear-gradient(#04acec, #0186ba);
background-color: #0186ba;
display: inline-block;
margin: 0px;
padding: 5px 15px;
min-width: 185px;
min-height: 35px;
}
.nav_main ul ul li:first-child:hover {
border-radius: 3px 3px 0px 0px;
}
.nav_main ul ul li:last-child:hover {
border-radius: 0px 0px 3px 3px;
}
.nav_main ul ul li {
border: none;
box-shadow: none;
text-align: left;
display: inline-block;
flex: 0 0 auto;
margin: 0px;
padding: 5px 15px;
min-width: 185px;
min-height: 35px;
}
.nav_main ul ul li>a:hover {
color: #fafafa;
}
.nav_main ul ul li>a {
font: bold 12px Arial, Helvetica;
text-transform: uppercase;
text-decoration: none;
text-shadow: 0 1px 0 #000;
color: #999;
}
.nav_main ul ul li:hover>ul {
visibility: visible;
opacity: 1;
margin: 0;
}
<!-- Main Navigation (Container for JavaScript Function)-->
<div id="Navigation" class="navigation">
<!-- ### Main Navigation Link Liste ### -->
<nav id="Nav_Main" class="nav_main">
<ul class="flex-box">
<li>
Home
<ul class="flex-box">
<li>
Referenzen
</li>
<li>
Downloads
</li>
<li>
Partner Programm
</li>
<li>
Existenzgründer
</li>
<li>
<!-- Philosophie -->
Philosophie
</li>
</ul>
</li>
<li>
Hosting
<ul class="flex-box">
<li>
Web Hosting
</li>
<li>
TYPO3
</li>
<li>
WordPress
</li>
<li>
Magento
</li>
<li>
PrestaShop
</li>
</ul>
</li>
<li>
<a class="ajaxy" href="webdesign.html">WebDesign</a>
</li>
</ul>
</nav>
<!-- ### Main Navigation Link Liste End ### -->
</div>
<!-- Main Navigation Container End -->
Inside your flex-box class you can add a margin-left: -35px; and it will fix the position of the sub menu according to the snippet. You should mention though, that this might cause problems for the responsive part of your site.

Trying to center naviation bar

I am having problems trying to center the navigation bar on my web page. I tried creating a wrapper div to center it, but it doesn't seem to work. The only thing that works in that div are changing the left margin. Here is the HTML:
body {
background: #bf5c71 url('body-bg.jpg');
}
.clearfix:after {
display: inline-block;
clear: both;
align-content: center;
}
/*----- Menu Outline -----*/
.menu-wrap {
box-shadow: inset 0px 0 0 rgba(255, 255, 255, 0.00);
-webkit-box-shadow: inset 0px 0 0 rgba(255, 255, 255, 0.00);
display: inline-block;
margin: 0px auto;
}
.menu {
display: inline-block;
margin: auto;
}
.menu li {
margin-top: 0px;
margin-right: 0px;
margin-left: 0px;
margin-bottom: 0px;
list-style: none;
font-family: 'Century Gothic';
}
.menu a {
transition: all linear 0.15s;
color: #FF283B;
}
.menu li:hover > a,
.menu .current-item > a {
color: #F5F5F5;
}
.menu .arrow {
font-size: 11px;
line-height: 0%;
}
/*----- Top Level -----*/
.menu > ul > li {
float: left;
display: inline-block;
position: relative;
font-size: 18px;
}
.menu > ul > li > a {
padding-top: 2px;
padding-right: 2px;
padding-left: 2px;
padding-bottom: 2px;
display: inline-block;
text-shadow: 0px 0px 0px rgba(0, 0, 0, 0.00);
}
.menu > ul > li:hover > a,
.menu > ul > .current-item > a {
background: F5F5F5;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index: 1;
opacity: 1;
}
.sub-menu {
width: 100%;
padding: 3px 0px;
position: absolute;
top: 100%;
left: 0px;
z-index: -1;
opacity: 0;
transition: opacity linear 0.15s;
box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.0);
background: 0;
}
.sub-menu li {
display: inline-block;
font-size: 16px;
}
.sub-menu li a {
padding-top: 10px;
padding-right: 20px;
padding-left: 20px;
padding-bottom: 5px;
display: inline-block;
}
.sub-menu li a:hover,
.sub-menu .current-item a {
background: #FF283B;
}
img {
border: thin solid #FF283B;
margin-left: 5%;
}
h3 {
margin-top: 3%;
font-size: 24px;
}
.wrapper {
display: inline-block;
margin: 0px auto;
}
<div class="wrapper">
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>
<div align="center">Home</a>
</div>
</li>
<li>
<div align="center">Projects <span class="arrow">▼</span>
<ul class="sub-menu">
<li>Image Adaptation
</li>
<li>Sonic Memory
</li>
<li>Documentary Video
</li>
</ul>
</div>
</li>
<li>
<div align="center">Resume
</div>
</li>
<li>
<div align="center">About
</div>
</li>
<li>
<div align="center">Contact
</div>
</li>
</ul>
</nav>
</div>
</div>
The only thing I can seem to do is just shift the bar left using margin-left.
Website: tylerbr.com
This is enough:
.content {
text-align: center;
}
You need to give your menu a width and change the display to "block"
Here is the style you need to change
.menu-wrap {
box-shadow: 0 0 0 rgba(255, 255, 255, 0) inset;
display: block;
margin: auto;
width: 880px;
}
Its a good idea to give a 100% width to the navbar. And the text-align center on the menu should do the trick.
.menu-wrap {
box-shadow: inset 0px 0 0 rgba(255,255,255,0.00);
-webkit-box-shadow: inset 0px 0 0 rgba(255,255,255,0.00);
display: inline-block;
margin: 0px auto;
width: 100%;
}
.menu {
width: 100%;
display: inline-block;
text-align: center;
}
What you are looking for is they style margin: 0 auto; take a look at this sample code and you will get it.
<style>
.wrapper{
width:100%;
height: 30px;
background: black;
}
.centered_div{
width: 200px;
background: red;
margin:0 auto;
}
</style>
<div class="wrapper">
<div class="centered_div">
test
</div>
</div>

CSS: margin-right: auto acting weird

HTML:
<ul id="menu">
<li>Categories 1
<ul id="cat1">
<li class="first">temp1</li>
<li>temp2</li>
<li>temp3</li>
</ul>
</li>
</ul>
CSS:
#menu {
background-color: #0000FF;
height: 20px;
padding: 15px 0 10px;
margin: 5px;
font: 12px Tahoma;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
box-shadow: inset 0px 0px 10px #000;
text-align: center;
}
#menu > li{
display: inline;
}
li a {
color: #fff;
text-decoration: none;
}
.first{
margin-top: 12px;
}
#cat1 > li{
display: block;
background-color: #0000FF;
width: 150px;
margin-right: auto;
}
#cat1 > li > a{
display: block;
padding: 10px;
box-shadow: inset 0px 0px 2px #000;
}
When i use margin-left: auto in #cat > li it is woring properly. margin-right:auto on the other hand doesn't get the full margin, and I don't understand why this is.
Here's my fiddle: http://jsfiddle.net/ZfN7t/25/
Thank you for any and all help!
Mayb you should set <li> inline-block , maybe text-align:center and reset margin/padding of <ul> second level too :)
http://jsfiddle.net/ZfN7t/26/
ul {
margin:0 auto;
padding:0;
}
#menu > li {
display: inline-block;
}
Remove the default padding for html elements and it should work like expected.
ul,li
{
margin:0;padding:0;
}
FIDDLE

Drop Down Menu not showing properly in IE

I have a navigation bar, which works perfect in Chrome & Mozilla, but does not work properly in IE.
When you hover the mopue on about us tab, the drop down should come, but its coming inline. and also the background position is not correct.
Pls Help
Code :
CSS :
#nav {
width : auto;
height : 25px;
margin : 10px auto;
padding : 5px;
}
#nav ul {
margin : 17px auto;
padding : 0px;
text-align: center;
}
#nav ul li {
display: inline-block;
list-style: none;
}
#nav ul li a {
text-decoration :none;
color: #175587;
font-size: 15px;
width : auto;
padding: 5px 1px 5px 1px;
height: 35px;
box-shadow: 3px 3px 8px gray;
background: url(../images/listback.png);
}
#nav ul li a:hover, #nav ul li a.current {
background: url(../images/hoverback.png);
color: white;
}
#nav li ul {
display: none;
position: absolute;
}
#nav li:hover ul {
display: block;
z-index: 10;
margin: 0px 0px 0px 0px;
background: url(../images/down2.png) no-repeat;
background-position: 13% 5%;
padding: 65px 0px 0px 0px;
}
#nav li ul li {
float: none;
display: block;
}
#nav li ul li a {
width: 155px;
height: auto;
margin: 0px 0px 0px 0px ;
padding: 5px 0px 5px 5px;
float: left;
background : rgba(29, 71, 113, 0.8);
font-size: 15px;
text-align: left;
text-decoration: none;
font-weight: bold;
color: white;
text-transform: uppercase;
outline: none;
box-shadow: none;
-webkit-box-shadow: none;
-moz-box-shadow: none;
display: block;
}
HTML :-
<div id="nav">
<ul>
<li>Home
</li>
<li>About Us
<ul>
<li>Group Profile
</li>
<li>Management Profile
</li>
<li>Milestones
</li>
<li>Vision & Missions
</li>
</ul>
</li>
<li>AGP
</li>
<li>Products
</li>
<li>Infrastructure
</li>
<li>Support
</li>
<li>Culture
</li>
<li>Certification
</li>
<li>Contact Us
</li>
</ul>
</div>
Please Help.
I added float:left and clear both to #nav li ul li (shown below)
#nav li ul li {
float:none;
display:block;
float:left;
clear:both;
}
Here's a demo working in IE -> http://jsfiddle.net/5kWJz/