I'm trying to vertical align some images to the bottom in floated elements, and I can't seem to get it to cooperate.
Here is a JSFiddle with an example. You can see they are aligning to the top.
http://jsfiddle.net/decr9gfj/1/
Some Code:
<ul class="clearfix">
<li><img src="http://fpoimg.com/100x150"></li>
<li><img src="http://fpoimg.com/100x100"></li>
<li><img src="http://fpoimg.com/100x75"></li>
</ul>
ul {
list-style-type:none;
margin:0;
padding:0;
background:#eee;
display: block;
vertical-align:bottom;
}
li {
float:left;
padding:0px 5px;
}
a {
display:block;
}
img {
display:block;
vertical-align:bottom;
}
Remove the float on the list items and add display:inline-block.
li {
display:inline-block;
padding:0px 5px;
}
jsFiddle example
ul {
list-style-type:none;
margin:0;
padding:0;
background:#eee;
display: block;
vertical-align:bottom;
}
li {
display:inline-block;
padding:0px 5px;
}
a {
display:block;
}
img {
display:block;
vertical-align:bottom;
}
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content:" ";
clear: both;
height: 0;
}
.clearfix {
display: inline-block;
}
/* start commented backslash hack \*/
* html .clearfix {
height: 1%;
}
.clearfix {
display: block;
}
/* close commented backslash hack */
<ul class="clearfix">
<li><img src="http://fpoimg.com/100x150">
</li>
<li><img src="http://fpoimg.com/100x100">
</li>
<li><img src="http://fpoimg.com/100x75">
</li>
</ul>
Related
How do I center my logo in my Navigation bar? I kind of already have it centered, but the issue that I'm running into is when I place an image in the content area, the image covers up part of the logo. I do want the logo kind of dropped a little from the navigation links. I don't want a giant space between the logo and the content image. Is there a way I can achieve this? The image attached is the design I'm trying to accomplish. Thanks in advance!
body {
font-family:Georgia;
font-size:12pt;
}
* {
margin:0;
padding:0;
}
#header {
background-color:#000000;
height:100px;
margin:auto;
}
#header ul {
margin:0 auto;
width:35%;
padding:12px;
list-style: none;
}
#header li {
float: left;
}
#header a {
padding:0 14px;
text-align:center;
display:block;
text-decoration:none;
color:#FFFFFF;
font-size:18pt;
}
#header ul li a.logo {
background: url("Logo.png");
background-repeat:no-repeat;
height:140px;
display:block;
width:140px;
padding: 0;
.clearfix {
*zoom: 1;
}
.clearfix:after {
content: "";
clear: both;
display: table;
}
#MainContent {
}
#MainContent img {
margin-top:-10px;
position:absolute;
left:0;
width:100%;
}
}
<body>
<div id="header" class="clearfix">
<ul class="Nav">
<li>Home</li>
<li>Menu</li>
<li></li>
<li><a href="gallery.html" >Gallery</a></li>
<li>About</li>
</ul>
</div>
<div id="MainContent">
<img src="Photos/drinks.jpeg">
</div>
</body>
You can add a z-index to your .logo class. This will render it above the image.
e.g.
.logo {
z-index: 100;
}
https://developer.mozilla.org/de/docs/Web/CSS/z-index
I currently have a Header in my HTML which is a Unordered List with List Items display = inline. What I am try to accomplish is to spread each of the 5 items into an equaled space (20% Width for each) and step them centered in their respective spaces. I was able to accomplish this with a lot of ease on the Footer, but instead of List Items, I used Divs for each of the Options. Can anyone help me do the same with list? I can redo it as Divs, but I'd like to at least know how to make the list work.
How it should be
html, body {
margin:0;
padding:0;
height:100%;
}
a:link {
text-decoration:none;
}
#page {
position:relative;
background:#E9EAEE;
min-height:100%;
}
#header {
position:fixed;
left:0px;
top:0px;
z-index:1;
width:100%;
background-color:#3f5c99;
padding-top:10px;
}
#header .holder {
width:100%;
float:left;
}
#header a {
color:#ffffff;
font-size:11px;
font-weight: bold;
padding:0px 10px 0 0;
text-transform:uppercase;
}
#header li {
display:inline;
margin-left:-10px;
padding:0 4px 0 6px;
border-left: 1px solid #2F477A;
}
.logo {
border-radius:2px;
}
<body>
<div id="page">
<div id="header">
<div class="holder">
<ul>
<li style="border-left:0px;"><img class="logo" src="../img/logo.png"/></li>
<li>Comics</li>
<li><img src="../img/friendOff.png"/></li>
<li><img src="../img/mailChatOff.png"/></li>
<li><img src="../img/globeOff.png"/></li>
</ul>
</div>
</div>
...
</div>
</body>
I hope I was able to illustrate what I am trying to accomplish, but if it is still unclear please let me know. Thanks in advance for any help.
You can try like this ,I hope it will helps you.
html, body {
margin:0;
padding:0;
height:100%;
}
a:link {
text-decoration:none;
}
#page {
position:relative;
background:#E9EAEE;
min-height:100%;
}
#header {
position:fixed;
left:0px;
top:0px;
z-index:1;
width:100%;
background-color:#3f5c99;
}
#header .holder {
width:100%;
float:left;
}
#header ul {
display: table;
margin: 0;
padding: 0;
width: 100%;
}
#header a {
color: #ffffff;
display: inline-block;
font-size: 11px;
font-weight: bold;
text-transform: uppercase;
}
#header li {
display: table-cell;
padding: 5px 0;
position: relative;
text-align: center;
vertical-align: middle;
width: 20%;
}
#header li:after {
border-left: 1px solid #2f477a;
content: "";
height: 20px;
position: absolute;
right: 0;
top: 8px;
}
.logo {
border-radius:2px;
}
<body>
<div id="page">
<div id="header">
<div class="holder">
<ul>
<li style="border-left:0px;"><img class="logo" src="../img/logo.png"/></li>
<li>Comics</li>
<li><img src="../img/friendOff.png"/></li>
<li><img src="../img/mailChatOff.png"/></li>
<li><img src="../img/globeOff.png"/></li>
</ul>
</div>
</div>
...
</div>
</body>
ul {
display: flex;
}
#header li {
...
flex: 1;
display: flex;
align-items: center;
justify-content: center;
...
}
https://jsfiddle.net/234zzgn7/
Add this css. Ofcourse this is using flexbox which is something that I found to be extremely awesome. But you should investigate whether your users support it or not.
http://caniuse.com/#search=flexbox
Here try this. Changes are on #header li and #header a
html, body {
margin:0;
padding:0;
height:100%;
}
a:link {
text-decoration:none;
}
#page {
position:relative;
background:#E9EAEE;
min-height:100%;
}
#header {
position:fixed;
left:0px;
top:0px;
z-index:1;
width:100%;
background-color:#3f5c99;
padding-top:10px;
}
#header .holder {
width:100%;
float:left;
}
#header a {
color:#ffffff;
font-size:11px;
font-weight: bold;
padding:0px 10px 0 0;
text-transform:uppercase;
display:block;
width:100%;
box-sizing:border-box;
}
#header li {
display:inline-block;
box-sizing:border-box;
width:20%;
margin-left:-10px;
padding:0 4px 0 6px;
border-left: 1px solid #2F477A;
}
.logo {
border-radius:2px;
}
<body>
<div id="page">
<div id="header">
<div class="holder">
<ul>
<li style="border-left:0px;"><img class="logo" src="../img/logo.png"/></li>
<li>Comics</li>
<li><img src="../img/friendOff.png"/></li>
<li><img src="../img/mailChatOff.png"/></li>
<li><img src="../img/globeOff.png"/></li>
</ul>
</div>
</div>
...
</div>
</body>
I've just finished a CSS3 class and I want to use what I've learned on my website. I want a horizontal bar across the top of the page with two images and some text between them, centered in the page. The problem is that I can't seem to get the float:left to work on the <li> elements.
I'll be using the same technique to put a menu below this bar. This is just the beginning of this page and may not even be the best design, I'm just trying to use in the real world what I learned in class a step at a time.
I'm trying to stay away from using classes everywhere in the HTML code, that's a lot of trouble in maintenance and changing things.
See my website.
Here's the HTML:
<div>
<ul id="topBar" class="clearfix">
<li><img src="../../images/heinleinmedalgold-glow150.jpg" /></li>
<li id="logo">pixelmeow's pages</li>
<li><img src="../../images/heart_grenade.jpg" /></li>
</ul>
</div>
Here's the CSS:
#import url(reset.css);
.clearfix:before, .clearfix:after {
content:" ";
display:table;
}
.clearfix:after {
clear:both;
}
body {
width:100%;
}
#topBar {
width:100%;
height:10em;
background-color:black;
}
#topBar ul {
margin:0 auto;
}
#topBar ul li {
float:left;
list-style:none;
border:2px solid red;
height:5em;
display:inline-block;
}
#topBar ul li:first-child {
text-align:right;
}
#topBar ul li:nth-of-type(2) {
min-width:40%;
padding-top:5em;
text-align:center;
}
#topBar ul li:last-child {
text-align:left
}
#logo {
font-family:kells_uncialbold;
color:gray;
top: 50px;
}
Your selectors are incorrect. #topBar ul li should be #topBar li. What you have tries to select a <ul> that's a descendant of an element with the ID of topBar, when in reality it is the element with that ID. So you could use either #topBar li or ul#topBar li.
#import url(reset.css);
.clearfix:before, .clearfix:after {
content:" ";
display:table;
}
.clearfix:after {
clear:both;
}
body {
width:100%;
}
#topBar {
width:100%;
height:10em;
background-color:black;
}
#topBar {
margin:0 auto;
}
#topBar li {
float:left;
list-style:none;
border:2px solid red;
height:5em;
display:inline-block;
}
#topBar li:first-child {
text-align:right;
}
#topBar li:nth-of-type(2) {
min-width:40%;
padding-top:5em;
text-align:center;
}
#topBar li:last-child {
text-align:left
}
#logo {
font-family:kells_uncialbold;
color:gray;
top: 50px;
}
<div>
<ul id="topBar" class="clearfix">
<li><img src="http://pixelmeow.com/images/heinleinmedalgold-glow150.jpg" /></li>
<li id="logo">pixelmeow's pages</li>
<li><img src="http://pixelmeow.com/images/heart_grenade.jpg" /></li>
</ul>
</div>
It's probably worth mentioning that a list here is probably not the best choice for layout. Also, you might have trouble centering when using floats.
JSfiddle Demo
div#topbar {
text-align: center;
background-color: black;
color: white;
}
div#topbar img {
vertical-align: middle;
}
#logo {
display: inline-block;
vertical-align: middle;
}
<div id="topbar">
<img src="http://pixelmeow.com/images/heinleinmedalgold-glow150.jpg" />
<h1 id="logo">pixelmeow's pages</h1>
<img src="http://pixelmeow.com/images/heart_grenade.jpg" />
</div>
I having some problems with the hover effect on the full width of each of my drop down menu items. I want each items background color to change. At the moment, I can only get the width of the text hovered, not the width of the drop down.
http://jsfiddle.net/7AXZR/
Thanks!
The HTML:
<div id="nav">
<ul>
<li><img src="images/kranz3.png" alt="kranz"/>COMPETE</li>
<li><img src="images/thumb3.png" alt="thumb"/>SCORE</li>
<div id="logolist"><li><img src="images/logorz.png" width="175em" /></li></div>
<li><img src="images/shopnav.png" alt="bag"/>SHOP</li>
<ul id="more-dropdown"><li><img src="images/morenav2.png" alt="more"/>MORE<ul>
<div id="dropdown-links">
<li>Print your own art</li>
<li>How it works</li>
<li>About Causes</li>
<li>About our products</li>
<li>About us</li>
<li>Help & Feedback</li>
<li>Terms of Service</li>
<li>Privacy</li></ul>
</div>
</li>
</ul>
</div>
<div class="clear">
</div>
The CSS:
#nav {
position:relative;
background:#ffffff;
width:100%;
height:0.2em:
overflow:visible;
margin-top:-2em;
font-family:Cusmyrb;
font-size:75%;
}
#logolist {
position:absolute;
padding-top:2em;
width:150px;
left:50%;
margin-left:-90px;
margin-top:-7%;
}
#nav ul {
list-style-type:none;
}
#nav li {
display:inline;
float:left;
width:20%;
margin-left:2%;
margin-right:2%;
margin-top:3%;
text-align:center;
}
#nav a {
display:block;
margin-right:0% auto;
padding-left:0% auto;
color:#343234;
text-decoration:none;
}
#nav a:hover {
color:#5020B8;
}
#nav a:active {
color:#5020B8;
}
.clear {
clear:both;
}
#more-dropdown {
margin: 0;
padding: 0;
height:0;
}
#more-dropdown li {
list-style: none;
float: left;
}
#dropdown-links li a {
float:left;
display: block;
font-family:Cusmyr;
font-size:14px;
background-color:#797A7D;
color:#797A7D;
text-decoration: none;
margin-top:0.5em;
margin-left:1em;
}
#dropdown-links li a:hover {
float:left;
display: block;
font-family:Cusmyr;
font-size:14px;
background-color:#01A07E;
color:#797A7D;
text-decoration: none;
margin-top:0.5em;
margin-left:1em;
}
#more-dropdown li ul {
display: none;
width: 6em; /* Width to help Opera out */
background-color:#797A7D;
border:1px solid white;
}
#more-dropdown li:hover ul {
display: block;
position: absolute;
margin: 0;
padding: 0; }
#more-dropdown li:hover li {
float: none;
background-color:#01A07E;
}
#more-dropdown li:hover li a {
color: #ffffff;
}
#more-dropdown li li a:hover {
}
switch
#nav a:hover
to
#nav:hover a
edit:
first: your <a> elements in the <li> elements have atop and left margins so they do not fill up the entire list item
second: the #nav li selector applies also to the list item in the dropdown list and you don't want them to float. This is because then the surrounding list items have height 0
I removed the float except for the first list item:
new fiddle:
http://jsfiddle.net/PZGLz/
It doesn't appear in safari when I preview it, but it does in other browsers.
Here's the jsfiddle.
You can see the "portfolio" list items have about 2 pixels of white space under each one. Where is this coming from? I've got the padding and margins set to 0 and nowrap but can't figure out any other reason why.. any ideas?
* {
margin:0;
}
html, body {
height:100%;
}
body {
background-color:#fff;
}
#leftnav {
background-color:#232323;
width:20%;
min-height:100%;
height: auto !important;
float:left;
text-align:center;
padding:75px 0 0px 0px;
position:fixed;
left:0;
top:0;
}
#portfolio {
white-space: nowrap;
text-align:center;
margin:0;
width:80%;
float:right;
}
#portfolio ul {
margin:0;
padding:0;
}
#portfolio li {
width: 25%;
display: inline-block;
text-align: center;
vertical-align: middle;
margin:0;
padding:0;
float:left;
}
#portfolio img {
max-width:100%;
margin:0;
padding:0;
}
#maintop {
width:80%;
height:45%;
background-color:#caab7e;
float:right;
text-align:center;
}
<body>
<div id="leftnav"></div>
<div id="maintop"></div>
<div id="portfolio">
<ul>
<li><img src="http://dummyimage.com/400x300/000/fff"></li>
<li><img src="http://dummyimage.com/400x300/090/fff"></li>
<li><img src="http://dummyimage.com/400x300/900/fff"></li>
<li><img src="http://dummyimage.com/400x300/009/fff"></li>
<li><img src="http://dummyimage.com/400x300/000/fff"></li>
<li><img src="http://dummyimage.com/400x300/090/fff"></li>
<li><img src="http://dummyimage.com/400x300/900/fff"></li>
<li><img src="http://dummyimage.com/400x300/009/fff"></li>
<li><img src="http://dummyimage.com/400x300/000/fff"></li>
<li><img src="http://dummyimage.com/400x300/090/fff"></li>
<li><img src="http://dummyimage.com/400x300/900/fff"></li>
<li><img src="http://dummyimage.com/400x300/009/fff"></li>
</ul>
</div>
</body>
It is from the font size / line height. Either add:
#portfolio li {
font-size: 0;
}
or:
#portfolio li {
line-height: 0;
}
Resulting in this updated fiddle.
I also don't know where that white space is coming from, but you can set li{ height: 87px; } that will make the white space be gone.
Opera browser have not space too. I am checking it in firefox with firebug plugin and I can see height of img is 285px and height of li is 290px. Now when I add height 285px for li, space disappear.
#portfolio li {
width: 25%;
display: inline-block;
text-align: center;
vertical-align: middle;
margin:0;
padding:0;
float:left;
height: 285px;
}