Why don't my anchors appear depressed when clicked? - html

I'm taking a coding class and we were making a navigation bar with clickable links. The problem is mine wouldn't work at all. I added position: relative; and top: 0; so that way the buttons would move down after clicking and also removed the box-shadow after clicking on the link. It doesn't seem to do anything. Does anyone know what the problem might be? Sorry if my question doesn't make any sense.
body {
margin: 10%;
font-family: Tahoma, Verdana, Geneva, sans-serif;
}
nav {
overflow: hidden;
width: 43%;
margin: 0 auto;
padding-bottom: 1em;
}
nav ul {
list-style-type: none;
/* Step 2: Remove bullets */
}
nav ul li {
float: left;
/* Step 3: Float li's left to line up horizontally */
}
/* Psuedoclass Class Selectors - State of links LVHA */
nav a:link {
/* Default state of link */
display: block;
/* Step 4: Gives anchor tag structure */
width: 6em;
/* Increases width of links and makes all buttons a standard width */
border: 2px solid rgb(175, 175, 175);
text-align: center;
text-decoration: none;
padding: .5em 1em;
/* Gives breathing room between content and inside of border */
margin: 0 5px;
border-radius: 6px;
background-color: rgb(190, 190, 190);
color: white;
text-shadow: #666 .1em .1em .1em;
/* Color, right, bottom, blur */
box-shadow: rgba(0, 0, 0, .5) 0 5px 3px;
/* Color, right, bototm, blur */
/* Sets position of each button to relative and sets positions to zero */
position: relative;
top: 0;
}
nav a:visited {
border: 2px solid rgb(175, 175, 175);
color: white;
}
nav a:hover {
background-color: #fdca00;
border-color: #fda700;
}
nav a:active a:focus {
/* Moves button 3px down and removes shadow on click */
top: 3px;
box-shadow: rgba(0, 0, 0, .5) 0 0 0;
}
<nav>
<ul>
<li>Men</li>
<li>Women</li>
<li>Kids</li>
<li>SALE</li>
</ul>
</nav>

The problem lies with this selector: nav a:active a:focus
It translates to an anchor element with focus inside an anchor element that's active inside a nav element. You don't want that. You want a list with two separate selectors, both originating from the nav element:
nav a:active, nav a:focus {}
This addresses both the active (currently being clicked) and focused (no other element has been selected yet) states of the element.
body {
margin: 10%;
font-family: Tahoma, Verdana, Geneva, sans-serif;
}
nav {
overflow: hidden;
width: 43%;
margin: 0 auto;
padding-bottom: 1em;
}
nav ul {
list-style-type: none;
/* Step 2: Remove bullets */
}
nav ul li {
float: left;
/* Step 3: Float li's left to line up horizontally */
}
/* Psuedoclass Class Selectors - State of links LVHA */
nav a:link {
/* Default state of link */
display: block;
/* Step 4: Gives anchor tag structure */
width: 6em;
/* Increases width of links and makes all buttons a standard width */
border: 2px solid rgb(175, 175, 175);
text-align: center;
text-decoration: none;
padding: .5em 1em;
/* Gives breathing room between content and inside of border */
margin: 0 5px;
border-radius: 6px;
background-color: rgb(190, 190, 190);
color: white;
text-shadow: #666 .1em .1em .1em;
/* Color, right, bottom, blur */
box-shadow: rgba(0, 0, 0, .5) 0 5px 3px;
/* Color, right, bototm, blur */
/* Sets position of each button to relative and sets positions to zero */
position: relative;
top: 0;
}
nav a:visited {
border: 2px solid rgb(175, 175, 175);
color: white;
}
nav a:hover {
background-color: #fdca00;
border-color: #fda700;
}
nav a:active, nav a:focus {
/* Moves button 3px down and removes shadow on click */
top: 3px;
box-shadow: rgba(0, 0, 0, .5) 0 0 0;
}
<nav>
<ul>
<li>Men</li>
<li>Women</li>
<li>Kids</li>
<li>SALE</li>
</ul>
</nav>

Related

Menu disappears when hovering away from sibling element

I know similar questions have been asked before, but I can't find an example that matches my use case. On hovering over divs, the dropdown menu appears, but as soon as you hover away from the div, the dropdown disappears. I know that in order to fix this, I need to add a :hover event to the dropdown itself, but I can't figure out a way to do this besides rewriting the whole css rule.
.header .text .nav-link div:hover + .dropdown {
display: block;
position: absolute;
z-index: 100;
margin-top: .2rem;
margin-left: -2rem;
background: hsl(0, 0%, 100%);
padding: 1.5rem;
text-align: left;
border-radius: 5px;
box-shadow: 0 0 15px 3px rgba(0, 0, 0, 0.4);
}
.header .text .nav-link .dropdown:hover {
display: block;
position: absolute;
z-index: 100;
margin-top: .2rem;
margin-left: -2rem;
background: hsl(0, 0%, 100%);
padding: 1.5rem;
text-align: left;
border-radius: 5px;
box-shadow: 0 0 15px 3px rgba(0, 0, 0, 0.4);
}
<div class=nav-link>
<div class='menu-item'>Product<img src="images/icon-arrow-light.svg"></div>
<div class="dropdown">
<ul>
<li>Overview</li>
<li>Pricing</li>
<li>Marketplace</li>
<li>Features</li>
<li>Integrations</li>
</ul>
</div>
</div>
Any help would be appreciated!
I'm assuming you want the dropdown to stay open when hovering product or the items in the drop down.
You can do this by adding a hover to the .nav-link element.
.dropdown {
display: none;
}
.nav-link {
display: inline-block;
/* This prevents the tiny gap the mouse will hit moving from the link to the dropdown */
padding-bottom: .2rem;
}
.nav-link:hover .dropdown {
display: block;
position: absolute;
z-index: 100;
/* this should fall within the .nav-link padding */
margin-top: 0;
margin-left: -2rem;
background: hsl(0, 0%, 100%);
padding: 1.5rem;
text-align: left;
border-radius: 5px;
box-shadow: 0 0 15px 3px rgba(0, 0, 0, 0.4);
}
<div class="nav-link">
<div class="menu-item">Product<img src="images/icon-arrow-light.svg"></div>
<div class="dropdown">
<ul>
<li>Overview</li>
<li>Pricing</li>
<li>Marketplace</li>
<li>Features</li>
<li>Integrations</li>
</ul>
</div>
</div>

How to draw a tab with text in it using HTML and CSS

I will like to make my tab look like this image below:
But I'm not able to draw this. I have gone to W3Schools and looked at several tutorials online but cannot draw this. I have even played around with the pseudo elements such as ::before and ::after but still no luck. Each selection will produce a page.
The design that you are looking for is similar to the one described in this answer of mine. I am posting a separate answer because what you need is a bit more complex than that one due to the presence of gradient background, overlapping triangular areas (on the next item) and box-shadow etc.
The approach used is similar to that answer in the sense that two pseudo-elements are added to each li element and they are skewed in the opposite directions to achieve the effect. The below are some of the additional steps that were done for your design:
A pseudo-element (:after) is added to the ul and a gradient that goes from semi-transparent white to transparent and then to a semi-transparent black is set as its background image. Size of this pseudo-element is lesser than the parent ul container and this produces the gradient effect.
Progressively decreasing z-index are assigned to each li element to bring the earlier element forward and have its triangular bit be above the next element.
box-shadow and border-right are added to the li:before and li:after elements to get the arrow and its shadow.
A solid white border and two box-shadow are added around the ul.
The output is responsive as you can see in the "full page view" of the snippet.
ul {
position: relative;
margin: 0;
padding: 0;
line-height: 60px;
color: white;
font-weight: bold;
text-align: center;
text-transform: uppercase;
border: 2px solid white;
border-radius: 30px;
list-style-type: none;
box-shadow: 2px 2px 0px #DDD, -2px 2px 0px #DDD;
white-space: nowrap;
overflow: hidden;
}
li {
position: relative;
display: inline-block;
width: 33.33%;
text-indent: -20px;
}
li:before,
li:after {
position: absolute;
left: 0;
content: '';
height: 50%;
width: 100%;
background: rgb(31, 139, 188);
border-right: 3px solid rgb(87, 153, 190);
box-shadow: 3px -2px 2px rgba(0, 0, 0, 0.15);
}
li:first-child:before,
li:first-child:after {
background: rgb(255, 0, 0);
}
li:before {
top: 0px;
transform: skewX(45deg);
transform-origin: left bottom;
z-index: -1;
}
li:after {
bottom: 0px;
transform: skewX(-45deg);
transform-origin: left top;
z-index: -2;
}
li:first-child {
text-indent: 0px;
z-index: 2;
}
li:nth-of-type(2) {
z-index: 1;
}
li:last-child {
width: calc(33.33% + 15px);
}
ul:after {
position: absolute;
content: '';
top: 3px;
left: 3px;
height: calc(100% - 6px);
width: calc(100% - 6px);
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.5), rgba(0, 0, 0, 0) 25%, rgba(0, 0, 0, 0) 75%, rgba(0, 0, 0, 0.05));
border-radius: 25px;
z-index: 3;
pointer-events: none;
}
/* if you need hover effects */
li:hover:before,
li:hover:after {
background: yellowgreen;
}
<ul>
<li>Text</li
><li>Text</li
><li>Text</li>
<!-- > is added in next line intentionally to avoid space between inline block elements -->
</ul>
You could also relay on a nav bar and flex.
codepen to play with or snippet below to run
nav {
display: flex;
/* basicly to help to easily spread evenly childs (float, inline-block, table, .. works too ) */
overflow: hidden;
/*might be usefull to hide links not rounded and last arrow */
background: #0077AF;
font-size: 1.8vw; /* 2em;*/
/* vw used for demo , i do not advise this without mediaqueries to control max and min font-size */
padding: 0;
/* reset */
margin: 0.5em 15px;
/* whatever */
border-radius: 2em;
/* image was rounded */
box-shadow: 0 0 0 3px white, 0 0 8px;
/* draw border and shadow */
position: relative;
/* will be used for the web 2.0 glossy thing */
}
nav:before {
/* the glossy thing */
content: '';
/* trigger pseudo */
position: absolute;
/* off flow so to stick where needed */
z-index: 2;
/* on top */
pointer-events: none;
/* click through */
border-radius: 2.5em;
/* increase border-radius because smaller than parent */
top: 5px;
left: 10px;
right: 10px;
bottom: 0;
box-shadow: 0 -15px 18px -8px rgba(255, 255, 255, 0.5);
/* fade outside */
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.65), transparent, transparent 80%);
/* glossy effect drawn */
filter: blur(3px);
/* increase a bit the blur/glossy effect, optionnal */
}
a {
flex: 1;
/* fill parent and share room according to amount */
background: inherit;
/* will be needed to blend with pseudo later */
color: white;
letter-spacing: 1px;
text-decoration: none;
min-width: 14em;
text-align: center;
font-family: 'Oswald', sans-serif;
/* looked close to your font-family */
text-shadow: 2px 2px 2px #222;
padding: 1em;
margin-right: -.8em;
/* will hide arrow on last element */
overflow: hidden;
position: relative;
/* set this to stick arrow shape */
overflow: visible;
/* let arrow show even if outside parent */
}
a:first-of-type {
margin-left: -1em;
/* optionnal */
}
a:after {
/* the right arrow shape */
content: '';
position: absolute;
padding: 1.5em;
box-shadow: 3px -3px 3px rgba(255, 255, 255, 0.5), 5px -5px 6px -1px rgba(0, 0, 0, 0.5);
transform: rotate(45deg);
right: -1em;
/* move outside the square shape */
top: 0.25em;
/* tune this if vertcal padding or line-height is reset or change */
background: inherit;
/* to blend with parent */
z-index: 1;
/* stands on top but under the glossy thing */
}
/* background colors can be modified */
.done {
background: #FC0000;
}
a:hover {
background: #DDA265;
}
img {
display: block;
width: 100%;
/* for the show to compare to html/css render */
}
<link href='https://fonts.googleapis.com/css?family=Oswald:700' rel='stylesheet' type='text/css'>
<p>CSS version & hover :</p>
<nav> SIZE & CRUST
CHEEZE & SAUCE
TOPPINGS
</nav>
<p>image version :
<img src="http://i.stack.imgur.com/ebD59.png" />
</p>

Reducing window size moves elements

Hello awesome programmers,
I have been struggling greatly with CSS for some time now. I have an issue when resizing a window, some of my divs begin to collapse down the page. (As shown)
Before:
before http://411metrics.com/pics/before.PNG
After:
before http://411metrics.com/pics/after.PNG
I have tried setting the min-width to 100% on various divs and also tried setting the overflow to hidden.
Does anyone have any suggestions as to how to fix this?
My HTML:
<div id="navigation">
<div id="branding-logo"><img src="/Portal/images/sharktek-logo.png" width="35" height="35"></div>
<div id="branding">Sharktek Tracking</div>
<div id="link-wrap">
<div id="active-nav">Dashboard</div>
Reports
Call Logs
Manage Campaigns';
</div>
<div id="nav-user">
Welcome<br>
Account Settings
Logout
</div>
</div>
<div id="nav-accent"></div>
My CSS:
#navigation {
z-index:3;
position: fixed;
top: 0;
width: 100%;
min-width:100%;
color: #ffffff;
height: 60px;
text-align: center;
/* Adds the transparent background */
background-color: rgba(22, 29, 37,1);
color: rgba(1, 172, 237, 1);
}
#navigation a {
float:left;
font-size: 14px;
padding: 25px 25px 0 25px;
color: white;
text-decoration: none;
}
#link-wrap {
float: left;
overflow: hidden;
margin-left: 15%;
}
#active-nav{
z-index: 2;
float:left;
color:white;
height: 60px;
background: -webkit-linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* For Firefox 3.6 to 15 */
background: linear-gradient(#346c83, rgba(1, 172, 237, 1)); /* Standard syntax */
}
#active-nav a:hover {
color:white;
}
#navigation a:hover {
color: grey;
}
#branding-logo {
margin-top: 15px;
margin-left: 10px;
float: left;
}
#branding{
margin-top: 20px;
margin-left: 10px;
font-size:1.4em;
color: white;
float: left;
padding: 0px;
}
#nav-accent {
z-index:2;
position: fixed;
top: 60px;
width: 100%;
color: #ffffff;
height: 2px;
padding-top: 1px;
/* Adds shadow to the bottom of the bar */
-webkit-box-shadow: 0px 0px 8px 0px #000000;
-moz-box-shadow: 0px 0px 8px 0px #000000;
box-shadow: 0px 0px 8px 0px #000000;
/* Adds the transparent background */
background-color: rgba(1, 172, 237, 0.95);
color: rgba(1, 172, 237, 1);
}
#nav-user {
color: white;
font-family:Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 15px 30px 0 0;
font-size: .8em;
float:right;
}
#nav-user a{
margin: 0;
padding: 0 0 0 10px;
font-size:.8em;
}
I have had similar problems until I started to understand and apply absolute positioning. i.e. positioning relative the div you are in.
For absolute positioning the parent div must be set to relative positioning and after that you fix your inner elements to whatever side you like without having the browser take over the flow control.
e.g. in your case, with ...
#link-wrap {
position: absolute;
width: 500px;
/* ... the rest */
}
... your nav links will stop jumping all over the page. I made a few more tweaks in this fiddle http://jsfiddle.net/xb9cdu34/2/ .

Increasing the width of button by a few percent on hover

So, I have this made.
HTML
<div id="navholder" class="bgd">
<nav id="nav">
<ul>
<li>Почетна</li>
<li>Делатност</li>
<li>Историјат</li>
<li>Службе</li>
<li>Колектив</li>
<li>Контакт</li>
</ul>
</nav>
</div>
#navholder {
height: 60px;
text-align: center;
margin: 0 auto;
}
#nav {
height: 30px;
margin-top: 10px;
background: #B8860B;
}
#nav ul li{
margin-top: 3px;
display: inline;
font-size: 120%;
opacity: 1.0;
}
#nav ul li a {
display: inline-block;
height: 120%;
padding: 5px;
-webkit-box-shadow: -1px 0px 22px rgba(50, 50, 50, 0.5);
-moz-box-shadow: -1px 0px 22px rgba(50, 50, 50, 0.5);
box-shadow: -1px 0px 22px rgba(50, 50, 50, 0.5);
border: 1px solid white;
opacity: 1.0;
background: #DAA520;
}
#nav a:hover {
color: white;
background: black;
width: ?
}
I want the buttons once hovered over with a mouse to increase about 20%. The problem that I found is if I use the exact width like "width: 60px not every button is of the same size.
On the other hand if I use width: 120% I believe the page takes the width of the whole #navholder element which is defined by the class .bgd.
Any ideas on how can I make this happen?
Thanks.
You could use transform: scale()
jsFiddle example
#nav a:hover {
transform:scale(1.3,1.3);
-webkit-transform:scale(1.3,1.3);
-moz-transform:scale(1.3,1.3);
}
Just increase the padding on hover:
#nav a:hover {
color: white;
background: black;
padding: 5px 10px; /* 5px top/bottom, 10px left/right */
}
You may set width with em's and increase font-size.
Also, you may add border/padding on hover:
#nav a:hover {
border-right: solid 20px black;
/* or padding-right */
}

How to expand my CSS3 menu and reduce its width

I was working on web project, then a requirement came that I should add a top-level menu to my site. So I did a search and I found a menu from this URL http://www.webdesignerdepot.com/2012/08/create-a-stunning-menu-in-css3/.
But when I added the required css files & font, then menu was displayed out of the layout as follow:-
So can anyone advise on how I can do the following :-
To expand the menu horizontally to cover the whole screen .as for the top blue-colored area.
to have it exeactly below the blue-colored top area.
Reduce the menu width, and have it same as the breadcrumb.
Thanks
the css for the menu is :-
.clearfix {
clear: both;
}
.wrap {
width: 940px;
margin: 4em auto;
}
nav {
background: -webkit-gradient(linear, center top, center bottom, from(#fff), to(#ccc));
background-image: linear-gradient(#fff, #ccc);
border-radius: 6px;
box-shadow: 0px 0px 4px 2px rgba(0,0,0,0.4);
padding: 0 10px;
position: relative;
}
.menu li {
float: left;
position: relative;
}
.menu li a {
color: #444;
display: block;
font-size: 14px;
line-height: 20px;
padding: 6px 12px;
margin: 8px 8px;
vertical-align: middle;
text-decoration: none;
}
.menu li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#ededed), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
/* Dropdown styles */
.menu ul {
position: absolute;
left: -9999px;
list-style: none;
opacity: 0;
transition: opacity 1s ease;
}
.menu ul li {
float: none;
}
.menu ul a {
white-space: nowrap;
}
/* Displays the dropdown on hover and moves back into position */
.menu li:hover ul {
background: rgba(255,255,255,0.7);
border-radius: 0 0 6px 6px;
box-shadow: inset 0px 2px 4px rgba(0,0,0,0.4);
left: 5px;
opacity: 1;
}
/* Persistant Hover State */
.menu li:hover a {
background: -webkit-gradient(linear, center top, center bottom, from(#ccc), to(#ededed));
background-image: linear-gradient(#ccc, #ededed);
border-radius: 12px;
box-shadow: inset 0px 0px 1px 1px rgba(0,0,0,0.1);
color: #222;
}
.menu li:hover ul a {
background: none;
border-radius: 0;
box-shadow: none;
}
.menu li:hover ul li a:hover {
background: -webkit-gradient(linear, center top, center bottom, from(#eee), to(#fff));
background-image: linear-gradient(#ededed, #fff);
border-radius: 12px;
box-shadow: inset 0px 0px 4px 2px rgba(0,0,0,0.3);
}
#font-face {
font-family: 'IconicStroke';
src: url("~/fonts/iconic/iconic_stroke.eot");
src: local('IconicStroke'),
url("~/fonts/iconic/iconic_stroke.svg#iconic") format('svg'),
url("~/fonts/iconic/iconic_stroke.otf") format('opentype');
}
.iconic {
color:inherit;
font-family: "IconicStroke";
font-size: 38px;
line-height: 20px;
vertical-align: middle;
}
a.iconic:hover {
color:inherit;
}
My advice! Use firebug(an addon of firefox). Click on the menu and it will open all the css. Try changing them dynamically and chk the changes instantly. It even gives you the file where you need to make changes.
Apart from that what john said is right. Using fluid layout(%) is better than rigid(px). So when you say you need Menu to be of size of page then just make it 100%.
Happy Coding!