So I have a fairly simple vertical CSS menu based off of UL.
<ul class="vertnav">
<li>Item1</li>
<li>Item2</li>
<li>Selected</li>
</ul>
I want three basic colors (say tan for default LI, orange for VERTNAVDOWN, and red for A:HOVER. However I can't seem to get the vertnavdown class to inherit right, and the .vertnav li a:visited overrides it every time. if I use !important to force it through I can't seem to also get the hover to work.
Any suggestions? I thought I understood inheritance in CSS but I guess I don't.
.vertnav{
list-style: none;
margin: 0px;
width: 172px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
text-align: left;
height: 45px;
}
.vertnav li{
margin: 0px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
border-bottom: 0px none;
border-right: 0px none;
border-top: 1px solid #fff;
border-left: 0px none;
text-align: left;
height: 45px;
width: 172px;
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
}
.vertnav li a{
display: block;
text-align: left;
color: #666666;
font-weight: bold;
background-color: #FFEEC1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
text-decoration: none;
padding-top: 10px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 15px;
height: 45px;
}
.vertnav li a:visited{
display: block;
text-align: left;
color: #666666;
background-color: #FFEEC1;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
font-weight: bold;
text-decoration: none;
padding-top: 10px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 15px;
height: 45px;
}
.vertnav li a:hover{
color: white;
background-color: #ffbf0c;
font-family: Verdana, Arial, Helvetica, sans-serif;
height: 45px;
text-decoration: none;
font-weight: bold;
}
.vertnavdown a
{
display:block;
color: #FFF;
background-color: #ff9000;
}
.vertnavdown a:hover
{
background-color: #ffbf0c;
}
^^^^^^^^^^^^^ Edited to add CSS. ^^^^^^
It would help if you could post the css as well.
What you normally need is something like this
<ul id="nav">
<li><a>one</a></li>
<li class="active"><a>two</a></li>
</ul>
the css would be:
#nav li{
color: red;
}
#nav li a:visited{
color: green;
}
#nav li.active a{
color: blue;
}
you need to be more specific with the active css naming.
.vertnav li a:visited is very specific, and in CSS, more specific overrides less specific, even if the less specific CSS comes later in the inheritance chain.
.vertnavdown on it's own will always be overridden by .vertnav li a:visited -- the best solution is to be more specific with your description of .vertnavdown.
Changing .vertnavdown a and .vertnavdown a:hover to
.vertnav ul li a.vertnavdown .vertnav ul li a.vertnavdown:hover will fix your problem.
EDIT:
Smacks head Apologies, I should have noted that you were trying to fix a problem with the :visited links ... Since you haven't specified a style for a.vertnavdown:visited it inherits the style of .vertnav a:visited.
The solution then is to add a.vertnavdown:visited to whatever style declaration you want it to inherit from. That should fix the problem.
Try with .vertnav li a:visited .vertnavdown
Related
I am trying to set a fixed bar menu in my webpage, with with a transition, not an instant transition, but a 1s transition. Here I leave the code
http://jsfiddle.net/t2fPk/
.sf-menu {
border-bottom: 3px solid #333;
background: #000;
position: relative;
padding: 0;
width: 100%;
}
.sf-menu > li {
border-right: 1px solid #333;
margin-bottom: -3px;
float:left;
}
.sf-menu > li > a {
border-bottom: 0px;
color: #B3B3B3;
font-family: 'Handlee', cursive;
font-weight: 500;
font-size: 28px;
text-transform: none;
font: 600 18px/22px "Open Sans", sans-serif;
color: #484848;
display: block;
padding: 17px 20px;
}
Something like this, but i can't get it
http://jsfiddle.net/ShL4T/8/
What kind of transition are you trying to do? I added a simple background color change to yours, fiddle
.sf-menu {
border-bottom: 3px solid #333;
background: #000;
position: relative;
padding: 0;
width: 100%;
}
.sf-menu > li {
border-right: 1px solid #333;
margin-bottom: -3px;
float:left;
}
.sf-menu > li > a {
border-bottom: 0px;
color: #B3B3B3;
font-family: 'Handlee', cursive;
font-weight: 500;
font-size: 28px;
text-transform: none;
font: 600 18px/22px "Open Sans", sans-serif;
color: #484848;
display: block;
padding: 17px 20px;
background-color:green;
}
.sf-menu > li > a:hover{
transition: background-color 1s ease;
background-color: red;
}
Here is a nice article on CSS transitions that should help http://css-tricks.com/almanac/properties/t/transition/
If you want to do nice animations I recommend looking into the javascript library Greensock. It's really fast and does a nice job of animation.
Noticing your class tags I'm guessing you might be using the Superfish navigation plugin.
If so, the best way to animate would be done inside their JavaScript file. Here's a link to the documentation:
http://users.tpg.com.au/j_birch/plugins/superfish/options/
The animation ones you want to use are:
speed: 'normal'
speedOut: 'fast'
In have created a new simple ASP.Net Web Application, in the Default.aspx file added new div as below
<div id="TestDiv"> Hi, This is CSS test. </div>
And for styling the above div, added below css in Site.css file
#TestDiv{ color:Red; }
If I check the Default.aspx page in Design view, found that the above text color is changed to Red.
But when I ran this application and check in browser, found that color is not changed and css is not applied to it.
I want to use the same Site.css which is declared in master page to be applied for the above div and I don't want to declare css style explicitly in Default.aspx page.
Could you please help me out how can I make it work.
Sharing Site.css content on request
/* DEFAULTS
----------------------------------------------------------*/
body
{
background: #b6b7bc;
font-size: .80em;
font-family: "Helvetica Neue" , "Lucida Grande" , "Segoe UI" , Arial, Helvetica, Verdana, sans-serif;
margin: 0px;
padding: 0px;
color: #696969;
}
a:link, a:visited
{
color: #034af3;
}
a:hover
{
color: #1d60ff;
text-decoration: none;
}
a:active
{
color: #034af3;
}
p
{
margin-bottom: 10px;
line-height: 1.6em;
}
/* HEADINGS
----------------------------------------------------------*/
h1, h2, h3, h4, h5, h6
{
font-size: 1.5em;
color: #666666;
font-variant: small-caps;
text-transform: none;
font-weight: 200;
margin-bottom: 0px;
}
h1
{
font-size: 1.6em;
padding-bottom: 0px;
margin-bottom: 0px;
}
h2
{
font-size: 1.5em;
font-weight: 600;
}
h3
{
font-size: 1.2em;
}
h4
{
font-size: 1.1em;
}
h5, h6
{
font-size: 1em;
}
/* this rule styles <h1> and <h2> tags that are the
first child of the left and right table columns */
.rightColumn > h1, .rightColumn > h2, .leftColumn > h1, .leftColumn > h2
{
margin-top: 0px;
}
/* PRIMARY LAYOUT ELEMENTS
----------------------------------------------------------*/
.page
{
width: 960px;
background-color: #fff;
margin: 20px auto 0px auto;
border: 1px solid #496077;
}
.header
{
position: relative;
margin: 0px;
padding: 0px;
background: #4b6c9e;
width: 100%;
}
.header h1
{
font-weight: 700;
margin: 0px;
padding: 0px 0px 0px 20px;
color: #f9f9f9;
border: none;
line-height: 2em;
font-size: 2em;
}
.main
{
padding: 0px 12px;
margin: 12px 8px 8px 8px;
min-height: 420px;
}
.leftCol
{
padding: 6px 0px;
margin: 12px 8px 8px 8px;
width: 200px;
min-height: 200px;
}
.footer
{
color: #4e5766;
padding: 8px 0px 0px 0px;
margin: 0px auto;
text-align: center;
line-height: normal;
}
/* TAB MENU
----------------------------------------------------------*/
div.hideSkiplink
{
background-color: #3a4f63;
width: 100%;
}
div.menu
{
padding: 4px 0px 4px 8px;
}
div.menu ul
{
list-style: none;
margin: 0px;
padding: 0px;
width: auto;
}
div.menu ul li a, div.menu ul li a:visited
{
background-color: #465c71;
border: 1px #4e667d solid;
color: #dde4ec;
display: block;
line-height: 1.35em;
padding: 4px 20px;
text-decoration: none;
white-space: nowrap;
}
div.menu ul li a:hover
{
background-color: #bfcbd6;
color: #465c71;
text-decoration: none;
}
div.menu ul li a:active
{
background-color: #465c71;
color: #cfdbe6;
text-decoration: none;
}
/* FORM ELEMENTS
----------------------------------------------------------*/
fieldset
{
margin: 1em 0px;
padding: 1em;
border: 1px solid #ccc;
}
fieldset p
{
margin: 2px 12px 10px 10px;
}
fieldset.login label, fieldset.register label, fieldset.changePassword label
{
display: block;
}
fieldset label.inline
{
display: inline;
}
legend
{
font-size: 1.1em;
font-weight: 600;
padding: 2px 4px 8px 4px;
}
input.textEntry
{
width: 320px;
border: 1px solid #ccc;
}
input.passwordEntry
{
width: 320px;
border: 1px solid #ccc;
}
div.accountInfo
{
width: 42%;
}
/* MISC
----------------------------------------------------------*/
.clear
{
clear: both;
}
.title
{
display: block;
float: left;
text-align: left;
width: auto;
}
.loginDisplay
{
font-size: 1.1em;
display: block;
text-align: right;
padding: 10px;
color: White;
}
.loginDisplay a:link
{
color: white;
}
.loginDisplay a:visited
{
color: white;
}
.loginDisplay a:hover
{
color: white;
}
.failureNotification
{
font-size: 1.2em;
color: Red;
}
.bold
{
font-weight: bold;
}
.submitButton
{
text-align: right;
padding-right: 10px;
}
#TestDiv
{
color:Red;
}
One of the reason of it not working is Directory Structure , which is making the CSS not reachable from your Default.aspx . otherwise there is no reason why it will not WORK. You can use the IE developer tool by pressing F12 and select the div and see if your site.css is applied or not. You also see the view source and copy the CSS path in the browser to see if it renders or not or your are getting 404
Make sure you made a tag that containing your currect css file location, and your link tag have to be on header but the div part has to be on body.
There are several reasons for this issue. It's always best to use a browser's dev tools to see what is actually being affected by your front-end changes. Chrome offers the absolute best suite for debugging...just right-click on your page and select "Inspect Element" on your div.
As for the specifics of this problem:
Check to see you have referenced Site.css specifically.
Ensure there are no other parent css definitions overriding yours
If there is a conflict (eg: a "div" definition for color), make sure your css ID definition comes AFTER it in the page flow
Alternative options:
Define CSS on a per-page basis using script closures.
Use inline styling for the particular element.
Response To Comments
Well, every browser has default rules that are assigned to the majority of elements. If you find a style that has been inherited from the body, it's likely due to a css "reset" stylesheet and/or schema where body has been given more reasonable default values. I doubt you'll even find that in an ASP.NET application.
I would suggest creating your own stylesheet and referencing it in your default.aspx page. It doesn't actually matter (so long as you reference YOUR stylesheet AFTER the GENERATED stylesheet) but it keeps everything separate. You don't have a need to change the generated CSS for the most part.
Got 2 answers for you:
Tell me where your deafult.aspx file is located? inside a follder something like site/asp/deafult.aspx and your style is in site/style/site.css, if it does then add in link tag <link href="../Style/Site.css" rel="stylesheet" type="text/css" />
If your website is in Site/deafult.aspx and css is in Site/Styles/Site.css then make sure the different bettwen the big and small words are same.
I want to duplicate the style of buttons on this page http://oakespavers.com/ (left-hand side) with the same hover effect. Every time I try, only the text in the boxes are affected. I want the entire div to change colors on mouseover and keep the code really simple.
This might do it:
HTML:
Home
Our Blog
Contact US
CSS:
a {
border-radius: 5px;
font-weight: 600;
text-align: left;
font-family: "Verdana", "Geneva", "sans-serif";
text-transform: none;
letter-spacing: 0px;
font-weight: bold;
font-size: 12px;
display: block;
padding: 10px 20px;
color: #666;
background-color: #E1E1E1;
text-decoration: none;
width: 225px;
margin: 5px;
}
a:hover {
color: white;
background-color: #75D039;
}
Here's a fiddle with an example
This menu items are moving when hover.How can I make the items static and not moving when hovering.
Same thing happens when putting a specific width and height.
Here's the NEW JSFiddle link.
http://jsfiddle.net/tagaawang/zTCCf/3/
/CSS/
<style type="text/css">
.div{margin:0 auto;position:relative;margin-top:40px;}
.pagination{height: 42px;
clear: right;
top: -21px;
left: 0;
position: absolute;}
.pagination ul{width: 100%;max-height: 42px;}
.pagination li{font-family: 'Open Sans', sans-serif;
list-style: none;
cursor: pointer;
font-weight: 600;
line-height: 23px;
text-indent: 8px;
color: white;
background-color: #0083DE;
height: 26px;
font-size: 14px;display: inline-block;
width: 26px;margin-left:10px; }
.pagination li.selected{background-color: white;
border: 4px solid #F0F0F0;
padding: 5px;
position: relative;
font-weight: 600;
color: #0F7ABE;
font-family: 'Open Sans', sans-serif;}
.pagination li:hover{background-color: #0083DE;
border: 4px solid #F0F0F0;
padding: 5px;
position: relative;
font-weight: 600;
color: #ffffff;
font-family: 'Open Sans', sans-serif;}
</style>
html
<div class="div">
<div class="pagination">
<ul>
<li>1</li>
<li class="selected">2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
</div>
based on your code, the hover and/or selected state goes along with a border of 4px:
border: 4px solid #F0F0F0;
This causes a shift of 4 pixel offcourse, solution:
Add a border with same color as the background of your site as placeholder, then when hovering, change border-color.
.pagination li{
border: 4px solid #fff;
}
.pagination li.selected, .pagination li:hover {
border-color: #F0F0F0;
}
So I have a menu from ul and li, and it looks something like this at page load:
but when i click each menu and executed the code this happens:
what should i do? here's my CSS:
#menu-centered {
padding: 0px;
margin-bottom: 0px;
}
#menu-centered ul {
margin: 0;
padding: 0;
height: 99px;
width: 603px;
}
#menu-centered li {
display: inline;
list-style: none;
padding: 0px;
background: url(images/menu1.png) no-repeat right top;
}
#menu-centered a {
border-style: none;
border-color: inherit;
border-width: medium;
display: block;
margin-right: 0;
padding: 20px 30px 0px 30px;
text-decoration: none;
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
font-weight: normal;
color: #FFFFFF;
height: 68px;
width: 130px;
text-align: center;
}
#menu-centered a:hover {
background: url(images/menu2.png) no-repeat right top;
}
and here's my html code for the menus:
<div id="menu-centered">
<ul>
<li> <a href="javascript:Clikbtn1()" >MENU1</a></li>
<li>MENU2</li>
<li>MENU3</li>
</ul>
</div>
Please help. Thanks
Your menus need some LoVe and HAte. In other words you need to create all four of the important link pseudoselectors to avoid letting browsers destroy your layout by applying the default active pseudoslector.
Define a:link, a:visited, a:hover and a:active for your menu, in that order exactly.