Navigation with algin:center - html-lists

i have here a little example side to learn HTML.
This is the HTML part:
<!-- header open -->
<header role="banner">
<h1>Beispielaufgaben zu HTML5<br>und CSS3</h1>
<nav class="clearfix">
<ul>
<li>HOME</li>
<li>HTML</li>
<li>CSS</li>
</ul>
</nav>
</header>
<!-- header close -->
This is the CSS part:
html {
margin:0;
pading:0;
}
.wrapper {
width:90%;
max-width:1500px;
margin-top:2%;
margin-left:auto;
margin-right:auto;
}
header h1 {
font-size:350%;
text-align:center;
background-color:#999;
}
nav ul li {
background-color:#CCC;
display:block;
float:left;
width:20%;
font-size:200%;
text-align:center;
}
}
I want that the navigation is centered like h1, but i didnt will work with a bunch of testet ways...
anyone knows a solution?

I made a few changes to the CSS and it should do what you want now:
html {
margin:0;
pading:0;
}
.wrapper {
width:90%;
max-width:1500px;
margin-top:2%;
margin-left:auto;
margin-right:auto;
}
header h1 {
font-size:350%;
text-align:center;
background-color:#999;
}
nav ul li {
background-color:#CCC;
display:block; /*Changed to display: inline-block to replace float*/
float:left; /*Removed because would interfere with added text-align on nav*/
width:20%;
font-size:200%;
text-align:center; /*Removed because not needed*/
}
} /*Removed random closing curly bracket*/
nav {
text-align: center; /*Added to align all <li> in center*/
}
Fiddle: http://jsfiddle.net/U6Khy/1/

Related

Why is the hover effect targeting child being overridden when I apply a 'transform scale' to the parent element?

Below is a drop-down list nested in a drop-down list. the first code snippet works just fine; as I hover over the parent of the first drop-down list it's height transitions and it displays as I intended, as with the subsequent nested drop-down list.
The problem is with the second snippet...
* {
margin: 0;
padding: 0;
}
body {
background-color: hsla(33,25%,75%,1);
box-sizing: border-box;
}
.flex-container {
width: 100%;
}
.flex-container a {
background: lightskyblue;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
height: 25px;
padding: 10px;
text-decoration: none;
transition: background-color 500ms, height 500ms, color 500ms;
}
.flex-container a:hover {
background: cornflowerblue;
color: snow;
}
.flex-container li:hover {
box-shadow: 10px 10px 10px black;
}
.flex-container ul {
list-style: none;
display: flex;
}
.flex-container > ul > li {
width: 100%;
position: relative;
}
ul li ul {
flex-direction: column;
position: absolute;
width: 100%;
left: 50%;
}
ul li li {
width: 100%;
top: 0;
height: 0;
overflow: hidden;
transition-duration: 500ms;
}
li:hover > ul > li {
height: 45px;
}
/*
ul li li:hover {
transform: scale(1.1);
}
*/
<!DOCTYPE html>
<html lang="eng">
<head>
<title>Page 2</title>
<meta charser="utf-8">
<link rel="stylesheet" href="styles/styles2.css">
</head>
<body>
<div class="flex-container">
<ul>
<li>
Home
<ul>
<li>
Two
</li>
<li>
Two
</li>
<li>
Two
<ul>
<li>
two
</li>
<li>
two
</li>
</ul>
</li>
</ul>
</li>
<li>
Home
</li>
<li>
Home
</li>
<li>
Home
</li>
</ul>
</div>
</body>
</html>
Here I make one change at the very bottom of the CSS as I wanted the hover effect to be just a bit more pronounced. I apply a transform scale effect to the dropdown list's li's.
The first drop-down list works just fine, but then the second drop-down list does not.
Can someone please explain what is happening?
* {
margin: 0;
padding: 0;
}
body {
background-color: hsla(33,25%,75%,1);
box-sizing: border-box;
}
.flex-container {
width: 100%;
}
.flex-container a {
background: lightskyblue;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
height: 25px;
padding: 10px;
text-decoration: none;
transition: background-color 500ms, height 500ms, color 500ms;
}
.flex-container a:hover {
background: cornflowerblue;
color: snow;
}
.flex-container li:hover {
box-shadow: 10px 10px 10px black;
}
.flex-container ul {
list-style: none;
display: flex;
}
.flex-container > ul > li {
width: 100%;
position: relative;
}
ul li ul {
flex-direction: column;
position: absolute;
width: 100%;
left: 50%;
}
ul li li {
width: 100%;
top: 0;
height: 0;
overflow: hidden;
transition-duration: 500ms;
}
li:hover > ul > li {
height: 45px;
}
ul li li:hover {
transform: scale(1.1);
}
<!DOCTYPE html>
<html lang="eng">
<head>
<title>Page 2</title>
<meta charser="utf-8">
<link rel="stylesheet" href="styles/styles2.css">
</head>
<body>
<div class="flex-container">
<ul>
<li>
Home
<ul>
<li>
Two
</li>
<li>
Two
</li>
<li>
Two
<ul>
<li>
two
</li>
<li>
two
</li>
</ul>
</li>
</ul>
</li>
<li>
Home
</li>
<li>
Home
</li>
<li>
Home
</li>
</ul>
</div>
</body>
</html>
Fixed.
I don't understand why the problem occurred in the first place, nor do i understand why the fix I found works but it does.
I simply made the overflow property 'visible' in the (ul li li:hover ) and it works.

Padding messes up flexbox alignment

I am trying to have two items as links in the top right corner of the page.
I posted my code on codepen for a visual example. Whenever I add padding for the visit button the about goes up on the page.
CSS:
.navigation {
display: flex;
justify-content: space-between;
align-content: center;
&-list {
display: flex;
align-self: center;
list-style: none;
font-size: 2rem;
}
&-item {
&-visit {
background-color: $color-tertiary;
padding: 2rem;
}
}
}
Html:
<div class="container">
<navigation class="navigation">
<h1 class="porto">Porto</h1>
<ul class="navigation-list">
<li class="navigation-item">About</li>
<li class="navigation-item navigation-item-visit">Visit</li>
</ul>
</navigation>
</div>
Try removing the height in &-item and padding-bottom in &-visit.

Center a horizontal menu with an image in the middle

I am trying to center my menu bar with my logo in the middle. right now everything is floating but it wont center to the middle of the page. Also when it is centered i need the background image that i placed on the left and right side of the logo to resize according to the width of the page - here is a link to how it looks live - Menu Test
on my website i still have the original menu I created where I placed the logo behind the menu bar and set a longer width so that the background would stretch but it won't auto adjust because of it.... Current Menu
I know my code is not perfect so please just bear with me
html
<div id="access">
<div class="menu-container">
<ul id="menu-left" class="menu">
<li class="menu-item">
Home
</li>
<li class="menu-item">
About
</li>
<li class="menu-item">
Services
</li>
</ul><!--END of menu-navigation-left-->
<ul id="menu-center">
<li class="menu-item">
<img src="images/logo.png" alt="Menu">
</li>
</ul> <!--close div center-->
<ul id="menu-right" class="menu">
<li class="menu-item">
Blog
</li>
<li class="menu-item">
Contact
</li>
<li class="menu-item">
Portfolio
</li>
</ul><!--END of menu-navigation-left-->
</div><!--END of menu-navigation-container-->
</div><!--END of access-->
css
header {
position:fixed;
}
#access {
width:100%;
overflow:hidden;
left:50%;
}
#access ul.menu{
display: inline-block;
}
#access ul {
}
#access ul a{
display:block;
}
#access ul#menu-left {
height:120px;
background-image:url(../images/menu.png);
}
#access ul#menu-center {
height:120px;
}
#access ul#menu-right {
height:120px;
background-image:url(../images/menu.png);
}
ul, li {
margin:0px;
padding:0px;
list-style:none;
float:left;
display:block;
}
#access a {
display: block;
font-size: 16px;
line-height: 15px;
padding: 13px 10px 12px 10px;
text-transform: titlecase;
text-decoration: none;
font:"Mc1regular", Arial, sans-serif;
}
a:link{
color:#fff;
}
a:visited{
color:#fff;
}
This should sort out your alignment issues.. just replace with your specs. I would just have one menu and centre it.
PLEASE NOTE, YOUR HEADER POSITION IS FIXED> position:relative would be better..
div.container {
width: 1160px;
margin: auto;
margin-top: -1;
margin-bottom: -1;
padding: 0;
padding-top: 10px;
background-color: #2d2d2d;
}
div.box {
margin: auto;
margin-top: 20px;
margin-bottom: 20px;
padding: 10px;
padding-bottom: 20px;
border: solid 1px #A29060;
background-color: #000;
overflow: hidden;
width: 940px;
}
div.top {
text-align: left;
margin: auto;
margin-left: 20px;
padding-top: 12px;
padding-bottom: 11px;
font-weight: normal;
font-size: 14px;
overflow: hidden;
width: 980px;
text-transform: uppercase;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
float: left;
padding-right: 20px;
}
a {
display: block;
color: #a29060;
text-decoration: none;
}
<div class="container">
<div class="box">
<div class="top">
<ul >
<li>Contact</li>
<li>Policies</li>
<li><img class="logo" src="images/logo.jpg" alt="logo" /></li>
<li>Policies</li>
</ul>
</div>
see this fiddle
http://jsfiddle.net/yvytty/RJ4Yp/
You can also have a look at this (it's not finished) but it has the basic layout sorted, menus etc
https://www.yve3.com/index.html
This is also a link to a great forum, HTML.net. They give you good opinions of your site and have a lot of expertise (just like here)
http://www.html.net/forums/

header div disappears only in firefox (on mouseover)

I have a very odd glitch that only happens in firefox. The header div of my site will disappear from view only after the user has scrolled down the page and then moved the mouse on to the header nav. I have been searching for a couple of hours now on what piece of code I may be missing.
The site is not super dynamic as it does need to be so I don't think there is any Jquery/javascript with improperly formatted event listeners or anything. What I suspect the problem to be is something in the CSS code. I have done 3 different things for this site that I normally do not do. I used an absolutely positioned div, I used z-index and I constructed a CSS only nested menu structure in the nav.
While none of these things by themselves (except the ap div) is truly offensive in nature, I wonder if the combination of these 3 items is causing me a problem?
Here is the page structure for the header div and the governing CSS
<div id="header">
<div id="headwrap">
<div id="logo">
<img src="images/logo.png" height="35px" width="35px"/>
</div> <!-- end logo -->
<div id="logotitle" class="ie">
Cambridge Companies
</div> <!-- end logotitle -->
<div class="headnav">
<ul id="top-menu">
<li><span>Home</span></li>
<li> <span>Company</span>
<ul class="sub-menu">
<li>Overview</li>
<li>Our Mission</li>
<li>Meet the Team</li>
</ul>
</li>
<li> <span>Investments</span>
<ul class="sub-menu">
<li>Completed</li>
<li>Opportunities</li>
</ul>
</li>
<li><span>Services</span></li>
<li><span>Careers</span>
<ul class="sub-menu">
<li>VP of Business Development</li>
<li>Assistant</li>
<li>Intern</li>
</ul>
</li>
<li><span>Contact</span></li>
</ul>
</div> <!-- end headnav -->
<div id="address" align="right">
<strong>1.888.615.6166</strong><br/>9075 W. Diablo Dr., Las Vegas, NV 89148
</div> <!-- end address -->
</div> <!-- end headwrap -->
</div> <!-- end header -->
#header{
position:absolute;
/*background-color:#F90;*/ /* position testing */
background:url(../images/navigation-background.png) repeat;
width:100%;
height:50px;
z-index:2;
}
#logo{
display:inline-block;
padding-top:6px;
margin-left:80px;
}
#logotitle{
position:absolute;
/*background-color:#CC9900;*/ /* position testing */
display:inline-block;
color:#FFFFFF;
height:26px;
width:auto;
font-size:26px;
font-family:Arial, Helvetica, sans-serif;
margin-left:4px;
margin-top:10px;
}
.headnav{
/*background-color:#0099FF;*/ /* position testing */
display:inline-block;
/*margin-left:12px;*/
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
letter-spacing:1pt;
height:10px;
padding-bottom:24px;
margin-left:280px;
}
.navitem{
display:inline-block;
color:#ccb38b;
}
.navitem a:link{color:#ccb38b;}
.navitem a:visited{color:#ccb38b;}
.navitem a:hover{color:#FFF;}
.navitem a:active{color:#ccb38b;}
#address{
/*background-color:#99FF33;*/ /* position testing */
display:inline-block;
float:right;
margin-right:80px;
margin-top:9px;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
color:#ccb38b;
}
#top-menu {
display:block;
float:left;
list-style:none;
margin:0;
padding:0;
}
#top-menu > li {
float:left;
display:block;
height:52px;
}
#top-menu > li > a {
color:#ccb38b;
font-size:12px;
text-decoration:none;
display:block;
}
#top-menu > li > a > span {
border-left:1px solid #ccb38b;
display:inline-block;
padding:0 12px;
height:12px;
margin:12px 0;
}
#top-menu > li:first-child > a > span {
border-left:0;
}
#top-menu > li:hover > a > span {
color:#fff;
text-decoration:none;
}
#top-menu li:hover .sub-menu {
display:block;
}
#top-menu .sub-menu {
position:absolute;
width:210px;
background:transparent url(../images/navigation-background.png) repeat;
list-style:none;
padding:0;
display:none;
margin:0;
margin-top:7px;
}
#top-menu .sub-menu a {
display:block;
padding:10px;
color:#ccb38b;
font-size:12px;
text-decoration:none;
}
#top-menu .sub-menu a:hover {
text-decoration:none;
color:#fff;
}
Any help, suggestions, comments on cleaning up my code or general thoughts are appreciated.
!UPDATE! -- I have solved the issue. At first I believed it was the z-index, however, changing this only made things worse. The problem was the positioning on the #header element. Since I had positioned it as "absolute" it was being rendered wrong. The fix was to change it to the following:
#header{
position:fixed; /* note that this changed to fixed instead of absolute */
/*background-color:#F90;*/ /* position testing */
background:url(../images/navigation-background.png) repeat;
width:100%;
height:50px;
z-index:2;
}
Once I changed the positioning, the header operated as designed. It sticks nicely to the top of the window regardless of scroll and does not disappear in firefox as previously reported.
I feel dumb that I did not think of this sooner, but hey that's how you learn right?
I hope this helps anyone else having the same problem.

Switching out show/hide for hoverintent for better usability with Dropdown Divs, problems changing code over

I am trying to switch out the show and hide functions of jquery for the hoverintent plugin. I want to do this for 2 reasons, number one you can control how long the mouse is over the menu item before the sub item pops up, and number 2 it stops multiple instances from building up. I have been trying since last night to change my code, but I am just not getting this to work...below is my original jquery and html, any help would be greatly appreciated. Thanks ALL!!!
Web Site with Dropdown Menu
http://www.nestudiosonline.com/test.php
Jquery
$(document).ready(function() {
// shows the hidden div in the list
$('#dave').mouseover(function() {
$('#aboutdke').show('200');
});
// hides the hide the div again for that list item
$('#dave').mouseleave(function() {
$('#aboutdke').hide();
}); });
html
<ul id="menu">
<li class="mega"><a class="dkeorg" href="#">DKE.ORG</a></li>
<li class="megamenu" id="dave"><a class="links" href="#">ABOUT DKE</a> <div id="aboutdke">div content </div></li>
<li class="megamenu"><a class="links" href="#">ALUMNI</a></li>
<li class="megamenu"><a class="links" href="#">UNDERGRADUATES</a></li>
<li class="megamenu"><a class="links" href="#">EVENTS</a></li>
<li class="megamenu"><a class="links" href="#">MULTIMEDIA</a></li>
<li class="megamenu"><a class="links" href="#">SHOP DKE</a></li>
</ul>
I did it yay...this is the most simple jquery solution to do a basic drop div with the hoverintent plugin, my html did not have to change at all, ill show my css too....observe
<script type="text/javascript" charset="utf-8">
//<![CDATA[
$(document).ready(function() {
//add hovering class to li's inside of the unordermened with the id menu
function addMega(){
$(this).addClass("hovering");
}
//remove hovering class to li's inside of the unordermened with the id menu
function removeMega(){
$(this).removeClass("hovering");
}
//configuariton for hoverintent plugin, hoveron time, mouse sensitivity, hoveroff time
var megaConfig = {
interval: 300,
sensitivity: 4,
over: addMega,
timeout: 200,
out: removeMega
};
//make list items with the class megamenu have the hoverinter plugin excuted on them
$("li.megamenu").hoverIntent(megaConfig)
});
//]]>
</script>
CSS
ul#menu
{
display:block;
list-style-type:none;
margin:0;
padding:0;
}
ul# menu li
{
display:inline;
position: relative;
}
ul#menu div {
display: none;
}
ul#menu li.mega div {
position: absolute;
}
ul#menu li.hovering div {
display: block;
}
#aboutdke
{
display:block;
color:#FFF;
text-align:left;
font-family:Verdana, Geneva, sans-serif;
font-size:10px;
background-color:#000;
margin:0;
padding-top:10px;
padding-right:10px;
padding-bottom:10px;
padding-left:10px;
border:0px;
width:910px;
height:280px;
float:left;
position:absolute;
z-index:99999;
top:164px;
left:140px;
}
a.links:link
{
display:block;
width:120px;
height:22px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:none;
text-align:center;
outline:none;
float:left;
}
a.links:visited
{
display:block;
width:120px;
height:22px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:none;
text-align:center;
outline:none;
float:left;
}
/* mouse over link */
a.links:hover
{
display:block;
width:120px;
height:22px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:underline;
text-align:center;
outline:none;
background-color:#000;
float:left;
}
/* selected link */
a.links:active
{
display:block;
width:120px;
height:22px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:underline;
text-align:center;
outline:none;
background-color:#000;
float:left;
}
a.dkeorg:link
{
display:block;
width:120px;
height:23px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:none;
text-align:center;
outline:none;
float:left;
}
a.dkeorg:visited
{
display:block;
width:120px;
height:23px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:none;
text-align:center;
outline:none;
}
/* mouse over link */
a.dkeorg:hover
{
display:block;
width:120px;
height:23px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:underline;
text-align:center;
outline:none;
float:left;
}
/* selected link */
a.dkeorg:active
{
display:block;
width:120px;
height:23px;
padding-top:8px;
padding-left:3px;
padding-bottom:0px;
color:#FFF;
text-decoration:underline;
text-align:center;
outline:none;
float:left;
}

Resources