Can't make float:left work on horizontal ul - html

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>

Related

How do I center my logo in the navigation bar?

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

Dropdown menu is hiding behind div

I am new to css my dropdown menu is hiding behind the div please help me to find out the problem. my HTML and CSS code is:
<style>
*
{
margin:0px;
padding:0px;
}
body
{
background-color:mintcream;
}
#header
{
height:260px;
width:auto;
margin:5px;
}
#headerimg
{
height: 260px;
width:100%;
}
#wrap #menu
{
width:550px;
margin:0 auto;
padding:10px;
}
#wrap
{
height:50px;
background-color:lightsalmon;
border:1px solid white;
border-radius:5px;
}
#wrap #menu ul li
{
background-color:black;
border-radius:5px;
width: 120px;
height: 30px;
line-height: 30px;
float: left;
text-align: center;
list-style-type:none;
margin-left: 3px;
}
#wrap #menu ul li a{
color:white;
text-decoration:none;
display:block;
}
#wrap #menu ul li a:hover
{
background-color:mistyrose;
color:orangered;
border-radius:5px;
}
#wrap #menu ul li ul li
{
display:none;
}
#wrap #menu ul li:hover ul li
{
display:block;
}
#content
{
width:100%;
height:500px;
background-color: teal;
margin:5px;
}
#content1
{
width:50%;
height:500px;
background-color: yellow;
float:left;
}
#content2
{
width:50%;
height:500px;
background-color:red;
float:left;
}
</style>
<body>
<div id="header">
<img id="headerimg" src="doc.jpg" />
</div>
<div id="wrap">
<div id="menu">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Contact Us</li>
<li>Services
<ul>
<li>Food</li>
<li>Hospital</li>
<li>Medical</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div id="content1"> </div>
<div id="content2"> </div>
</div>
</body>
I am new to css. My dropdown menu is hiding behind the div. Please help me to find the problem.
Please add below css
ul {position: relative; z-index: 99999; }
Just add position:relative in "#wrap #menu ul li" . I think your problem was solved. If you have any other problem then put it here.
Thanks for asking.

Vertically aligning images in floated elements

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>

Vertically align image in li tag without height

I'm trying to vertically align the shopping cart image and have it change on hover as well. I checked the other answers but they all seem involve changing the height.
JSFIDDLE http://jsfiddle.net/omarel/8agvv15s/
.navlogo, .navlogo_strip {
z-index:99;
}
.navlogo img {
width:120px;
margin:10px 10px 10px 10px;
}
.navlogo_strip img {
width:50px;
margin:10px 10px 10px 10px;
}
.floatleft {
float:none;
}
.floatright {
float:none;
}
.nav_container ul li {
display: inline-block;
text-align: center;
line-height:90px;
}
.nav_container ul li a {
padding:50px 30px 50px 30px;
margin:0px;
cursor:pointer;
}
.nav_container ul {
/* margin-top:15px; */
margin-left:30px;
margin-top:0px;
}
.nav_container {
text-align: center;
width:100%;
font-size:16px;
letter-spacing: -1px;
}
.nav_container ul li:hover {
/* not needed background-color:#08298A; */
}
.nav_container ul li:hover a {
color:#fff;
background-color:#08298A;
}
header {
width:100%;
margin: auto;
min-width:420px;
/* 0 0 8px rgba(0,0,0,0.1)*/
}
HTML
<div class="navlogo floatleft">
<img src="logo.png" />
</div>
<div class="desktopnav">
<div class="floatleft">
<div class="nav_container">
<ul>
<li>Browse</li><li>Sell</li>
</ul>
</div>
</div>
<div class="floatright">
<div class="nav_container">
<ul>
<li><img src="http://s10.postimg.org/s09rtjls5/cart.png?noCache=1430871415" /></li><!-- <li>Profile</li> --><li>Sign out</li>
</ul>
</div>
</div>
</div>
<div style="clear:both;"></div>
</header>
Use background-position property in CSS allows you to move background image in main element.
Source: Link
There is a good explanation and solution of this here: http://css.maxdesign.com.au/listutorial/master.htm
It says that using list-style-image results in inconsistent placement of the image with different browsers. Then it explains how to use background images for the bullets for a better result.
Source: CSS ul li image to align with text

Is it possible for an anchor link stay highlighted on single page website using pure css?

Is it possible to keep an anchor link highlighted on a single page using pure CSS?
I already saw a lot of tutorials about the link highlight when someone is in a designated page. But I never saw someone do what I asked... only with javascript. But I don't wanna use js because is a fancy noscript page that I want to do.
ul {
margin: auto;
word-wrap:break-word;
padding:0px;
position:fixed;
}
a {
width:30px;
}
a:link, a:visited {
text-decoration:none;
display:block;
background-color:gray;
color:#ffffff;
}
a:hover, a:active {
background-color:black;
}
.contentWrap {
top:0px;
width:300px;
bottom:0;
background-color:#FF9933;
position: absolute;
margin:auto;
left: 0;
right: 0;
}
.container {
height:1000px;
}
#one {
background-color:orange;
}
#two {
background-color:green;
}
<ul>
<li>One</li>
<li>Two</li>
</ul>
<!-Content/->
<div class='contentWrap'>
<div class='container' id='one'></div>
<div class='container' id='two'></div>
</div>
<!-Content/->
It is possible using only css with the :target pseudo-class and the general sibling selector. However, the links must come after the containers and the containers can not be in another element.
For the html, you need to remove the .contentWrap div and move the <ul> after the .container divs.
<div class='container' id='one'></div>
<div class='container' id='two'></div>
<ul>
<li><a href='#one'>One</a></li>
<li><a href='#two'>Two</a></li>
</ul>
For the css, you need to change the ul and .container rules. In the selector for the new rule, :target selects the container with the id that the fragment identifier links to. Then ~ selects the following ul with the descendant a with the corresponding href attribute.
ul {
margin: auto;
word-wrap:break-word;
padding:0px;
position:fixed;
top: 0;
left: 0;
}
.container {
height:1000px;
width:300px;
margin: auto;
}
#one:target ~ ul [href='#one'],
#two:target ~ ul [href='#two'] {
background: #ccc;
}
ul {
margin: auto;
word-wrap:break-word;
padding:0px;
position:fixed;
top: 0;
left: 0;
}
a {
width:30px;
}
a:link, a:visited {
text-decoration:none;
display:block;
background-color:gray;
color:#ffffff;
}
a:hover, a:active {
background-color:black;
}
.container {
height:1000px;
width:300px;
margin: auto;
}
#one {
background-color:orange;
}
#two {
background-color:green;
}
#one:target ~ ul [href='#one'],
#two:target ~ ul [href='#two'] {
background: #ccc;
}
<div class='container' id='one'></div>
<div class='container' id='two'></div>
<ul>
<li><a href='#one'>One</a></li>
<li><a href='#two'>Two</a></li>
</ul>