Div doesn't contain nested elements - html

I have been having trouble with one of my divs for some reason, even though the nav tags are nested within it when I inspect element with firefox or in chrome the div seems to be completely on its own.
<div class="nav">
<nav class="social">
<ul>
<li><img class="icon" src="assets/facebook.png" alt=""></li>
<li><img class="icon" src="assets/google.png" alt=""></li>
<li><img class="icon" src="assets/linkedin.png" alt=""></li>
<li><img class="icon" src="assets/twitter.png" alt=""></li>
<li><img class="icon" src="assets/wordpress.png" alt=""></li>
</ul>
</nav>
<!-- #include _nav -->
</div>
Maybe this is something to do with the css styling for it so here is the css too. I have a feeling it might be something to do with hammer for mac but it seems to work in other respects.
.head {
padding-top: 25px;
overflow: hidden;
padding-bottom: 10px;
// background-color: yellow;
}
h1 {
margin: auto;
text-align: center;
color:white;
font-family: sans-serif;
font-size: 35px;
text-shadow: 0 1px 0 #ccc,
0 2px 0 #c9c9c9,
0 3px 0 #bbb,
0 4px 0 #b9b9b9,
0 5px 0 #aaa,
0 6px 1px rgba(0,0,0,.1),
0 0 5px rgba(0,0,0,.1),
0 1px 3px rgba(0,0,0,.3),
0 3px 5px rgba(0,0,0,.2),
0 5px 10px rgba(0,0,0,.25),
0 10px 10px rgba(0,0,0,.2),
0 20px 20px rgba(0,0,0,.15);
padding-bottom: 10px
}
.banner {
height: 200px;
background-color: red;
float: left;
margin: 0px;
}
.callout {
height: 200px;
background-color: green;
float: right;
margin-left: 5px;
margin-right: 0px;
}
.nav {
padding-bottom: 10px;
}
.headnav {
padding-top: 10px;
float: left;
overflow: hidden;
}
nav li {
display: inline;
padding-right: 15px;
}
nav li:last-child {
padding-right: 0px;
}
nav li a {
text-decoration: none;
color: white;
clear: both;
font-size: 20px;
padding-bottom: 4px;
}
nav li a:hover {
color: gray;
}
.icon {
width: 45px;
height: auto;
}
.social {
float: right;
overflow: hidden;
}
.social li {
display: inline;
}
Thanks in advance.

As both your nav elements (social/headnav) contained within the div element (confusingly named "nav") are floated to the right and the left these are removed from the normal document flow (see Mozilla Developer Network for more), and thus the div won't appear to "wrap around" or contain the elements when inspected in developer tools.
These elements are however still children of the div on the Document Object Model (DOM).
Normally an element that only contains floated children would have a height of 1px but in this case it is 10px due to the padding you have applied. This behaviour can cause a problem in terms of defining layout, for example margin below the parent, or styling like background pattern, colour or borders.
It is however entirely normal behaviour and not something you have done wrong.
There are several solutions to clearing floats so that the parent element area is affected by the floated children.
Adding another element after the floated elements with style="clear: both";
<br style="clear: both;" />
Adding the style overflow: hidden to the parent container.
Using one of the clearfix methods listed on CSS tricks

Related

why is my css for span hover not working?

When you move the mouse over image thumbnails, i.e. all images in ul .thumbs, you should see a small box which shows the text in the span embedded in the image link. This does not happen. Why and how do I fix it ?
http://jsfiddle.net/raj4dev/hbyg43d9/3/
html
<body>
<div id="container">
<h1>css slide show</h1>
<ul class="thumbs">
<li><img src="img/thumb1.jpg"><span>Img 1</span></li>
<li><img src="img/thumb2.jpg"><span>Img 2</span></li>
<li><img src="img/thumb3.jpg"><span>Img 3</span></li>
</ul>
<ul class="slides">
<li class="first" id="slide-1"><img src="img/slide1.jpg"></li>
<li id="slide-2"><img src="img/slide2.jpg"></li>
<li id="slide-3"><img src="img/slide3.jpg"></li>
</ul>
</div>
</body>
css
*{
margin: 0;
padding: 0;
border: none;
outline: none;
list-style: none;
}
body{
background: #465c8f url(../img/bg-image.jpg) repeat-x;
font-family: 'Arial', 'sans-serif';
}
#container{
width: 718px;
overflow: hidden;
margin: 40px auto;
}
h1{
color: #fff;
text-align: center;
margin-bottom: 20px;
}
ul.thumbs li{
float: left;
margin-bottom: 10px;
margin-right: 9px;
}
ul.thumbs a{
display: block;
position: relative;
width: 85px;
height: 55px;
border: 4px solid transparent;
font: bold 12px/25px Arial, sans-serif;
color: #515151;
text-decoration: none;/*remove underlines*/
text-shadow: 1px 1px 0px rgba(255,255,255,0.25), inset 1px 1px 0px rgba(0,0,0,0.15);
}
ul.thumbs img{
border: #333 solid 4px;
}
ul.slide{
overflow: hidden;
clear: both;
border: #333 solid 4px;
}
ul.slides, ul.slides li, ul.slides a, ul.slides img{
width: 705;
height: 350px;
position: relative;
}
ul.thumbs li a:hover span{
position: absolute;
z-index: 101;
bottom: -30px;
left: -22px;
display: block;
width: 100px;
height: 25px;
text-align: center;
border-radius: 3px;
}
This is a clever approach to creating a slide show that does not require JavaScript or jQuery, rather nicely done.
There was a typo in one of your class names in the CSS and that was creating some confusion (change ul.slide to ul.slides).
I guessed that what you wanted to do was display the span on hover, which means that to begin with, the span need to be hidden using display: none, and I added a new CSS rule for ul.thumbs li a span to correspond with ul.thumbs li a:hover span. (Note, you could also use :hover on li instead and get a similar effect.)
I also altered how the floated elements are styled. If you add overflow: auto to ul.thumbs, all the floats are contained within the parent block and you can then add the bottom margin to the parent ul instead of the li, which is more advantageous in some designs, your can decide.
For the thumbnail images, see ul.thumbs img, I set the height to 100% and let the thumbnails scale to fit the inherited height (from li) and use vertical-align: top if you want to remove the whitespace below the images.
I also set the with on the li instead of the a, but the distinction really depends on the details of our design.
For the most part, your CSS is good as is. The only missing concept was the initial hiding of the span so that it can appear on hover.
Note: I did not pay much attention to the width of the span and its exact positioning. If you have a lot of text (like a caption), the width of 100% will not be enough (I set it that way to make it fit in the li container). You can change it as you see fit.
*{
margin: 0;
padding: 0;
border: none;
outline: none;
list-style: none;
}
body {
background: #465c8f url(../img/bg-image.jpg) repeat-x;
font-family: 'Arial', 'sans-serif';
}
#container{
width: 718px;
overflow: hidden;
margin: 40px auto;
}
h1{
color: #fff;
text-align: center;
margin-bottom: 20px;
}
ul.thumbs {
border: 1px dotted white; /* for demo only... */
overflow: auto;
margin-bottom: 10px;
}
ul.thumbs li{
float: left;
width: 85px;
height: auto;
margin-right: 9px;
border: 1px dotted white; /* for demo only... */
}
ul.thumbs a {
display: block;
position: relative;
border: 4px solid transparent;
font: bold 12px/25px Arial, sans-serif;
color: #515151;
text-decoration: none;/*remove underlines*/
text-shadow: 1px 1px 0px rgba(255,255,255,0.25), inset 1px 1px 0px rgba(0,0,0,0.15);
}
ul.thumbs img{
vertical-align: top; /* if you need to remove whitespace below image */
height: 100%;
border: #333 solid 4px;
}
ul.slides { /* fix typo in class name */
overflow: hidden;
clear: both;
border: #333 solid 4px;
}
ul.slides, ul.slides li, ul.slides a, ul.slides img{
width: 705;
height: 350px;
position: relative;
}
ul.thumbs li a span { /* Need to provide a default styling for the span... */
position: absolute;
bottom: 0px;
left: 0px;
display: block;
width: 100%;
height: auto;
text-align: center;
border-radius: 3px;
background-color: white;
display: none;
}
ul.thumbs li a:hover span {
display: block;
}
<div id="container">
<h1>css slide show</h1>
<ul class="thumbs">
<li><img src="http://placehold.it/60x60"><span>Img 1</span></li>
<li><img src="http://placehold.it/60x60"><span>Img 2</span></li>
<li><img src="http://placehold.it/60x60"><span>Img 3</span></li>
</ul>
<ul class="slides">
<li class="first" id="slide-1"><img src="http://placehold.it/240x120"></li>
<li id="slide-2"><img src="http://placehold.it/180x120"></li>
<li id="slide-3"><img src="http://placehold.it/120x120"></li>
</ul>
</div>
Your hover styles work fine, but you have ul.slides on top of ul.thumbs, so the :hover action isn't being passed to your anchor.
In the future, please share the relevant pieces of code in your question on StackOverflow for posterity and searchability.
Just add z-index: 2; to your ul.thumbs a css like coryward said your link is underneath something so you can't hover over it you need to bring it to the top so you can hover on it.

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 to center li when it's floated left

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.

Vertical Align Unordered List Nav Links?

I see that this question has been asked many times but I think my case is slightly different.
The navigation for the site I am working on is constructed with an unordered list like so:
<div class="nav_root nav_area_top">
<ul class="nav_root_wrap">
<li class="nav_parent first">
<a href="california.providence.org/torrance/pages/Locations.aspx">
Locations
</a>
</li>
<li class="nav_parent first">
<a href="california.providence.org/torrance/pages/Locations.aspx">
Health Services
</a>
</li>
</ul>
</div>
...
.nav_area_top ul.nav_root_wrap > li
{
background-image: url(../images/vert_bg_blue.jpg);
background-color: #0C83BB;
padding: 4px 15px 4px 15px;
float: left;
font-size: 13px;
margin-left: 3px;
-moz-border-radius: 5px 5px 0 0;
-webkit-border-radius: 5px 5px 0 0;
border-radius: 5px 5px 0 0;
min-height: 36px;
text-align: center;
border: 0px;
}
.nav_area_top ul.nav_root_wrap > li > a
{
color:#fff;
padding: 0px;
line-height: 18px;
}
Which renders to:
As you can see some of the nav items are one line and some are two.
Is it possible for me to vertical-align: middle the one line items?
add this style (override if necessary)
.nav_area_top ul.nav_root_wrap > li {
line-height: 36px;
}
.nav_area_top ul.nav_root_wrap > li > a {
line-height: normal; /* or just choose another value: e.g. 1.5; */
vertical-align: middle;
display: inline-block;
*zoom: 1;
*display: inline;
}
last two properties are inline hacks necessary for IE<8 to properly render inline-blocks element
It's hard without a fixed height for your <li>. If you do have a fixed height you could:
<style>
#centerMe{
line-height:4em
}
</style>
<p id="centerMe">
This line is vertically centered!
</p>
You'd set the line height to your liking.
I also saw this from Nerds to Geeks:
#container li{
display: table-cell;
vertical-align: middle;
text-align: center;
font-size:28px;
}
I Changed the p element to li; it should still work.

help in Vertical CSS Menu

What I'm trying to do to design a vertical CSS menu like this one . on the right of this site
. I've two problems .
How can I add an image in the menu item .
How can I MAKE the BORDER RADIUS of all the item on the top and on the bottom NOT for each one .
That's my code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS3 Buttons</title>
<style>
.button {
width: 400px;
height: 100px;
line-height: 100px;
color: #C0C0C0;
text-decoration: none;
font-size: 50px;
font-family: helvetica, arial;
font-weight: bold;
display: block;
text-align: center;
position: relative;
padding-bottom:1px;
/* BACKGROUND GRADIENTS */
background: #F5F3F4;
/* BORDER RADIUS */
/* -moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px; */
/* TEXT SHADOW */
text-shadow: 1px 1px 1px black;
/* BOX SHADOW */
-moz-box-shadow: 0 1px 3px black;
-webkit-box-shadow: 0 1px 3px black;
box-shadow: 0 1px 3px black;
}
/* WHILE HOVERED */
.button:hover {
color: #A8A8A8;
-moz-box-shadow: 0 2px 6px black;
-webkit-box-shadow: 0 2px 6px black;
}
/* WHILE BEING CLICKED */
.button:active {
-moz-box-shadow: 0 2px 6px black;
-webkit-box-shadow: 0 2px 6px black;
}
</style>
</head>
<body>
Profile
Privacy
Services
Avatar
Language
</body>
</html>
First, you should adjust your html to include a list as follows (notice I also added id attributes):
<ul>
<li> Profile </li>
<li> Privacy </li>
<li> Services </li>
<li> Avatar </li>
<li> Language </li>
</ul>
Then, to add the image use the following css:
a#profile-btn {
background-image:url(/image_path/profile.png);
}
a#privacy-btn {
background-image:url(/image_path/privacy.png);
}
a#services-btn {
background-image:url(/image_path/services.png);
}
a#avatar-btn {
background-image:url(/image_path/avatar.png);
}
a#language-btn {
background-image:url(/image_path/language.png);
}
And finally the rounded borders:
ul {list-style:none;}
ul li:first-child a {
-moz-border-radius-topleft: 25px;
-moz-border-radius-topright: 25px;
-webkit-border-radius-topleft:25px;
-webkit-border-radius-topright:25px;
border-top-right-radius:25px;
border-top-left-radius:25px;
}
ul li:last-child a {
-moz-border-radius-bottomleft: 25px;
-moz-border-radius-bottomright: 25px;
-webkit-border-radius-bottomleft:25px;
-webkit-border-radius-bottomright:25px;
border-bottom-right-radius:25px;
border-bottom-left-radius:25px;
}
EDIT: This code is intended to work with all your other provided css, as long as you replace the HTML as shown.
Using pseudo classes like so:
(If your nav is a list and the button class is on the list element)
li.button:first-child {
-moz-border-radius: 4em 4em 0 0;
border-radius: 4em 4em 0 0;
}
li.button:last-child {
-moz-border-radius: 0 0 4em 4em;
border-radius: 0 0 4em 4em;
}
Use lists for that:
<ul id="main-menu">
<li>Link 1</li>
<li>Link 2</li>
<li>Link 3</li>
</ul>
And the CSS:
ul li {
float: left;
display: inline;
text-decoration: none;
font-size: 20px;
font-family: helvetica, arial;
font-weight: bold;
display: block;
text-align: center;
position: relative;
margin: 0 0 0 30px;
background: #F5F3F4;
-moz-border-radius: 10px 10px 0 0; /* 10 top left, 10 top right. 0 for the rest */
-webkit-border-top-radius: 10px; /* This will select only the top part */
border-radius: 10px 10px 0 0;
text-shadow: 1px 1px 1px black;
-moz-box-shadow: 0 1px 3px black;
-webkit-box-shadow: 0 1px 3px black;
box-shadow: 0 1px 3px black;
padding: 15px 30px;
}
ul li a { color: #C0C0C0; text-decoration: none; }
Hope you get the point. You can have a preview here: http://www.jsfiddle.net/UtNA8/
You could use a containing element for the links, ideally one that can apply a semantic relationship to its contents, I've used a ul (since it's basically a non-ordered list) and style that, rather than trying to style specific instances of an otherwise non-grouped set of elements:
html
<ul>
<li> Profile </li>
<li> Privacy </li>
<li> Services </li>
<li> Avatar </li>
<li> Language </li>
</ul>
css
ul {
width: 12em;
border-radius: 1em;
overflow: hidden;
}
ul li {
padding: 0.5em;
background-color: #eee;
}
JS Fiddle demo.
If you're targeting browsers with reliable implementations of last-child you could also use the :first-child and :last-child pseudo elements:
css:
ul li {
width: 12em;
padding: 0.5em;
background-color: #eee;
}
ul li:first-child {
-webkit-border-top-radius: 1em;
-moz-border-radius: 1em 1em 0 0;
border-radius: 1em 1em 0 0;
}
ul li:last-child {
-webkit-border-bottom-radius: 1em;
-moz-border-radius: 0 0 1em 1em;
border-radius: 0 0 1em 1em;
}
JS Fiddle demo
I'd be wary of first-child, last-child pseudo selectors. Obviously they are great ideas, and you should use them because they're a part of the standard, but at the same time you'll need to make some allowances for browsers that don't properly adhere to standards - ahem MS. Same goes for the border-radius properties obviously. Oh and finally, you might want to include your icon graphics as tags inside of your links (that is, if you want them to show up on any browser that doesn't support css properly, and you feel their content is of particular note).