div shifts to the right when drop down menu appears - html

So I have an image inside a div that is centered in an outer-wrapper. I have a horizontal menu at the top of the wrapper that displays 5 sub divs inline. I have added css for a drop down menu that appears when you hover over the first of the 5 inline sub divs. When the drop down menu appears, it causes the image to shift to the right and I can't for the life of me figure out how to correct it. As you can see I have played around with z-index but i'm not sure if I understand what is happening or not happening with z-index and how it is used correctly.
HTML:
<div class="wrapper">
<div id="topmenu">
<div id="home">Home
<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul>
</div>
</div>
<div id="logo">
<img src="image.jpeg" />
</div>
</div>
CSS
.wrapper{
position:relative;
width:960px;
height:905px;
margin-top:5px;
margin-left:auto;
margin-right:auto;
/*text-align:left;
border:2px solid red;*/
background-color:#FFFFFF;
}
#topmenu{
position:relative;
border-bottom:2px solid #164207;
height:30px;
background-color:#ffffff;
z-index:3;
}
#logo{
position:relative;
border-bottom:2px solid #164207;
}
#logo img{
position:relative;
height:350px;
width:500px;
z-index:1;
}
#home{
display:inline-block;
float:left;
margin-top:5px;
margin-left:15px;
width:169px;
color:#164207;
font-family:serif;
font-weight:bold;
font-size:20px;
text-align:center;
border-right:2px solid #164207;
}
#home:hover .sub-menu {display:inline-block;}
.sub-menu {
overflow:hidden;
display: none;
width: 169px;
background-color: #164207;
color:#FFFFFF;
margin-top: 5px;
border: 1px solid #fff;
-webkit-box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
-moz-box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
}
.sub-menu li {
position:relative;
list-style-type: none;
display: block;
border-bottom: 1px solid #FFFFFF /*#eaeaea*/;
font-family:serif;
font-size: 12px;
height: 15px;
padding: 8px 0;
}

You need to add position: absolute; to .sub-menu to create a stacking context.
jsFiddle
#home{
display:block;
float:left;
margin-top:5px;
width:184px;
color:#164207;
font-family:serif;
font-weight:bold;
font-size:20px;
text-align:center;
border-right:2px solid #164207;
}
#home:hover .sub-menu {display:block;}
#course:hover .sub-menu{display:block;}
#leagues:hover .sub-menu{display:block;}
#events:hover .sub-menu{display:block;}
#about:hover .sub-menu{display:block;}
.sub-menu {
overflow:hidden;
display: none;
width: 182px;
background-color: #164207;
color:#FFFFFF;
/*padding: 10px 10px;
margin-left: 0px;*/
margin-top: 5px;
border: 1px solid #fff;
-webkit-box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
-moz-box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
box-shadow: 0px 13px 25px rgba(0,0,0, 0.2);
position:absolute; /**************************** Important Bit*/
top:24px;
}
To re-adjust alignment- Remove margin-left:15px; from #home, #course, #leagues, #events, and #about and adjust widths on all of them. Then adjust the width of .sub-menu. See updated jsFiddle above for details and working model.
Example with navigation set up in <ul> unordered list </ul>. - Don't Need all the id's and resulting redundant CSS.

Related

How to have the cutout of a div at the bottom right with shadow to the left

Fiddle: https://jsfiddle.net/pj489c50/
HTML:
<div class="folded-corner-topright">
<p>JUST ANOTHER TEXT</p>
</div>
How can I modify my CSS, so
The box shadow goes all the way to the end at the top
Move the arrow to the bottom and to add a gray arrow left of the blue arrow.
This should get you close. As a tip, I would separate your :before and :after selector properties so its more clear which rules are being applied to each.
html{
height:100%;
}
body{
height:100%;
-moz-box-sizing:border-box;
box-sizing:border-box;
padding:20px;
background: #FFF;
}
[class^="folded-corner-"]{
color: #444;
position:relative;
width:350px;
background:#E4E4E4;
margin-bottom:10px;
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.3);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.3);
}
[class^="folded-corner-"],
[class^="folded-corner-"]:before{
min-height:100px;
right: 20px;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
[class^="folded-corner-"]:before,
[class^="folded-corner-"]:after{
position:absolute;
content:"";
display:block;
position:absolute;
bottom:0;
margin-right: 20px;
width:0px;
height:0px;
box-sizing: border-box;
border-style:solid;
}
[class^="folded-corner-"] p{
padding:20px;
color:#444;
font-size:12px;
}
.folded-corner-topright:before{
border-width:0px 0px 20px 20px;
border-color:transparent transparent #d7d7d7 transparent;
right: 0px;
}
.folded-corner-topright:after{
right:-20px;
border-width:20px 20px 0px 0px;
border-color:#0099E7 #fff transparent transparent;
box-shadow:3px 3px 2px 2px #FFF;
}
<div class="folded-corner-topright">
<p>JUST ANOTHER TEXT</p>
</div>

active link with css sliding down

I have one problem with my CSS code.
The problem is active link sliding down.
This is my DEMO page link from codepen .
If you check my DEMO page then you see blue border color active links. I want that links come on the al the images. But now 5,6,7 numbers picture active link blue border sliding down. What can i do here anyone can help me?
.slider-control-nav a {
display: inline-block;
width: 96px;
height: 71px;
float:left;
border-radius:3px;
-webkit-border-radius:3px;
-moz-border-radius:3px;
-o-border-radius:3px;
text-indent: -9999px;
margin-left:16px;
margin-top:5px;
}
.slider-control-nav a.active {
border:2px solid #3978f5;
opacity:1;
box-shadow:inset 0px 0px 10px 3px #777777;
-moz-box-shadow:inset 0px 0px 10px 3px #777777;
-webkit-box-shadow:inset 0px 0px 10px 3px #777777;
width: 97px;
height: 72px;
}
.imgtmb img {
width:97px;
height:auto;
border-radius:3px;
-webkit-border-radis:3px;
-o-border-radius:3px;
-moz-border-radius:3px;
}
.imgtmb {
float: left;
width: 97px;
height: 72px;
margin-left: 16px;
margin-top: 6px;
}
Move slider-control-nav section from within img_tb and place it above.
Increase .container's width to not force the images below

Remove the border where two division intersect

I am attaching two division's border and remove the border where two division intersect but its not remove. I have tried this code.
<div style="border:solid 1px #CCC;
margin: 15px 0px 0px 350px;
border-bottom:none;
padding:12px 12px 8px 12px;
border-radius:5px 5px 0px 0px;
width:300px;
text-align:center;">
<strong style="font-size:18px; color:#000">ABC</strong>
</div>
<div style="width:968px;
float:left;
margin:0px 15px 15px 15px;
border: solid 1px;
border-color:#CCC;
border-radius:10px;">
Hello
</div>
Can anybody help me to solve this error.
jsFiddle: http://jsfiddle.net/9XFDp/1/
Just nudge the top div by 1px from top and use some background-color or even border-bottom is fine
Demo
Added the below properties to the header div
position: relative;
top: 1px;
background: #fff;
z-index: 1;
Note: Don't use inline CSS, create classes instead.
Demo 2 (Without using background-color, used border-bottom: 1px solid #fff; instead)
Like this
DEMO
CSS
.title{
border:solid 1px #CCC;
margin: 15px 0px 0px 350px;
border-bottom:1px solid #ffffff;
padding:12px 12px 8px 12px;
border-radius:5px 5px 0px 0px;
width:300px;
text-align:center;
font-size:18px; color:#000
font-weight:bold;
position:relative;
top:1px;
}
.content{
width:968px;
float:left;
margin:0px 15px 15px 15px;
border: solid 1px;
border-color:#CCC;
border-radius:10px;
}

CSS Box Shadow - Hover Class

I'm trying to build a generic hover class that uses box-shadow amd that will work with multiple colors of buttons. For this reason, I want the "shadow" to be different for every color of button. I'm trying to figure out if there is a way to use or set only the color attribute of a shadow element?
Here is what I mean:
/*Notice that .button shadows does not have a color value*/
.button {
-webkit-box-shadow:
0px 8px 16px 0px;
box-shadow:
0px 8px 16px 0px;
}
.button:hover{
-webkit-box-shadow:
0px 16px 16px 0px;
box-shadow:
0px 16px 16px 0px;
}
/*And color elements does not have other values for the shadow*/
.red{
-webkit-box-shadow:
rgba(255, 0, 0, 0.1);
box-shadow:
rgba(255, 0, 0, 0.1);
}
.green{
-webkit-box-shadow:
rgba(0, 255, 0, 0.1);
box-shadow:
rgba(0, 255, 0, 0.1);
}
...to be used as follows:
<div class="button red>Red Button</div>
<div class="button green>Green Button</div>
I hope that explains the situation. Brainstorm time!
You need to add color: red
.red{
color:red
}
.green{
color:green
}
Since color: property applies to the text also, you need to wrap the text with span tag and give color:black to span.
DEMO
Unfortunately there is no way to specify ONLY the color for a box shadow as specified here: http://dev.w3.org/csswg/css3-background/#the-box-shadow
You will need to give a separate box shadow rule for each color class.
In CSS3 there in no box-shadow-color rule, so for different buttons you need to specify all shadow parameters (size, position, color).
try this css styles in this style using color for individual menu, u can try shadow to set instead of color...
HTMl Code
<div class="menu">
<ul>
<li class="active1">Home</li>
<li>About Us</li>
<li>Portfolio</li>
<li>Product</li>
<li>Services</li>
<li>Contact</li>
</ul>
</div>
CSS Style
.menu{
font-family:Arial, Helvetica, sans-serif;
color:white;
float:left;
position:absolute;
top:95px;
width:855px;
background-image:url(../images/bottom-menu-line.png);
background-position:center bottom;
background-repeat:no-repeat;
}
.menu ul{padding:0; margin-left:65px; border-radius:10px;}
.menu ul li {
float:left;
border-radius:10px;
width:110px;
height:47px;
list-style:none;
padding:0;
margin-left:5px;
margin-right:5px;
/*overflow:hidden*/
}
.menu ul li a {
font-size:12px;
color:#fffcc7;
background-image:url(../images/button.png);
background-position:center;
height:47px;
overflow:hidden;
line-height:47px;
text-decoration:none;
width:110px;
text-align:center;
float:left;
border-radius:10px;
}
.menu li {float:left; padding:0;}
.menu ul li a:hover {
margin: -3px;
}
.menu ul li:nth-of-type(6) a:hover {
border:3px solid #c10202 !important;
border-radius:10px !important;
}
.menu ul li:nth-of-type(5) a:hover {
border:#c1d65f solid 3px;
border-radius:10px;
}
.menu ul li:nth-of-type(4) a:hover {
border:#01d290 solid 3px;
border-radius:10px;
}
.menu ul li:nth-of-type(3) a:hover {
border:#904ca1 solid 3px;
border-radius:10px;
}
.menu ul li:nth-of-type(2) a:hover {
border:#00caf3 solid 3px;
border-radius:10px;
}
.menu ul li:nth-of-type(1) a:hover {
border:3px #d44c1f solid;
border-radius:10px;
}
.active1{
border:3px #d44c1f solid;
width:110px !important;
border-radius:10px;
height:47px !important;
margin-bottom:7px !important;
margin-right:5px !important;
}
.active2{
border:#00caf3 solid 3px;
width:110px !important;
border-radius:10px;
height:47px !important;
margin-bottom:7px !important;
margin-right:5px !important;
}
.active3{
border:#904ca1 solid 3px;
width:110px !important;
border-radius:10px;
height:47px !important;
margin-bottom:7px !important;
margin-right:5px !important;
}
.active4{
border:#01d290 solid 3px;
width:110px !important;
border-radius:10px;
height:47px !important;
margin-bottom:7px !important;
margin-right:5px !important;
}
.active5{
border:#c1d65f solid 3px;
width:110px !important;
border-radius:10px;
height:47px !important;
margin-bottom:7px !important;
margin-right:5px !important;
}
.active6{
border:3px solid #c10202;
width:110px !important;
border-radius:10px;
height:47px !important;
margin-bottom:7px !important;
margin-right:5px !important;
}
No you can't, you have to put the 2 cases normal and hover for each button
http://dev.w3.org/csswg/css3-background/#the-box-shadow

CSS Margin problem

I'm starting out in HTML and CSS.
I have a div element on the page, which doesn't fill the whole page.
In it- there's a ul element and some list items in it.
I want to put the list 227px from the top of the div element, but I can't manage to accomplish this- it pushes it more.
Also- between the list items I want a margin of 40 pixels, but it also does more.
What's the problem?
Here's my code:
Html:
<body>
<div class="Hashta">
<div class="Menu">
<ul id="MenuItems">
<li><a href="#" >ONE</a></li>
<li><a href="#" >TWO</a></li>
<li><a href="#" >THREE</a></li>
<li><a href="#" >FOUR</a></li>
</ul>
</div>
</div>
</body>
CSS:
body {
background-color: Gray;
}
.Hashta{
width:874px;
height:650px;
background-color:black;
margin: auto auto 50px auto;
border-radius: 20px;
border: 3px solid darkgray;
moz-box-shadow: 2px 2px 10px black;
webkit-box-shadow: 2px 2px 10px black;
box-shadow: 2px 2px 10px black;
}
.Menu {
margin-top: 227px;
padding-right: 50px;
float:right;
}
#MenuItems {
list-style:none;
}
#MenuItems li {
text-align:center;
position:relative;
padding: 4px 10px 4px 10px;
margin-right:30px;
margin-bottom: 40px;
border:none;
}
#MenuItems li a{
width: 280px;
height: 70px;
background-color: green;
color:White;
font-family:Arial, Helvetica, sans-serif;
font-size:24px;
display:block;
outline:0;
text-decoration:none;
text-shadow: 1px 1px 1px #000;
line-height: 70px;
}
If you want to measure the pixels- you can install this: http://www.mioplanet.com/products/pixelruler/
(click to rotate)
Thanks!
You should start your styling by resetting all elements so that each browser shows them identical.
You can check one of the many CSS reset libraries around there, but for starting something like this would be already good:
* {
margin: 0;
padding: 0;
}
This, appearing for first in your CSS stylesheet, will remove all margins and paddings for each element, so you can add them later only in the elements you want.
Update
If you want to restore some element margins or paddings after that code (for example in body) simply write a new rule after the one before, like
body {
padding:10px; /* Add 10px to body only */
}
The total height of every list item is height + padding + border + margin.
Change the padding of #MenuItems li into:
padding: 0 10px 0 10px;
See http://jsfiddle.net/NGLN/rBjrD/1/
Add margin:0; padding:0 for body
In #MenuItems li replace:
padding: 4px 10px 4px 10px;
with:
margin: 4px 10px 4px 10px;
This will make the distance equal to 40px between buttons.
Try absolute positioning:
.Hashta{
width:874px;
height:650px;
background-color:black;
margin: auto auto 50px auto;
border-radius: 20px;
border: 3px solid darkgray;
moz-box-shadow: 2px 2px 10px black;
webkit-box-shadow: 2px 2px 10px black;
box-shadow: 2px 2px 10px black;
position:relative;
}
.Menu {
position:absolute;
top:227px;
right:0;
padding-right: 50px;
float:right;
}
try this:
<style>
body {
background-color: Gray;
}
.Hashta{
width:874px;
height:650px;
background-color:black;
margin: auto auto 50px auto;
border-radius: 20px;
border: 3px solid darkgray;
moz-box-shadow: 2px 2px 10px black;
webkit-box-shadow: 2px 2px 10px black;
box-shadow: 2px 2px 10px black;
}
.Menu {
margin-top: 227px;
padding-right: 50px;
float:right;
}
#MenuItems {
list-style:none;
}
.secLi{
text-align:center;
position:relative;
padding: 0px 10px 0px 10px;
margin-right:30px;
margin-top: 40px;
border:none;
}
.firstLi{
text-align:center;
position:relative;
padding: 0px 10px 0px 10px;
margin-right:30px;
margin-top: -16px;
border:none;
}
#MenuItems li a{
width: 280px;
height: 70px;
background-color: green;
color:White;
font-family:Arial, Helvetica, sans-serif;
font-size:24px;
display:block;
outline:0;
text-decoration:none;
text-shadow: 1px 1px 1px #000;
line-height: 70px;
}
</style>
<body>
<div class="Hashta">
<div class="Menu">
<ul id="MenuItems">
<li class="firstLi"><a href="#" >ONE</a></li>
<li class="secLi"><a href="#" >TWO</a></li>
<li class="secLi"><a href="#" >THREE</a></li>
<li class="secLi"><a href="#" >FOUR</a></li>
</ul>
</div>
</div>
</body>