I want to make a navigation bar. I supposed a big block would be shown when i hover a the nav bar. However, it didn't work.
This is my html code.
<div id="outerContainer">
<div id="header">
<a id="logo" href="#"><img src="#"></a>
<div id="nav">
<div class="selectors">aaa</div>
<div class="selectors">bbb</div>
<div class="selectors">ccc</div>
<div class="selectors">ddd</div>
</div>
</div>
<div id="innerContainer">
<div class="navHidden"></div>
<div class="navHidden"></div>
<div class="navHidden"></div>
<div class="navHidden"></div>
<div id="content"></div>
</div>
And, this is my css.
#nav{
position:relative;
float:left;
width:600px;
padding-left:30px;
padding-top:25px;
}
.selectors{
width:150px;
position:relative;
float:left;
margin:0;
z-index:10px;
}
.selectors:hover{border-bottom-color:silver;background-color:silver;}
.navHidden{
width:760px;
height:100px;
background-color:silver;
position:absolute;
z-index:10;
display:none;
visibility:hidden;
}
I want the web become as follow:
|.selectors |.selectors | .selectors | .selectors |
| navHidden .....(only shown when hover)......|
I can only allowed to use html and css, because this is homework.
Thanks.
Your code was adapted so now your have desired layout. But it is NOT PERFECT I did not remove excess rules. Do your homework by yourself
HTML
<div id="header">
<a id="logo" href="#"><img src="#"></a>
<div id="nav">
<div class="selectors">
aaa
<div class="navHidden">Lorem ipsum text</div>
</div>
<div class="selectors">
bbb
<div class="navHidden">Lorem ipsum text</div>
</div>
<div class="selectors">
ccc
<div class="navHidden">Lorem ipsum text</div>
</div>
<div class="selectors">
ddd
<div class="navHidden">Lorem ipsum text</div>
</div>
</div>
</div>
CSS
#nav{
position:relative;
float:left;
width:600px;
padding-left:30px;
padding-top:25px;
}
.selectors{
width:150px;
position:relative;
float:left;
margin:0;
z-index:10px;
}
.selectors:hover{
border-bottom-color:silver;
background-color:silver;
}
.navHidden{
width:760px;
height:100px;
background-color:silver;
position:absolute;
z-index:10;
display:none;
top: 100%;
left: 0;
}
.selectors:hover .navHidden {display: block;}
Try this way to create your navigation.
<style>
ul, li {list-style: none; padding: 0; margin: 0; float: left;}
li a{display: block; width: 100px; height: 40px;}
li a:hover{display: block; width: 100px; height: 40px; background: red;}
li ul {display: none;}
li:hover ul {display: block;}
</style>
</head>
<ul id="nav">
<li class="selectors">aaa</li>
<li class="selectors">bbbb
<ul id="innerContainer">
<li class="navHidden">222</li>
</li>
</ul>
</li>
</ul>
Related
I have drop down menu which use css for acting like menu :-
#primary_nav_wrap
{
background:url("../img/footer_lodyas.png")no-repeat center center fixed;
display:inline-block;
width:800px;
}
#primary_nav_wrap ul
{
list-style:none;
position:relative;
margin:0;
padding:0
}
#primary_nav_wrap ul a
{
display:block;
color:black;
text-decoration:none;
font-weight:bold;
font-size:15px;
line-height:50px;
padding:0 15px;
font-family:yekan,montserratAltenates;
}
#primary_nav_wrap ul li
{
position:relative;
display:inline-block;
float:right;
margin:0;
padding:0
}
#primary_nav_wrap ul li.current-menu-item
{
background:#ddd
}
#primary_nav_wrap ul li:hover
{
background:rgba(255, 153, 0, 0.7);
}
#primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
#primary_nav_wrap ul ul li
{
width:200px
}
#primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px
}
#primary_nav_wrap ul ul ul
{
top:0;
left:100%
}
#primary_nav_wrap ul li:hover > ul
{
display:block
}
.slidshow_container{
max-width:800px;
position:relative;
margin:0;
padding:0;
}
.mySlides{
position:relative;
margin:0;
padding:0;
}
.numbertext{
font-family:yekan,montserratAltenates;
font-size:15px;
position:absolute;
padding:10px;
color:white;
}
.prev,.next{
cursor:pointer;
position:absolute;
padding:10px;
color:white;
margin:auto;
top:150px;
font-size:30px;
border-radius:0px 3px 3px 0px;
}
.next:hover{
background:rgba(40,40,40,0.8);
border-radius:3px 0px 0px 3px;
}
.prev:hover{
background:rgba(40,40,40,0.8);
}
.next{
right:0;
}
.mySlides .text{
font-family:yekan,montserratAltenates;
font-size:15px;
position:absolute;
bottom:0px;
padding:20px;
margin-bottom:5px;
width:800px;
text-align:center;
color:white;
background:rgba(35, 35, 35, 0.60);
overflow:hidden;
}
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home</li>
<li>
Category
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 5</li>
</ul>
</li>
<li>
Contact us
</li>
<li>
About us
</li>
</ul>
</nav>
<br style="clear:both;" />
<div class="slidshow_container">
<div class="mySlides fade">
<div class="numbertext">1 / 4</div>
<img src="~/Content/img/slideshow/image_1.jpg" style="width:100%;height:400px" />
<div class="text">image 1</div>
</div>
<div class="mySlides fade">
<div class="numbertext">2 / 4</div>
<img src="~/Content/img/slideshow/image_2.jpg" style="width:100%;height:400px" />
<div class="text">image 2</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3 / 4</div>
<img src="~/Content/img/slideshow/image_3.jpg" style="width:100%;height:400px" />
<div class="text">image 3</div>
</div>
<div class="mySlides fade">
<div class="numbertext">4/ 4</div>
<img src="~/Content/img/slideshow/image_4.jpg" style="width:100%;height:400px" />
<div class="text">image 4</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
But when I move the mouse over the category menu the blow list get under the image of slide menu like image below:-
So how can I solve this problem ?
z-index will fix your problem,
The z-index property specifies the stack order of an element.
An element with greater stack order is always in front of an element
with a lower stack order.
Note: z-index ONLY works on positioned elements (position:absolute,
position:relative, or position:fixed).
Syntax :
z-index: auto|number|initial|inherit;
Initial value: auto
Applies to positioned elements
Inherited no
https://developer.mozilla.org/en/docs/Web/CSS/z-index
#primary_nav_wrap
{
background:url("../img/footer_lodyas.png")no-repeat center center fixed;
display:inline-block;
width:800px;
}
#primary_nav_wrap ul
{
list-style:none;
position:relative;
margin:0;
padding:0
}
#primary_nav_wrap ul a
{
display:block;
color:black;
text-decoration:none;
font-weight:bold;
font-size:15px;
line-height:50px;
padding:0 15px;
font-family:yekan,montserratAltenates;
}
#primary_nav_wrap ul li
{
position:relative;
display:inline-block;
float:right;
margin:0;
padding:0
}
#primary_nav_wrap ul li.current-menu-item
{
background:#ddd
}
#primary_nav_wrap ul li:hover
{
background:rgba(255, 153, 0, 0.7);
}
#primary_nav_wrap ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0;
/* Here Put z-index*/
z-index:9999;
}
#primary_nav_wrap ul ul li
{
width:200px
}
#primary_nav_wrap ul ul a
{
line-height:120%;
padding:10px 15px
}
#primary_nav_wrap ul ul ul
{
top:0;
left:100%
}
#primary_nav_wrap ul li:hover > ul
{
display:block
}
.slidshow_container{
max-width:800px;
position:relative;
margin:0;
padding:0;
}
.mySlides{
position:relative;
margin:0;
padding:0;
}
.numbertext{
font-family:yekan,montserratAltenates;
font-size:15px;
position:absolute;
padding:10px;
color:white;
}
.prev,.next{
cursor:pointer;
position:absolute;
padding:10px;
color:white;
margin:auto;
top:150px;
font-size:30px;
border-radius:0px 3px 3px 0px;
}
.next:hover{
background:rgba(40,40,40,0.8);
border-radius:3px 0px 0px 3px;
}
.prev:hover{
background:rgba(40,40,40,0.8);
}
.next{
right:0;
}
.mySlides .text{
font-family:yekan,montserratAltenates;
font-size:15px;
position:absolute;
bottom:0px;
padding:20px;
margin-bottom:5px;
width:800px;
text-align:center;
color:white;
background:rgba(35, 35, 35, 0.60);
overflow:hidden;
}
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home</li>
<li>
Category
<ul>
<li>Sub Menu 1</li>
<li>Sub Menu 2</li>
<li>Sub Menu 3</li>
<li>Sub Menu 5</li>
</ul>
</li>
<li>
Contact us
</li>
<li>
About us
</li>
</ul>
</nav>
<br style="clear:both;" />
<div class="slidshow_container">
<div class="mySlides fade">
<div class="numbertext">1 / 4</div>
<img src="~/Content/img/slideshow/image_1.jpg" style="width:100%;height:400px" />
<div class="text">image 1</div>
</div>
<div class="mySlides fade">
<div class="numbertext">2 / 4</div>
<img src="~/Content/img/slideshow/image_2.jpg" style="width:100%;height:400px" />
<div class="text">image 2</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3 / 4</div>
<img src="~/Content/img/slideshow/image_3.jpg" style="width:100%;height:400px" />
<div class="text">image 3</div>
</div>
<div class="mySlides fade">
<div class="numbertext">4/ 4</div>
<img src="~/Content/img/slideshow/image_4.jpg" style="width:100%;height:400px" />
<div class="text">image 4</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
I started to write my code as always and I got this strange vertical spacers between header and section as seen below. This is something very noobish but cant deal with it.
CSS
.container {
background:#000;
}
.pos-center {
background:#000;
width:1080px;
margin: 0 auto;
}
.slider {
background:url(slider.jpg) no-repeat;
height:338px;
width:1080px;
border-bottom:#ff5300 3px solid;
}
.nav {
background:#F00 ;
height:40px;
}
.nav li {
display:inline-block;
list-style:none;
}
HTML
<body>
<header>
<div class="container">
<div class="pos-center">
<div class="slider">
</div>
</div>
</div>
</header>
<section>
<div class="container">
<div class="pos-center">
<div class="nav">
<ul>
<li>Zadaj Pytanie</li>
<li>Komentarze</li>
<li>Dodaj do Ulubionych</li>
<li>Nasze Aukcje</li>
<li>O Nas</li>
</ul>
</div>
</div>
</div>
</section>
</body>
It's because your ul inside .nav has a margin-top.
Set it to margin-top: 0 and you should be fine.
.container {
background:#000;
}
.pos-center {
background:#000;
width:1080px;
margin: 0 auto;
}
.slider {
background:url(slider.jpg) no-repeat;
height:338px;
width:1080px;
border-bottom:#ff5300 3px solid;
}
.nav {
background:#F00 ;
height:40px;
}
.nav ul {
margin-top: 0; //Here
}
.nav li {
display:inline-block;
list-style:none;
}
<body>
<header>
<div class="container">
<div class="pos-center">
<div class="slider">
</div>
</div>
</div>
</header>
<section>
<div class="container">
<div class="pos-center">
<div class="nav">
<ul>
<li>Zadaj Pytanie</li>
<li>Komentarze</li>
<li>Dodaj do Ulubionych</li>
<li>Nasze Aukcje</li>
<li>O Nas</li>
</ul>
</div>
</div>
</div>
</section>
</body>
</html>
This question already has answers here:
How come my float elements aren't within their parent
(2 answers)
Closed 8 years ago.
The Header part of my template doesn't get the height of its nested Elements.
<header id="header">
<div id="header-inner">
<div id="top-left">
Site Title
</div>
<nav id="top-right">
<div class="menu">
<ul>
<li class="current_page_item">Home</li>
<li class="page_item page-item-2">Home2</li>
</ul>
</div>
</nav>
</div>
</header>
#header {width:100%; float:left;}
#header-inner {width:600px; margin:0 auto;}
#top-left {float:left;}
#top-right {float:right;}
I also made a jsfiddle:
http://jsfiddle.net/hqpb3cyc/
The only solution I know is to give the #header and / or #header-inner float:left; or display:inline-block; But I think thats not the right way to do this!?
Hope someone can help me
best regards
You have to clear floats. For example:
<br style="clear: both" />
#header {
width: 100%;
float: left;
background: #D3D3D3;
}
#header-inner {
width: 600px;
margin: 0 auto;
}
#top-left {
float: left;
}
#top-right {
float: right;
}
<header id="header" role="banner">
<div id="header-inner">
<div id="top-left">
Site Title
</div>
<nav id="top-right">
<div class="menu">
<ul>
<li class="current_page_item">Home
</li>
<li class="page_item page-item-2">Home2
</li>
</ul>
</div>
</nav>
</div>
<!-- clear both floats -->
<br style="clear: both" />
</header>
Addinional you can use pseudo-element :after to clear floats:
#header {
width: 100%;
float: left;
background: #D3D3D3;
}
#header-inner {
width: 600px;
margin: 0 auto;
}
#top-left {
float: left;
}
#top-right {
float: right;
}
#header-inner:after {
content: "";
clear: both;
}
<header id="header" role="banner">
<div id="header-inner">
<div id="top-left">
Site Title
</div>
<nav id="top-right">
<div class="menu">
<ul>
<li class="current_page_item">Home
</li>
<li class="page_item page-item-2">Home2
</li>
</ul>
</div>
</nav>
</div>
</header>
You should clear the floated inner element. You don't even have to change your HTML. You can do that in CSS as well by using the after pseudo element:
#header {width:100%; float:left;}
#header-inner {width:600px; margin:0 auto; border: 1px solid red;}
#top-left {float:left;}
#top-right {float:right;}
#header-inner::after{
display: block;
content: "";
clear: both;
}
<header id="header" role="banner">
<div id="header-inner">
<div id="top-left">
Site Title
</div>
<nav id="top-right">
<div class="menu">
<ul>
<li class="current_page_item">Home</li>
<li class="page_item page-item-2">Home2</li>
</ul>
</div>
</nav>
</div>
</header>
Updated fiddle
I would like to have my logo inside my menu, and the list in the middle of the page. But only when i make it float right my logo is staying inside my menu... Here's an example: http://gyazo.com/76719bc76c08765cb1f8fee588b3daae
<body>
<div id="Wrapper">
<header>
<div id="Menu">
<div id="Nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Contact Us</li>
<li>Social</li>
</ul>
</div>
<Div id="logo">
<img src="Breaking Bad.png" alt="Logo" height="150px">
</div>
</div>
</header>
<div id="Video"><iframe width="640" height="360" src="http://www.youtube.com/embed/Gx7L8FWN80Y" frameborder="0" allowfullscreen></iframe></div>
<div id="News"></div>
<div id="Footer"></div>
</div>
</body>
body{
font-family:impact;
overflow-y: scroll;
background-color:#4A4247;
margin:0px;
}
#Wrapper{
margin:0 auto;
width:1000px;
}
#Menu{
color:#09b800;
margin:0 auto;
width:1000px;
height:150px;
background-color:#151D04;
}
#Nav{
text-align:center;
margin:0 auto;
display:table;
}
#Logo{
clear:right;
float:left;
}
#Video{
width:640px;
height:360px;
margin-top:20px;
float:left;
background-color:black;
margin-bottom:20px;
}
#News{
margin-top:20px;
width:340px;
height:360px;
color:black;
float:right;
background-color:black;
margin-bottom:20px;
}
#Footer{
clear: both;
background-color:black;
height: 100px;
}
This might be usefull:
<body>
<style>
body{
font-family:impact;
overflow-y: scroll;
background-color:#4A4247;
margin:0px;
}
#Wrapper{
margin:0 auto;
width:1000px;
}
#Menu{
color:#09b800;
margin:0 auto;
width:1000px;
height:150px;
background-color:#151D04;
}
#Nav ul{
margin:0 auto;
}
#Nav{
width:850px;
margin-left:-75px;
text-align:center;
display:table;
float:left;
}
#Logo{
clear:right;
float:left;
width:150px;
}
#Video{
width:640px;
height:360px;
margin-top:20px;
float:left;
background-color:black;
margin-bottom:20px;
}
#News{
margin-top:20px;
width:340px;
height:360px;
color:black;
float:right;
background-color:black;
margin-bottom:20px;
}
#Footer{
clear: both;
background-color:black;
height: 100px;
}
</style>
<div id="Wrapper">
<header>
<div id="Menu">
<div id="logo">
<img src="Breaking Bad.png" alt="Logo" height="150px">
</div>
<div id="Nav">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Contact Us</li>
<li>Social</li>
</ul>
</div>
</div>
</header>
<div id="Video"><iframe width="640" height="360" src="http://www.youtube.com/embed/Gx7L8FWN80Y" frameborder="0" allowfullscreen></iframe></div>
<div id="News"></div>
<div id="Footer"></div>
</div>
</body>
I merge HTML and CSS together,
put float left to both #Nav and #Logo, static width, with negative margin.Read the code and you will notice the trick.
I'm trying to center text within the image and have the text change colour on hover.
However the divider between the text keeps knocking out the grid and I cant get the a:hover function to work? Thanks for helping.
This is what I am trying to achieve,
http://tinypic.com/view.php?pic=az791h&s=8#.U4i1MfldUrU
http://jsfiddle.net/pR8C4/
enter code here
<div id="gallery">
<ul>
<li>
<div class="gallery-image">
<a href=""><img src="http://lorempixel.com/output/people-q-g-320-220-1.jpg"/>
<p class="gallery-desc">top title</p>
<div class="line-separator-three"></div>
<p class="gallery-desc-bottom">bottom title</p></a>
</div>
</li>
<li>
<div class="gallery-image">
<a href=""><img src="http://lorempixel.com/output/people-q-g-320-220-1.jpg"/>
<p></p></a>
</div>
</li>
<li>
<div class="gallery-image">
<img src="http://lorempixel.com/output/people-q-g-320-220-1.jpg"/>
</div>
</li>
<li>
<div class="gallery-image">
<img src="http://lorempixel.com/output/people-q-g-320-220-1.jpg"/>
</div>
</li>
<li>
<div class="gallery-image">
<img src="http://lorempixel.com/output/people-q-g-320-220-1.jpg"/>
</div>
</li>
<li>
<div class="gallery-image">
<img src="http://lorempixel.com/output/people-q-g-320-220-1.jpg"/>
</div>
</li>
<li>
<div class="gallery-image">
<img src="http://lorempixel.com/output/people-q-g-320-220-1.jpg"/>
</div>
</li>
<li>
<div class="gallery-image">
<img src="http://lorempixel.com/output/people-q-g-320-220-1.jpg"/>
</div>
</li>
<li>
<div class="gallery-image">
<img src="http://lorempixel.com/output/people-q-g-320-220-1.jpg"/>
</div>
</li>
</ul>
</div>
enter code here
#gallery {
width:100%;
margin-right:auto;
margin-left:auto;
margin-top:45px;
position:relative;
-webkit-transform: translateZ(0);
}
#gallery ul {
list-style:none;
margin:0;
padding:0;
}
#gallery ul li {
overflow:hidden;
width: 30%;
margin:1.66%;
float:left;
}
#gallery li a {
position:relative;
display:block;
}
#gallery ul p {
position:absolute;
z-index:2;
padding-left:20%;
top:33%;
font-size:1.5em;
font-family:'avenir';
text-align:center;
}
#gallery ul a {
color:#fff;
}
.gallery li a:hover{
color:#FF8000;
}
#gallery ul img {
position: relative;
z-index:1;
width: 100%;
}
.line-separator-three{
width:50%;
margin-left:25%;
height:1px;
background:#F5F5F5;
border-bottom:1px solid #F5F5F5;
margin-top:20px;
margin-bottom:20px;
position:absolute;
z-index:3;
}
enter code here
For the :hover effect you just have to change the class-selector .gallery li a:hover into an id-selector #gallery li a:hover.