Hi I have some HTML and CSS that creates a <ul> on my screen. The items are links to other pages on the site. I want the items in the list to be black normally, light grey if hovered over, and light grey if it's the screen the user is on.
Here is the HTML for the <ul> on the home screen. On the home screen, the list item "Home" should be light grey, while all the others should be black unless hovered over.
<div id="navmenu">
<ul>
<li><a class="selected" href="index.html">Home</a></li>
<li>Research</li>
<li>CV</li>
<li>Links</li>
</ul>
</div>
My CSS sheet is:
#navmenu {
margin: auto;
}
#navmenu ul {
text-align:center;
}
#navmenu ul li {
display:inline;
padding-left:25px;
padding-right:25px;
}
#navmenu ul li a {
color:#000000;
}
#navmenu ul li a:hover {
color:#F2F2F2;
}
#navmenu ul li a:selected {
color:#F2F2F2;
}
The links are black, which is good. They also turn light grey when I hover over them, which is great. But whenever I select one of the items to go to the page, I can't get the link that I'm currently on to be light grey. This also applies to the home page - whenever I go to the first page, the "Home" item is in black.
Can anyone see what I'm doing wrong here? Any help is appreciated.
Do you mean to do this:
#navmenu ul li a.selected {
color:#F2F2F2;
}
See: http://jsfiddle.net/audetwebdesign/nSgDf/
There is currently no :selected pseudo-class in CSS2 or CSS3.
Apply the .selected class to denote the current page that the user is visiting.
Reference: http://www.w3.org/TR/css3-selectors/#pseudo-classes
Related
How do I disable all of them from opening when I hover with the mouse?
I just want the icon I'm on to open.
Can someone tell me the best approach for this ?
Thank you.
before hover
after hover
codepen.io
repl.it view
repl.it source files
When I come on it with the mouse, I just want that column to slide.
There are all the codes in the codepen.io, but the icons are not
visible.
.top-social-bg {
background-color: rgba(0, 0, 0, 60%);
text-align: center;
position: absolute;
right: 0px;
}
<div class="top-social-bg" >
<ul id="top-social">
<li><span class="ts-icon"><i class="icon-call" style="color:white"></i></span><span class="ts-text">telephone</span></li>
<li><span class="ts-icon"><i class="icon-envelope-alt" style="color:white"></i></span><span class="ts-text">email</span></li>
<li><span class="ts-icon"><i class="icon-facebook" style="color:white"></i></span><span class="ts-text">facebook</span></li>
<li><span class="ts-icon"><i class="icon-instagram" style="color:white"></i></span><span class="ts-text">instagram</span></li>
</ul>
</div>
It's hard to give you the correct direction, without seeing how your css is defined for icons I'm assuming you have a .top-social-bg:hover (...followed by maybe li a or i or i:before?)...`
You place the hover where you want hover detected, and then change the css for the child element. You need to specify a style that is specific to the icon.
For example
.top-social-bg li:hover i { display:block;}
or perhaps it's
.top-social-bg li:hover i:before { display:block;}
And then define a class for how it should appear when not hovered.
.top-social-bg li i { display:none;}
or perhaps it's
.top-social-bg li i:before { display:none;}
My website has a scaling problem on the chrome browser in android on mobile. This does not happen in Firefox on mobile or in any desktop browser. When the navbar is selected and drops down, it scales the webpage. Note that the page is scaled differently depending on which dropdown has been selected. It seems as though the navbar has invisible content that is breaking frame when the dropdown behavior is engaged.
I have stitched together 4 screenshots of the issue.
Help with either a fix or a workaround would be much appreciated.
#NavigationBarList{
list-style-type:none;
padding:0;
}
li{
font-size:130%;
}
nav a{
display:block;
}
/* This customizes the presentation of the list elements (menu items) in the navbar. */
nav li{
display:block;
font-weight:bold;
font-size:200%;
color:#7F1717;
background-color:#9E939E;
width:25%;
text-align:center;
text-decoration:none;
text-transform:uppercase;
z-index:11;
-moz-box-shadow: inset 0 0 1px #000000;
-webkit-box-shadow: inset 0 0 1px #000000;
box-shadow: inset 0 0 1px #000000;
}
nav ul{
width:100%;
}
/* Hide the sub menu items. */
nav ul ul {
display:none;
}
nav ul ul ul {
display:none
}
/* When hovered over, the CSS menu will drop down. */
nav li:hover > ul {
text-align:center;
font-size:40%;
display:block;
}
/* Don't underline links in the list elements (menu items). */
ul a {
text-decoration:none;
color:#7F1717;
}
/* Change the background color of hovered list elements. This was both active and hover... */
nav li:hover{
background-color:#625C62;
}
/* This customizes the ul elements in the sub-menu. */
nav ul ul{
position:absolute;
padding:0;
width:100%
}
nav ul ul ul{
position: absolute;
width:400%;
left:100%;
top:0;
}
#totheleft{
left:-100%;
}
nav ul ul ul li{
text-align:center;
font-size:250%;
}
/* I think this refers to the dropdown navbar location and properties. */
nav ul ul li {
position:relative;
}
<nav>
<ul id="NavigationBarList">
<li style="float:left;">Events
<ul>
<li>Tournaments</li>
<li>Kid's Hour</li>
<li>Local Calendar</li>
</ul>
</li>
<li style="float:left;">Programs
<ul>
<li>Summer Camps</li>
<li>In Schools
<ul>
<li>After School</li>
<li>Registration</li>
</ul>
</li>
<li>Local Instructors</li>
</ul>
</li>
<li style="float:left;">Content
<ul>
<li>Posts</li>
<li>Games
</ul>
</li>
</li>
<li style="float:left;">Connect
<ul>
<li>Contact Us</li>
<li>Resources
<ul id="totheleft">
<li>Chess</li>
<li>Go</li>
<li>Xiangqi</li>
<li>Shogi</li>
<li>Backgammon</li>
</ul>
</li>
<li>About Us</li>
</ul>
</li>
</ul>
</nav>
Add this to the head section of all your pages.
<meta name="viewport" content="user-scalable=0">
From the google developers site
Without a viewport, mobile devices will render the page at a typical desktop screen width, scaled to fit the screen.
So when you visit the webpage on mobile, the view is actually zoomed out to fit all your content. When you touch your navbar, the browser also tries to zoom in. Setting user-scalable=0 prevents this from happening.
The downside is your users will no longer be able to scale the zoom on the website on mobile, but the only alternative would be to rewrite your website to use a fluid layout.
Your <ul>s that contain the dropdown items have width=100%. This means the width will be 100% of the first relatively positioned parent (which in this case is the <body>). This is causing an overflow on the x axis.
You could make the <ul>s 25% width and the <li>s inside 100%, instead of what you have now where the <li>s are 25%.
Giving you
/* This customizes the ul elements in the sub-menu. */
nav ul ul{
position:absolute;
padding:0;
width:25%;
}
and
/* I think this refers to the dropdown navbar location and properties. */
nav ul ul li {
position:relative;
width:100%;
}
I went to your site and checked it out real quick... I noticed you are using absolute positioning to position your content in the center of your page. I assume this is what is causing your issue.
I would look up a tutorial on how to create a repeating background image and use that instead of trying to use one image with no repeat. then you can center your content with margin: 0 auto.
I know its not a definite answer but I hope it nudges you in the right direction.
The workaround I came up with was to set overflow-x:hidden on my overlay. I had tried this previously on the body, but on Android overflow-x does not work on the body; it must be set for a container. There is presumably a related reason that this issue only arose on Android. This workaround works perfectly.
I've tried unsuccessfully to fix this for the last few days:
the first time I open the page it has some weird padding on the dropdown menu, only happens on chrome (works fine on FFx and IE)
after the first time the page is loaded it loads fine
as you can see on the screenshot I've already put
.myCustomNav ul
{
padding: 0px !important;
}
the dropdown menu is called like this:
<div>
<ul class="myCustomNav nav">
<li>
<a .../>
</li>
</ul>
</div>
any idea what's wrong?
you can test for yourselves on http://istore.titus.biz/lovelovelove/#
Do you want to reduce the padding on the dropdown? Then reduce the padding on the following class in your css.
.horizontal-category a:link,.horizontal-category a:visited{
color:#96979D;
padding:4px 6px;
display:inline-block;
font-weight:bold;
border-right:1px solid #ec008c;
/*background:#09C;*/
}
Invalid solution - Comments below
You need to make the li for .dropdown-menu - display: block. This needs to be placed at the bottom of your nav CSS.
CSS
.dropdown-menu li {
display: block;
}
If you want to test this do this:
.dropdown-menu li {
display: block !important;
}
That should fix it, but do not use !important as your solution. Just make sure that the first snippet is below the other dropdown CSS.
changed
.myCustomNav li{ display:inline;}
to
.myCustomNav li{ display:inline-block;}
and it worked, just needed a few extra tweaks to position it then
I have two kind of links, the one should be white, the other links should be black. Therefore I added a class to the first navigation
<nav class="navigation">
Über mich
</nav>
In CSS I now did this
.navigation
{
float:right;
margin-top:15pt;
}
.navigation a, a:visited, a:active{
color:white;
text-decoration:none;
margin-left:20px;
}
.navigation a:hover
{
color:white;
text-decoration:underline;
text-decoration-color: red;
margin-left:20px;
}
Now I have other links that should be displayed in black and not in white
<b>Source Code runterladen:</b> Link
Note that this link IS NOT inside a navigation tag. So I did this in CSS
.sourceCode a, .sourceCode a:hover, .sourceCode a:visited, .sourceCode a:active
{
color:black;
}
But the problem is that both links are either white or black. I want them to be different, but it doesn't work and I don't really know why.
Here's the complete source code
http://jsfiddle.net/bVN9X/
Note that the Links in the header are white, but also the links that should be under "Projekte" are white, too. I don't really know why.
Your selector must be defined in this way:
a.sourceCode
Because the way you have it now, it's looking for an a tag inside something with a sourceCode class.
You should change you css as shown below:
a.sourceCode, a.sourceCode:hover, a.sourceCode:visited, a.sourceCode:active
{
color:black;
}
Sorry with title if it is not looks bad, I don't know how can I write the title for my issue.
So I have a menu bar with some menu-items and submenu-items as:
<div id="mainmenu">
<ul id="menu">
<li><a class="current" href="">Menu1</a></li>
<li>Menu2
<ul>
<li>Submenu1</li>
<li>Submenu2</li>
</ul>
</li>
<li>Menu3</li>
<li>Menu4</li>
</ul>
</div>
Here is the fiddle of what I have done so far.
What I want is to keep the menu-item also in :hover state if its submenu-item is being hover, such as If my mouse is on submenu or submenu2 the Menu2 should also be darkened. How can I do this with CSS?
I hope I am clear with my question.
EDIT:
Wooo thanks a lot every-one.
got it with: #menu li:hover
#menu li:hover,#menu a:hover,#menu > li a.current{
}
In last line of your CSS, add #menu li:hover to target selectors
Updated example here: http://jsfiddle.net/7UaNn/
Add this #menu li:hover > a in the following css
#menu a:hover, #menu > li a.current {
// your Style
}
So it should look like this:
#menu a:hover, #menu > li a.current, #menu li:hover > a {
// your Style
}
See Demo: http://jsfiddle.net/akhurshid/bk2HA/7/
At the moment all you hoverstyles for the listitem are applied to the a- Element.
However, you need to apply them to the li-Element to keep the hover state active.
Sometimes that may become tricky, but in your case it's pretty easy, just add:
#menu > li:hover{
background:#474747;
}
to your styles.
See your modified fiddle
Along with "a" also add hover for "li" :
#menu > li:hover{
background:#474747;
}
You may achieve this by hooking up to the :hover state of the parent li element instead of the anchor element - which is a children of the list-item that is actually hovered - like so:
li a:hover,
li:hover > a {
color: #fff;
}
You might need to use :nth-child() to get around every sublink being in hover state. Did not test this.
/edit: updated the selector, now using > a to only select the direct child anchor element of the hovered list element, no need for :nth-child or the like.
Make the thing that is changed on hover the background of the LI rather than the background of the 'a'.
ul#menu li:hover { background:#000; }