i have a stack right now when i explore HTML5 and CSS3 , i try to create a expand and collapse menu but i have problem when menu pull down a border bottom from css3 not pull down too, how can i solve it?
i post my code for you can easy to see and correct for me, tks!
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style/style.css" media="screen" />
<script src="http://code.jquery.com/jquery-2.0.0.js"></script>
<script>
$(function() {
$('#MainMenu').click(function(){
$('.sub').slideToggle();
});
});
</script>
<title>Admin Control Panel - TBB Rocking Crew</title>
</head>
<body>
<div id="dHeader">
<header> </header>
</div>
<div id="dBody">
<aside>
<article class="asideBoxTitle"> <img src="img/home.jpg" class="ico"/> <span class="asideTitle">Dashboard</span> </article>
<article class="asideBoxTitle"> <a href="#"> <img src="img/world.png" class="ico"/>
<ul id="menu">
<li id="MainMenu" class="asideTitle">WorldWide</li>
<li class="sub">Chapterz</li>
<li class="sub">Memberz</li>
</ul>
</a> </article>
<article class="asideBoxTitle"> <img src="img/home.jpg" class="ico"/> <span class="asideTitle">Dashboard</span> </article>
</aside>
<!-- end aside-->
<section> </section>
</div>
</body>
</html>
==============================
#charset "utf-8";
/* CSS Document */
body{
margin:0px;
}
aside{
width:240px;
background:#f5f5f5;
position:absolute;
top: 58px;
bottom:0;
border-right-width:1px;
border-right-style:solid;
border-right-color:#e2e2e2;
}
.asideBoxTitle{
height:40px;
line-height:40px;
border-bottom-width:1px;
border-bottom-style:solid;
border-bottom-color:#e2e2e2;
width:100%;
}
.asideBoxTitle a{
text-decoration:none;
float:left;
}
.asideTitle{
color:#000;
text-decoration:none;
margin-left:20px;
margin-top:-10px;
vertical-align:middle;
}
.asideBoxTitle ul{
display:inline-table;
list-style-type: none;
margin: 0;
padding: 0;
cursor:pointer;
}
.sub{
display:none;
color:#000;
text-decoration:none;
margin-left:20px;
vertical-align:middle;
}
.sub:after{
border-bottom-width:1px;
border-bottom-style:solid;
border-bottom-color:#e2e2e2;
width:100%;
}
.ico{
vertical-align:text-top;
margin-left:10px;
}
#dHeader{
background:#20638f;
height:58px;
width:100%;
}
The problem is that you're specifying the height of each item at 40px. They must stay at 40px. They won't move. You are currently making the <a> tags move dynamically, and that will work, but just for the stuff inside the <a> tags; the parent object won't be affected.
A simple way to solve this is to simply set the height attribute of the <article class="asideBoxTitle"> elements to be a min-height instead and remove the float properties from the child <a> tags so that they affect the position of their parent's next sibling. Like so:
.asideBoxTitle{
min-height:40px;
line-height:40px;
border-bottom-width:1px;
border-bottom-style:solid;
border-bottom-color:#e2e2e2;
width:100%;
}
.asideBoxTitle a{
text-decoration:none;
}
Here's a JSFiddle. Regards.
Related
I made a menu and used width: 100% to make sure it comes across the entire page but there were white spaces on the right and left side (looks more like width:95%?) So I then tried using position:absolute top:0 left:0 which solved the problem and made the menu look like width 100%,
Unfortunately, this operation caused my h2 header element to disappear and I cannot find a way to properly place it now?
JSBin code of my html and css code
#mainMenu {
font-family:Arial, Times, sans-serif;
list-style-type:none;
padding:0;
}
#mainMenu a {
text-decoration:none;
margin:5px;
padding:2px;
color:SeaGreen;
font-weight:bold;
}
#mainMenu a:hover {
color:Teal;
}
#menu {
text-align:center;
width:100%;
height:50px;
background-color:paleGoldenRod;
position:absolute;
left:0;
top:0;
}
li {
display:inline;
}
footer {
background-color:SlateGray;
height:150px;
width:100%;
position:absolute;
bottom:0;
left:0;
}
<!DOCTYPE html>
<html>
<head>
<title>Miko</title>
<link href="#" rel="stylesheet" type="text/css">
</head>
<body>
<div id="menu">
<ul id="mainMenu">
<li>HOME</li>
<li>ABOUT</li>
<li>CONTACT ME</li>
</ul>
</div>
<h2>About The Page</h2>
<p>To Be Added</p>
<footer>
<p>Web Design</p>
</footer>
</body>
</html>
How come position:absolute makes my h2 disappear?
To avoid the default margins in general, you can add margin: 0; to html and body.
To place your absolutely positioned menu behind the h2element, you can apply z-index: -1, which moves it behind its parent element.
In my snippet below I also changed the text-centering to right alignment and added a padding-right on the ul. You can play around with those values so they fit your needs.
html, body {
margin: 0;
}
#mainMenu {
font-family:Arial, Times, sans-serif;
list-style-type:none;
padding-right: 30px;
}
#mainMenu a {
text-decoration:none;
margin:5px;
padding:2px;
color:SeaGreen;
font-weight:bold;
}
#mainMenu a:hover {
color:Teal;
}
#menu {
text-align:right;
width:100%;
height:50px;
background-color:paleGoldenRod;
position: absolute;
z-index: -1;
}
li {
display:inline;
}
footer {
background-color:SlateGray;
height:150px;
width:100%;
position:absolute;
bottom:0;
left:0;
}
<!DOCTYPE html>
<html>
<head>
<title>Miko</title>
<link href="#" rel="stylesheet" type="text/css">
</head>
<body>
<div id="menu">
<ul id="mainMenu">
<li>HOME</li>
<li>ABOUT</li>
<li>CONTACT ME</li>
</ul>
</div>
<h2>About The Page</h2>
<p>To Be Added</p>
<footer>
<p>Web Design</p>
</footer>
</body>
</html>
Add padding-top: 50px (the menu height) to body.
body {
padding-top: 50px;
}
#mainMenu {
font-family:Arial, Times, sans-serif;
list-style-type:none;
padding:0;
}
#mainMenu a {
text-decoration:none;
margin:5px;
padding:2px;
color:SeaGreen;
font-weight:bold;
}
#mainMenu a:hover {
color:Teal;
}
#menu {
text-align:center;
width:100%;
height:50px;
background-color:paleGoldenRod;
position:absolute;
left:0;
top:0;
}
li {
display:inline;
}
footer {
background-color:SlateGray;
height:150px;
width:100%;
position:absolute;
bottom:0;
left:0;
}
<!DOCTYPE html>
<html>
<head>
<title>Miko</title>
<link href="#" rel="stylesheet" type="text/css">
</head>
<body>
<div id="menu">
<ul id="mainMenu">
<li>HOME</li>
<li>ABOUT</li>
<li>CONTACT ME</li>
</ul>
</div>
<h2>About The Page</h2>
<p>To Be Added</p>
<footer>
<p>Web Design</p>
</footer>
</body>
</html>
JSBin
Position in css is tricky thing, everyone uses absolute positioning for placement of element.but before using it. you need to know about what the position is all about. when we use position:absolute then element act like it is floating on top of all element.while using absolute positioning element goes out from html normal flow.
you have used position absolute for both menu links and footer, So these elemment are floating on top of other elements.enter code here
use position absolute and fixed when you want to stick element to specific position.
#mainMenu {
font-family:Arial, Times, sans-serif;
list-style-type:none;
padding:0;
}
#mainMenu a {
text-decoration:none;
margin:5px;
padding:2px;
color:SeaGreen;
font-weight:bold;
}
#mainMenu a:hover {
color:Teal;
}
#menu {
text-align:center;
width:100%;
height:50px;
background-color:paleGoldenRod;
}
li {
display:inline;
}
footer {
background-color:SlateGray;
height:150px;
width:100%;
position:absolute;
bottom:0;
left:0;
}
if you still want to use position absolute for menu, so you need to use proper margin for h2 tag.so that h2 tag will not be hidden beside menu links.
header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
nav {
line-height:30px;
background-color:gainsboro;
height:548px;
width:100px;
float:left;
padding:px;
}
body {
background-color:Lavender;
}
article {
float:right;
height:1250px;
width:580px;
text-align:center;
padding:1em;
background-color:#5DADE2;
}
section {
float:left;
height:1320px;
width:600px;
text-align:center;
padding:0em;
background-color:#ECF0F1
}
footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
div.container {
width:100%;
border:2px solid purple;
}
.clearfix {
overflow: auto;
}
.clear {
clear:right;
line-height:0;
}
<!DOCTYPE HTML>
<html>
<head>
<title>Links - Bannerlord Assignment</title>
<link rel="stylesheet" type="text/css" a href="BannerlordTheme2.css">
</head>
<div class="container">
<body>
<header>
<h1>Further Information</h1>
</header>
<nav>
Home<br>
About<br>
Media<br>
</nav>
</body>
</div>
<br class="clear" />
</html>
Please do bear with me I am aware this is mind-numbingly basic but I need to start somewhere and I both can't find an answer and can't find a reason why.
My nav bar does not correspond to my div's border and this is less of a problem but how do I get it so that the nav bar and the header don't overlap when I use the border because as of now the div border is only working on the header.
you need overflow hidden to container.
header {
background-color:black;
color:white;
text-align:center;
padding:5px;
}
nav {
line-height:30px;
background-color:gainsboro;
height:548px;
width:100px;
float:left;
padding:px;
}
body {
background-color:Lavender;
}
article {
float:right;
height:1250px;
width:580px;
text-align:center;
padding:1em;
background-color:#5DADE2;
}
section {
float:left;
height:1320px;
width:600px;
text-align:center;
padding:0em;
background-color:#ECF0F1
}
footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
div.container {
width:100%;
border:2px solid purple;
overflow: hidden;
}
.clearfix {
overflow: auto;
}
.clear {
clear:right;
line-height:0;
}
<!DOCTYPE HTML>
<html>
<head>
<title>Links - Bannerlord Assignment</title>
<link rel="stylesheet" type="text/css" a href="BannerlordTheme2.css">
</head>
<div class="container">
<body>
<header>
<h1>Further Information</h1>
</header>
<nav>
Home<br>
About<br>
Media<br>
</nav>
</body>
</div>
<br class="clear" />
</html>
Have you thought about adding a 5px top margin to your nav bar, this will account for the 5px border... I think. I'm also still learning. Best of luck, I'll be watching.
Also you always want body to be the outer most thing of what is rendered on the page. So any containers need to be inside of it.
Problem is a) your body tag is in the wrong place (should start just before head, and end just before html tag and b) there is no height declaration on the container.
Adding this code to the CSS:
html,body {
background-color:Lavender;
height:100%;
}
div.container {
width:100%;
height:100%;
border:2px solid purple;
}
and having this to html should work.
<body>
<div class="container" style = "border: solid yellow;">
<header>
<h1>Further Information</h1>
</header>
<nav>
Home<br>
About<br>
Media<br>
</nav>
</div>
<br class="clear" />
</body>
</html>
I have been trying to design a multilevel navigational menu in HTML and CSS but have not been able to stack the list items inside ul.sub1 on top of each other. They definitely seem to obey the rules defined for ul#navmenu li but that's definitely not what I expected . The list items under ul.sub1 should be stacked on top of each other instead of being aligned horizontally one after the other. What is the logical error that I am making? Please explain as I am a newbie to CSS Navigational Menus. Here is my HTML code snippet :
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<style>
*{
margin:0px;
padding:0px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box; <!--Specifies an element should have padding and border included in element's total width and height-->
<!--Content Box is the default value for the height and width properties-->
}
<!--Resetter rules for browsers-->
#bodyContainer {
}
body {
border:black 2px solid;
background-color : grey;
padding:5px;
}
div#header {
margin:10px auto;
background-color : red;
width:70%;
-webkit-border-radius:15px;
-moz-border-radius:15px;
border-radius:15px;
}
div#header1 {
display:inline-block;
width:50%;
text-align:center;
line-height:80px;
}
div#header2 {
display:inline-block;
width:50%;
text-align:center;
line-height:80px;
}
ul#navmenu , ul.sub1{
list-style-type:none;
background-color:#444;
margin-bottom:20px;
border-radius:5px;
}
ul#navmenu li {
border:black 1px solid;
background:yellow;
border-radius:5px;
height:30px;
text-align:center;
line-height:30px;
width:33.33%;
float:left;
position:relative;
}
ul#navmenu a {
text-decoration:none;
width:100%;
display:block;
}
ul.sub1 li {
border:black 1px solid;
background:yellow;
border-radius:5px;
height:30px;
text-align:center;
line-height:30px;
width:100px;
positipn:absolute;
display:block;
}
</style>
</head>
<body>
<div id="bodyContainer">
<div id="header">
<div id="header1"><h1>Welcome</h1></div><div id="header2"><h1>You Get to choose better !! </h1></div>
</div>
<div id="content">
<div id="contentHeader">
<p>You Select ... We Serve </p>
</div>
<div id="nav">
<ul id="navmenu">
<li>Home
<ul class="sub1">
<li>Home1</li>
<li>Home2</li>
<li>Home3</li>
</ul>
</li>
<li>Electronics</li>
<li>Fashions</li>
</ul>
</div>
</div>
<div id="sidebar">
</div>
<div id="footer">
<p>WebApp Version Numbered v1.0. All rights Reserved. </p>
</div>
</div>
</body>
</html>
The "li" elements you're having problems with have their width overridden by the parent's "li", because of the higher specificity of the "ul#navmenu li" versus "ul.sub1 li"
So either add:
width: 100% !important;
to your "ul.sub1 li" rule, or make the same rule of higher specificity, for example:
ul#navmenu li ul.sub1 li
and the width of the "ul.sub1 li" width will be used.
You can learn more about CSS specificity in this smashing article: http://www.smashingmagazine.com/2007/07/27/css-specificity-things-you-should-know/
I've been trying to absolutely position my navigation at the bottom right of its parent div (header>nav>menu) and i'm a little lost. Help would be appreciated!
I've been trying to relatively position its parent div, but each property i try, it either disappears from the browser, aligns all the way at the bottom right of the page and not its parent div, or somewhere else i'm not wanting it to go.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="images/favicon.png" />
</head>
<body>
<div id="wrapper">
<header>
<div class="logo">
<img src="images/logo.png" / id="logo">
</div>
<nav>
<ul id="menu">
<li>Home</li>
<li>Portfolio</li>
<li>Career</li>
<li>Contact</li>
</ul>
</nav>
</header>
</div>
</body>
</html>
body {
margin:auto;
width:960px;
}
.logo {
display:block;
float:left;
width:242px;
height:141px;
margin:0px;
}
#header {
position:relative;
height:100%;
}
#nav .menu {
position:absolute;
bottom:0px;
right:0px;
margin:0px;
padding:0px;
float:right;
}
#menu ul {
list-style:none;
}
#menu li {
display:inline;
float:left;
}
#menu a {
display:block;
width:120px;
font-weight:bold;
color:#FFFFFF;
background-color:#98bf21;
text-align:center;
padding:4px;
text-decoration:none;
text-transform:uppercase;
}
#menu a:hover,a:active
{
background-color:#7A991A;
}
you define in your css nav is a tag element not id or menu is a id not class Please change to your css and define as like this
Change to this
#nav .menu
into this
nav #menu
Demo
You made some mistakes,
you use #header in css but you don't put id header to the <header> tag,
you use #nav in css instead of nav tag because there is no id in nav tag,
#header height is 100%. it will take the height of parent. put height:auto; so that it will take only the height it need to fit its content.
I made a JSFiddle. please check. hope this will solve your problem.
http://jsfiddle.net/banded_krait/Q4Zjj/
I am trying to replicate layout of html5doctor.com. I have IE8 installed here.
I am able to produce following output:
HTML
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css" />
</head>
<body>
<div id="header">
</div>
<div id="nav">
<div id="navmenus">
<ul id="navmenulist">
<li class="menu" id="id1">
Home
<li class="menu">
Products
<li class="menu">
About Us
</ul>
</div>
</div>
<div id="content" >
<div id="article"></div>
<div id="sidebar"></div>
</div>
<div id="footer"></div>
</body>
</html>
CSS
/*I have added CSS Reset from http://meyerweb.com/eric/tools/css/reset/
Just deleted it for simplicity
*/
body
{
margin:0px;
padding:0px;
background-color:#E8E8E8;
text-align:center;
}
#header
{
background-color:#1F7ADB;
width:100%;
height:150px;
}
#nav
{
background-color:#1F7ADB;
width:100%;
text-align:center;
}
#navmenus
{
background-color:#14B3F7;
width:900px;
text-align:left;
}
li.menu
{
list-style:none;
display:inline;
height:35px;
padding:12px;
}
li.menu:hover
{
background-color:yellow;
}
li.menu a
{
text-decoration:none;
font-family:Arial;
font-size:18px;
}
#content
{
width:900px;
background-color:#ffffff;
height:1300px;
}
Notice li.menu:hover in above CSS. It is not working in IE8. So I added <!DOCTYPE html> as suggested at this thread.
It made hover work but now it broke the layout as follows:
I will like to get result that will work on IE8 first and then will like to learn work around that will work consistently in major (may not be in IE6) browser. And will glad to stick to CSS and HTML (no script). And above all will like to learn whats exactly wrong here.
Remove the text-align:center; from the body and use margin:auto for the block elements you want centered in the page..
The elements that require it are #navmenus and #content, so
#navmenus
{
background-color:#14B3F7;
width:900px;
margin:0 auto;
}
#content
{
width:900px;
background-color:#ffffff;
height:1300px;
margin:0 auto;
}
I would update the CSS for the content area to this:
#content
{
width:900px;
background-color:#ffffff;
height:1300px;
margin: 0 auto;
}
Using the margin will center this element, rather than trying to use text-align on the parent element.