How to center li when it's floated left - html

Hi this seems to be a common problem, however the solutions I've found haven't worked for me yet :(
I found this however this solution didn't work for me for some reason.
My demo link:
http://leongaban.com/_stack/centering/
I'm trying to get the top nav to center, as well as the Portfolio Nav to center as well.
My JSFiddle:
http://jsfiddle.net/8DM65/
Please help! Driving me nuts X_x
HTML
<header>
<div id="main-nav">
<ul>
<li>Portfolio</li>
<li>Contact Me</li>
<li>Resume</li>
</ul>
</div>
<div id="logo-title">
<img src="images/leon_gaban.png" width="256" height="256" class="avatar" />
<h1>Hello</h1>
<h2>Web Designer & Developer</h2>
<h3>And self-improvement blogger</h3>
</div>
</header>
<section id="content">
<div class="portfolio-nav">
<ul>
<li class="cta">Select Portfolio</li>
<li class="selected">Design & Development</li>
<li class="not-selected">Flash & Animation</li>
</ul>
</div>
<div id="showcase-div">
<ul id="showcase-boxes">
<li>Test</li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</section>
CSS
/* 02 Header */
header {
width: 100%;
height: 720px;
margin: 0 auto;
background: #ededed;
border-bottom: 1px solid #ccc;
}
header h1 {
font-size: 2em;
font-weight: 400;
font-style: italic;
}
header h2 {
font-size: 3.125em;
font-weight: 700;
}
header h3 {
font-size: 1.125em;
font-weight: 400;
font-style: italic;
}
#logo-title {
width: 100%;
margin: 60px auto;
text-align: center;
}
.avatar {
width: 256px;
height: 256px;
margin-bottom: 20px;
-webkit-border-radius: 128px;
-moz-border-radius: 128px;
-ms-border-radius: 128px;
-o-border-radius: 128px;
border-radius: 128px;
-webkit-box-shadow: 0 0 0px 6px white, 0 0 0 8px #cccccc, 0 10px 40px #333333;
-moz-box-shadow: 0 0 0px 6px white, 0 0 0 8px #cccccc, 0 10px 40px #333333;
box-shadow: 0 0 0px 6px white, 0 0 0 8px #cccccc, 0 10px 40px #333333;
}
#main-nav {
width: 80%;
height: 100px;
margin: 0 auto;
text-align: center;
font-size: 1.5em;
border-bottom: 2px solid white;
}
#main-nav ul {
clear: left;
float: left;
width: 100%;
list-style: none;
padding: 30px 0;
position:relative;
left:50%;
}
#main-nav ul li {
display:block;
position:relative;
right:50%;
float: left;
padding: 0 20px;
}
/* 03 Content */
#content {
width: 100%;
height: 100%;
margin: 0 auto;
}
#content ul {
list-style: none;
}
.portfolio-nav {
height: 60px;
padding: 30px 0 0 0;
background: #ccc;
}
.portfolio-nav ul {
margin: 0 auto;
text-align: center;
}
.portfolio-nav ul li {
display: inline;
float: left;
padding: 0 20px;
text-align: center;
}
#showcase-div {
width: 80%;
height: 100%;
margin: 0 auto;
background: blue;
padding-bottom: 60px;
}

You've actually added too much CSS to these elements and appear to be coding yourself in the wrong direction. I would scrap all the position: relative; stuff and instead focus on building your li's around inline-block. That makes the li's not expand width-wise push each other into a vertical stack.
#main-nav ul li {
display: inline-block;
padding: 0 20px;
}
#main-nav ul {
list-style: none;
padding: 30px 0;
}

Why have you gone with a big mixture of floats, clears, display and positioning? You need to remove a lot of code if you're going to make any sense of what you're doing.
For example, that first navigation. You don't need to display the list-items as block-level elements, and then float them, and then clear them, and then try and position them halfway across the page.
They are list-items, and you want to display them inline.
#main-nav ul {
width: 100%;
list-style: none;
padding: 30px 0;
}
#main-nav ul li {
display: inline;
padding: 0 20px;
}
http://jsfiddle.net/8DM65/2/

It appears I can get this to work very easily with the following:
.portfolio-nav{
text-align: center;
}
.portfolio-nav > ul{
display: inline-block;
}

What i found was that changing the #main-nav width css to 35% fixed it but removes the extra white separator line, so you could add an hr tag with a color of white to fix that. To fix the #portfolio-nav, I changed the width to 44% and added margin: 0 auto.

Related

How to remove blank white space below footer?

I tried to eliminate the white space according to the answered questions that I found. But not of them is working on my side.
I tried to remove the padding in div's footer, but still the white space still there.
How to fix this?
CSS:
footer #bottom-footer{ background: url(/files/bg-testimonials.jpg) no-repeat; background-repeat: no-repeat; background-size: cover; box-shadow: inset 0 0 0 1000px rgba(0, 0, 0, 0.52); color: #000; text-align: left; padding: 50px 0 50px 0; font-size: 0.8125em; font-family: 'Open Sans', sans-serif; font-weight: 600; letter-spacing: normal; position: relative; left: 0; bottom: 0; height: auto; width: 100%; }
.footer-wrap a{ color: #000; }
.footer-wrap a:hover{ color: #d31716; }
.footer-logo a{ margin-bottom: 6px; display: block; }
.footer-socials{ float: none; line-height: 0; text-align: center; padding: 1em 0 2em;}
.footer-socials a{ border-radius: 100%; border: 3px solid #FFF; color: #FFF; display: inline-block; font-size: 1.25em; line-height: 2.50em; margin-left: 0.1em; text-align: center; vertical-align: middle; width: 2.50em; height: 2.50em; }
.footer-socials .social-icons span{ cursor: pointer; display: inline-block; }
.footer-socials .socials i{ -webkit-backface-visibility: hidden; -moz-backface-visibility: hidden; backface-visibility: hidden; }
.tagcloud a{ font-size: 13px !important; background: rgba(0,0,0,0.4); padding: 8px 10px; margin: 0 2px 4px 0; display: inline-block; line-height: 1; }
.sidebar .tagcloud a{ background: #23A38F; color: #FFF; }
.bottom-menu{ float: right; margin: 1em 4em 0 0; }
.bottom-menu ul{ list-style-type: none; font-size: 1.1125em; }
.bottom-menu ul li{ display: inline-block; font-family: 'Open Sans', sans-serif; font-weight: normal; line-height: 1.8; border-radius: 5px; border: 1px solid #CCC; box-shadow: 0 0 2px rgba(0,0,0,0.3); padding: 1em; margin: 0 0.10em 0 0; background: #FFF; color: #3e3e3e; }
.footerimg{ width:6em; }
.copyright{ margin: 2em 0 0 4em; }
.copyrighttext{ font-size: 1.08em; font-weight: 600; color: #B3B3B3; margin: 0 0 0 0.50em; }
#imgv ul{ list-style-type: none; letter-spacing: 1px; margin-top: -20px; font-size: 0.75em; }
#imgv ul li{ display: inline; }
.social-footer-mobile{ display: none; }
.footer-vertical-line{ border-top: 1px solid #8c8b8b;width: 9em; vertical-align: middle; position: relative; }
.left{ left: 32.50em; top: 1.65em; }
.right{ right: 32.50em; top: -1.45em; float: right; }
HTML:
<div id="bottom-footer" class="footer-menu">
<div class="ak-container">
<div class="footer-wrap clearfix">
<div class="footer-socials clearfix">
<div class="footer-vertical-line left"></div>
<div class="socials">
<span class="font-icon-social-facebook"></span>
<span class="font-icon-social-twitter"></span>
<span class="font-icon-social-youtube"></span>
<span class="font-icon-social-linkedin"></span>
</div>
<div class="footer-vertical-line right"></div>
</div>
<div class="footer-columns-4">
<ul>
<li>Products</li>
<li>All products</li>
<li>Standard loan</li>
<li>Promo loans</li>
<li>Insurance for loans</li>
</ul>
<ul>
<li>About Loans</li>
<li>How to apply</li>
<li>Our partner stores</li>
<li>Terms & Conditions</li>
<li>Safety guarantee</li>
</ul>
<ul>
<li>For Customers</li>
<li>Financial literacy</li>
<li>Payments & Guidelines</li>
<li>Menu</li>
<li>FAQ</li>
</ul>
<ul>
<li>Title</li>
<li>About us</li>
<li>News</li>
<li>Careers</li>
<li>Contacts</li>
</ul>
</div>
<nav role="navigation">
<div class="bottom-menu">
<ul class="footer-desktop-version">
<li><span class="footer-icon-cs icon-icon-support"></span>Customer Service: <strong>11111111</strong></li>
<li><span class="footer-icon-cs icon-icon-collection"></span>Collections <strong>1111111</strong></li>
</ul>
</div>
</nav>
<div class="copyright">
<img src="/files/footer.jpg" class="footerimg"><span class="copyrighttext"> All Rights Reserved ® 2017
Company Name</span>
</div><!-- .copyright -->
</div><!-- .footer-wrap -->
</div>
</div>
Your code shows nothing, perhaps you can't reveal your web address no problem.
You need to check something in your html any div or content area have minus value like top:-100px if you set something like this you need to change like margin-top:-100px
first you have to right click on the footer and click inspect
then you will see all the css applied to that particular element, select the parent element
check if bottom padding is applied to body or footer element
if you dont find bottom padding for footer or body element or other parent class of footer specify bottom padding in negative. (eg -5px)
note: you dont need to modify the css directly for testing purpose you can change and check the effect in debugging tool itself (f12 shortcut for debugging tool)
it should be something like:
(element name) { padding-bottom:-30px); }
also check for bottom margin if padding does not work.

How to align vertically the top and main menus?

I have two menus: one is at the very top and another one right under it. I can't get the two menus to align properly to the right on top of each other. I want to align the last menu items of each of them vertically.
Here's the link: http://bit.ly/1KJjaOZ
CSS:
#header-text {
float: left;
border-radius: 25px;
border: 1px solid #CCC;
padding: 0 1em 2.35em 1em;
width: 15.30em;
height: 2em;
margin: 0 0 0 560px;
}
.top-menuv2 ul {
list-style-type: none;
margin: 10px 20px 0 90px;
font-size: 0.80em;
float: none;
}
.top-menuv2 li {
display: inline-block;
position: relative;
}
.top-menuv2 ul li {
display: inline;
margin-left: 20px;
font-family: 'Open Sans Bold', sans-serif;
line-height: 1.8;
}
You have to restructure your codes. Adding a huge margin to certain div is not a good solution. Since your top menu is right aligned, why don't you use float: right; instead?
Here is my solution. It's recommendable for you to make a backup because I technically redo your top menu html and css styles.
HTML:
<div class="top-navigation top-menuv2">
<ul>
<li>Contacts</li>
<li>Our Partners</li>
<li>Careers
<ul>
<li>Vacancies</li>
<li>Corporate Culture</li>
</ul>
</li>
</ul>
<div id="header-text">
<div class="header-text cc"> Customer Service 02 753 57 11</div>
</div>
</div>
And the style:
.top-menuv2 ul {
list-style-type: none;
margin: 15px 63px 0px 10px;
font-size: 0.8em;
float: right;
}
#header-text {
border-radius: 25px;
border: 1px solid #CCC;
padding: 0px 1em 2.35em;
width: 15.3em;
height: 2em;
float: right;
margin: 10px 0px 0px;
}
I won't use such a huge margin for my divs as it will ruin your design when it goes responsive. Hope it helps!
All you have to do is add this class :
.top-navigation.top-menuv2 ul {
text-align: right;
padding-right: 42px;
}
you can use this class..
.top-menuv2 {
display: inline-block;
margin: 10px 0 0 0;
}
.top-menuv2 ul {
list-style-type: none;
margin: 10px 20px 0 30px;
font-size: 0.80em;
float: none;
display: inline-block;
}
try to add margin left 14px to "search-icon" div. (return your menus to the previous positions before doing that)

How make 4 items fit perfectly inside the container

Codepen - http://codepen.io/anon/pen/ZGYQej
I need to make 4 items fit perfectly inside a container and each item must have 5px margin of the other. I'm trying to do but it is never perfect, what do I mean by perfect? The first item should be in the far left, and the last at the far right, and yet the four items need to be far apart with 5px .
Code:
HTML:
<section class="statistics">
<div class="container">
<h2 class="statistics__title">Estátisticas</h2>
<ul class="statistics__list">
<li class="statistics__item"></li>
<li class="statistics__item"></li>
<li class="statistics__item"></li>
<li class="statistics__item"></li>
</ul>
</div>
</section>
CSS:
.container {
box-sizing: content-box;
padding-left: 3%;
padding-right: 3%;
margin-left: auto;
margin-right: auto;
}
.statistics__title {
margin: 15px 15px 15px 0;
font-weight: lighter;
}
.statistics {
width: 100%;
}
.statistics__list {
margin: 0;
padding: 0;
list-style: none;
}
.statistics__item {
margin: 0 5px;
display: inline-block;
width: 23%;
height: 230px;
background-color: #FFF;
border-radius: 5px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24);
}
Try usin the pseudo-class :last-child on .statistics__item
This way you can give all elements margin-right:5px except for the last element, causing the first item to be in the far left, and the last at the far right while the four items are seperated with a margin of 5px.
box-sizing:content-box;
padding-left:3%;
padding-right:3%;
margin-left:auto;
margin-right:auto;
}
.statistics__title {
margin: 15px 15px 15px 0;
font-weight: lighter;
}
.statistics {
width: 100%;
}
.statistics__list {
margin: 0;
padding: 0;
list-style: none;
}
.statistics__item {
margin-right: 5px;
display: inline-block;
width: 23%;
height: 230px;
background-color: #FFF;
border-radius: 5px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24);
}
.statistics__item:last-child {
margin-right: 0px;
}
<section class="statistics">
<div class="container">
<h2 class="statistics__title">Estátisticas</h2>
<ul class="statistics__list">
<li class="statistics__item"></li>
<li class="statistics__item"></li>
<li class="statistics__item"></li>
<li class="statistics__item"></li>
</ul>
</div>
</section>
This possible solution involves CSS flexbox, check out the demo below.
.statistics__title {
background: silver;
}
.statistics__list {
list-style: none;
padding: 0;
margin: 0 -5px; /*get rid of the left margin on 1st item, and right margin on 4th item*/
display: flex;
}
.statistics__item {
background: gold;
flex-grow: 1;
margin: 0 5px;
}
<section class="statistics">
<div class="container">
<h2 class="statistics__title">Estátisticas</h2>
<ul class="statistics__list">
<li class="statistics__item">1</li>
<li class="statistics__item">2</li>
<li class="statistics__item">3</li>
<li class="statistics__item">4</li>
</ul>
</div>
</section>
JSFiddle: http://jsfiddle.net/b0t9m95L/

CSS and HTML navbar list with image

I am semi-new to web development and am currently working on a webpage with a fixed top navbar. I have my logo in the center of a list and my links outside it. I would like the links to be vertically centered. I will include a screenshot and the code. Maybe you can help me? Thanks a lot! I appreciate your time.
Screenshot of Navbar
HTML:
<div class="header">
<div class="table">
<div class="navbar">
<ul>
<li>Home</li>
<li>About</li>
<li>Before & After</li>
<li><img src="photos/logo.png"> </li>
<li>Portfolio</li>
<li>Facebook</li>
<li> <script src="js/email.js"></script>
</ul>
</div>
</div>
</div>
CSS:
#font-face {
font-family: offbeat;
src: url(offbeat.woff);
font-weight: normal;
font-style: normal;
}
body {
margin: 0 auto;
padding: 0;
background: rgb(209,202,178);
}
.header {
background: rgb(175,166,135);
width: 100%;
height: 100px;
margin: 0px;
padding: 0px;
position: fixed;
top: 0px;
z-index: 2;
border-bottom: 1px solid rgb(102,102,102);
}
.table {
display: table;
float: left;
left: 50%;
width: 1150px;
height: 100px;
line-height: 100px;
overflow: auto;
position: absolute;
}
.logo img {
z-index: 4;
position: relative;
left: 50%;
}
.navbar {
float: left;
right: 48.5%;
position: relative;
}
.navbar li {
display: inline;
padding: 0px;
margin: 0 auto;
width: 100%;
margin-right: 40px;
text-shadow: 1px 1px rgb(115,109,88);
font-family: offbeat;
font-size: 20px;
letter-spacing: 5px;
white-space: nowrap;
overflow: auto;
}
.navbar a {
text-decoration: none;
color: rgb(255,255,255);
text-align: center;
border-bottom: 1px solid;
border-color: rgb(255,255,255);
padding: 10px;
margin: 5px;
white-space: nowrap;
}
.navbar a:hover {
background-color: rgb(135,127,99);
}
I would look to use line-height to achieve this. Set the height on the parent container .navbar to 100px then set a line-height of 100px on the .navbar li.
This will mean the link text is always in the centre of the navbar. To ensure the logo was in the centre I would add vertical align middle.
As a bonus I would look to implement box-sizing it greatly helps with layouts that use padding.
#font-face {
font-family: offbeat;
src: url(offbeat.woff);
font-weight: normal;
font-style: normal;
}
*,
*:before,
*:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
margin: 0 auto;
padding: 0;
background: rgb(209, 202, 178);
}
.header {
background: rgb(175, 166, 135);
width: 100%;
height: 100px;
margin: 0px;
padding: 0px;
position: fixed;
top: 0px;
z-index: 2;
border-bottom: 1px solid rgb(102, 102, 102);
}
.navbar {
margin: 0;
padding: 0;
text-align: center;
}
.navbar ul {
margin: 0;
padding: 0;
overflow: hidden;
}
.navbar li {
display: inline-block;
padding: 0px;
margin-right: 40px;
text-shadow: 1px 1px rgb(115, 109, 88);
font-family: offbeat;
font-size: 20px;
letter-spacing: 5px;
line-height: 100px;
vertical-align: middle;
}
.navbar img {
vertical-align: middle;
}
.navbar a {
text-decoration: none;
color: rgb(255, 255, 255);
text-align: center;
border-bottom: 1px solid;
border-color: rgb(255, 255, 255);
padding: 10px;
margin: 5px;
white-space: nowrap;
}
.navbar a:hover {
background-color: rgb(135, 127, 99);
}
<div class="header">
<div class="navbar">
<ul>
<li>Home
</li>
<li>About
</li>
<li>Before & After
</li>
<li>
<img src="http://placehold.it/50x50">
</li>
<li>Portfolio
</li>
<li>Facebook
</li>
<li>
<script src="js/email.js"></script>
</ul>
</div>
</div>
I edit your base code as you used a lot of needed positioning techniques. Please compare with your code.
try adding this to your css
.navbar ul
{
display:inline;
vertical-align:middle;
}
Let the ul padding:20px 0px; direct the center vertically and text-align:center direct your center horizontally. Also use inline-block so that you can give your entire li focus for menu linking purposes
here is your problem solved FIDDLE
p.s. Your main problem is you are using way too much css. This is not supposed to be such a hard implementation and you definitely do not need absolute positioning, but fixed positioning. The rest is just colors.
If you need to give more padding to the top so they look closer to the bottom, use the padding property to distribute the padding as needed (i.e. padding: 40px 0px 5px) etc.
Here is a common saying we have...Use "absolute" only when "absolutely" necessary ;)
heres how i did it.
core change on css:
.navbar {
display:table;
margin: 15px auto;
}
.navbar li {
line-height:70px;
display: block;
padding: 0px;
float:left;
margin: 0 auto;
margin-right: 40px;
text-shadow: 1px 1px rgb(115,109,88);
font-family: offbeat;
font-size: 20px;
letter-spacing: 5px;
white-space: nowrap;
}
simplified html:
<div class="header">
<ul class="navbar">
<li>Home</li>
<li>About</li>
<li>Before & After</li>
<li><img src="http://img1.wikia.nocookie.net/__cb20120630091052/farmville2/images/0/0f/Google-Logo.png" height=70px /></li>
<li>Portfolio</li>
<li>Facebook</li>
</ul>
<script src="js/email.js"></script>
</div>
http://jsfiddle.net/4a8dkz3n/
i messed around a bit on jsfiddle so it might be a bit different,
but basically i gave display:table to so that i can give "margin:0 auto;" to it
and used 'line-height' to vertical alignment of the list menu.
also simplified the code a bit.

float left causes div to gain 'margin'

I have 5 divs in two wrapper divs and when I am assigning the float left attribute to the 5 dips they are gaining a 'top-margin' of 5, as in they have a space between the top of the wrapper div and them. Here is My HTML and CSS
HTML:
<div class="headerMenuWrapper">
<div class="menuOuterWrapper">
<div class="menuInnerWrapper" id="menuWrapper">
<div class="menuItem">Home</div>
<div class="menuItem">About Us</div>
<div class="menuItem">Products</div>
<div class="menuItem">FAQ</div>
<div class="menuItem">Contact Us</div>
</div>
</div>
</div>
CSS:
.menuOuterWrapper{
margin: auto;
margin-top: 0;
width: 95%;
height: 100%;
}
.menuInnerWrapper {
margin: auto;
margin-top: 0;
width: 90%;
height: 100%;
background-color: #327CF1;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
box-shadow: 1px 1px 5px #000000;
}
.menuItem {
height: 100%;
text-align: center;
border-right: 1px solid #051625;
float: left;
}
.headerMenuWrapper {
margin: auto;
width: 95%;
height: 50%;
}
Is this what you are looking for?
You have a lot going on in your markup that shouldn't be.
I simplified everything for you by using:
nav
ul
li
Instead of floats and margins, I used:
display: table
display: table-cell
text-align: center
HTML
<nav id="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Products</li>
<li>FAQ</li>
<li>Contact Us</li>
</ul>
</nav>
CSS
* {
margin: 0;
padding: 0;
border: none;
}
#menu {
margin: 0 auto;
text-align: center;
}
#menu > ul {
display: table;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
box-shadow: 1px 1px 5px #000000;
background: #327CF1;
width: 100%;
}
#menu ul > li {
display: table-cell;
text-align: center;
border-right: 1px solid white;
color: white;
}
#menu > ul > li:last-child {
border: none;
}
use Resetting Browser-Style Defaults for Elements
shorthand for you
{
margin: 0px;
padding: 0px;
}
margin: auto tells to browser automatically calculate margin
example of reset styles here http://meyerweb.com/eric/thoughts/2007/04/12/reset-styles/