I wanted to replace text on hover with css and though it didn't work, Google chrome ignored the entire :hover pseudo-class, while Mozilla firefox safely ignored content and continued to run the rest of the events
Html:
<li id="menuDebating">Debating</li>
Css:
#menuDebating a:hover{
content: "Public Speaking" !important;
color:red;
}
Fiddle: http://jsfiddle.net/FSyAv/
However I have read the css3 declaration and I know that content should not work for :hover, which isn't a big deal since implementation is easy with javascript.
But, I then looked at it further and tried using the a:hover::before psuedo-class and that's where it gets really strange
Html:
<li id="menuDebating">Debating</li>
Css:
#menuDebating a:hover::before{
content: "Public Speaking" !important;
color:red;
}
Fiddle: http://jsfiddle.net/FSyAv/1/
In Chrome, it flickers non-stop, Safari flickers, then stops for while and continues flickering, while Mozilla and Opera runs the event as intended
content can only be used with pseudo elements (before and after).
You can force it to "overwrite" the original word by setting its position to absolute:
Demo
ul li {
position:relative;
}
#menuDebating a:hover:before{
position:absolute;
top:0; left:0; right:0; bottom:0;
content: "Public Speaking";
color:red;
background:#FFF;
}
Related
I am implementing a close button on an element containing text with CSS. The close button is generated content from a pseudo element with content:'X';. I need the cursor to become a pointer on that "X" so I used :
cursor:pointer;
It works fine in Chrome and Firefox but it doesn't seem to work in Internet Explorer (testing on IE11 windows 7).
DEMO (test in IE)
I also tried with cursor:hand; but it doesn't solve the issue. How can I make the cursor a pointer while hovering the "X" but not on the text of the div?
Relevant code :
div{
font-size:2em;
position:relative;
display:inline-block;
}
div::before{
content:'X';
cursor:pointer;
display:block;
text-align:right;
}
<div>some text</div>
--EDIT--
I am aware that making a child or sibling in the markup and applying cursor:pointer; to it will work but I would like to minimize markup and use a pseudo element for the close button as it has no semantic value.
I'm really late to the game, but I just now figured out a solution to this problem.
This solution allows a pointer on the child element, while retaining a default cursor on the parent element.
(See the accepted answer here for a solution that doesn't include keeping the parent element's cursor default: cursor: pointer doesn't work on :after element?)
First of all, for this hacky solution, you have to give up the ability to interact with the parent element using the mouse.
Set the parent element to cursor: pointer.
Then, setting the parent element to pointer-events: none will allow you to "click/hover through" the parent element.
Then, for the pseudo element, just re-enable pointer events with pointer-events: auto.
Voila!
div{
font-size:2em;
position:relative;
display:inline-block;
/* remove ability to interact with parent element */
pointer-events: none;
/* apply pointer cursor to parent element */
cursor:pointer;
/* make it more obvious which is child and which parent for example*/
background: darkred;
}
div::before{
content:'X';
display:block;
text-align:right;
/* restore ability to interact with child element */
pointer-events: auto;
/* make it more obvious which is child and which parent for example*/
width: 30px;
text-align: center;
background: white;
}
<div>some text</div>
I believe that it's not working in pseudo elements in IE,
What I'm use to do is add cursor: ponter to main element.
If you need to add cursor: pointer to pseudo element only, than only way is to add child element
like:
<div><span></span>some text</div>
div{
font-size:2em;
position:relative;
display:inline-block;
}
div > span{
cursor:pointer;
}
div > span::before{
content:'X';
display:block;
text-align:right;
}
But than is no point to using pseudo class...
demo
HTML:
<div>
<div id="closebutton">
X
</div>
some text
</div>
css:
div{
font-size:2em;
position:relative;
display:inline-block;
}
div#closebutton{
cursor:pointer;
display:block;
text-align:right;
}
DEMO
demo
div{
font-size:2em;
position:relative;
display:inline-block;
border:1px solid #000;
margin:20px;
padding:20px;
}
div:after{
cursor:pointer;
display:block;
position:absolute;
height:20px;
width:20px;
top:-10px;
right:-10px;
content:'X';
font-size:15px;
}
<div>
some text
</div>
In order to make IE 7,8,9,10 behave like regular browsers that can deal with pseudo selectors, I always use IE7.js, a JavaScript library to make Microsoft Internet Explorer behave like a standards-compliant browser. It fixes many HTML and CSS issues related to Internet Explorer. An alternative would be modernizr.js which is a good implementation to get pseudo selectors working with IE. I hope, that helps.
I'm having an issue with IE8 where when an image is clicked inside of a link, the :active selector is not being triggered by IE.
Example:
HTML:
<img src="http://www.w3schools.com/images/pulpit.jpg">
CSS:
a {
display:inline-block;
padding:10px;
border:1px solid #F00;
}
a:hover {
border-color:#0F0;
}
a:active {
border-color:#00F;
}
Live demo: jsFiddle
When clicking the area around the image, the link acts normally, but when clicking the image itself, it fails to update.
Any ideas on why this is happening and if there are any workarounds? Since it is mostly working I don't mind appending some JavaScript if needed.
It may work better if you put the states on the img, but I can't get rid of the outline. http://jsfiddle.net/wSp7J/3/
I'm starting to use the :before pseudo element to display logos before anchor text in a list.
I've followed Nicolas Gallagher's instructions, but the background images are not displaying in IE8. Works in other browsers. Anyone see what I might be doing wrong?
I've posted the example here:
http://vervedesignstudios.com/gb/testBefore.html
Here is the markup:
Thanks in advance for your advice.
<style>
/* Pseudo-element cropping bit */
.iLst24 li a:before {
content:"";
float:left;
width:24px;
height:24px;
margin:0 6px 0 0;
background-image:url("images/HomeSprite.png");
}
.iLst24 .fb a:before {background-position:0 0;}
.iLst24 .tw a:before {background-position:0 -50px;}
.iLst24 .yt a:before {background-position:0 -100px;}
</style>
<div class="iLst24">
<ul>
<li class="fb">Facebook</li>
<li class="tw">Twitter</li>
<li class="yt">YouTube</li>
</ul>
</div>
IE8 has multiple issues with float and specific width/height values on tags. Try adding a "zoom:1" to trigger haslayout and see if that helps.
I got one strange problem which I never got before. Please see this code:
The css:
#btn{
margin-left:150px;
padding:10px;
display:block;
}
#btn a{
padding:5px 20px;
background:green;
color:#FFF;
text-decoration:none;
outline:none;
}
#btn a:hover{
background:#933;
}
#btn a:focus, #btn a:active{
background:#CF0;
color:#000;
}
Here the HTML
<div id="btn">
Click here
</div>
The focus and active css working well in firefox, but not in the chrome and safari.
Yeah seems like little problem with focus in webkit. Not really a bug. Easily fixable in html. Just use tabindex.
[hide]
[show]
ta da ...
This is also the case for Webkit based 'focus' events, it doesn't take. The fix is to put a tabindex="0" attribute on the A and then it receives the focus event. You might also want to have at least a "#" as the href just in case.
It's fixable, some additional code needed though...
<div id="btn">
Click here
</div>
jsfiddle
I know it's ridiculous... You can read more here
Hope this helps
The solution posted by user1040252 did the trick for me.
I have a div with images that sets an image in a span tag to visible on a click.
Firefox ignores the classname:focus in my CSS file.
<div class="thumbnail_frame">
<img src="pictures\\figures\\thumbs\\image_1.JPG"/>
<span>
<img src="pictures\\figures\\image_1.JPG"/>
</span>
</div>
My CSS (part of it):
.thumbnail_frame:focus span{visibility: visible;}
//...
.thumbnail_frame span
{
visibility: hidden;
position: fixed;
top: 20px;
left: 20px
}
But this only worked in Internet Exporer 9. Firefox 12 kept ignoring the focus also in other simple examples like found here:
explanation:
http://de.selfhtml.org/css/eigenschaften/pseudoformate.htm
try it:
http://de.selfhtml.org/css/eigenschaften/anzeige/pseudo_links.htm
But adding tabindex="0", as in
<div tabindex="0" class="thumbnail_frame">
<img src="pictures\\figures\\thumbs\\image_1.JPG"/>
<span>
<img src="pictures\\figures\\image_1.JPG"/>
</span>
</div>
works like a charm. One click opens the hidden span, and the second one closes it very neatly.
Use tabindex="0" to make an element focusable if it is not already. See https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex for more information about tabindex.
Setting tabindex to -1 makes it unfocusable. Setting tabindex to a positive integer is not recommended unless you're trying to explicitly set the tab order, as it can create accessibility issues.
For more information about tabindex and accessibility, see https://webaim.org/techniques/keyboard/tabindex.
You should know that the pseudo class :focus doesn't go with A. The A tag has 4 pseudo classes : :link, :hover, :active, :visited
i am trying to make a CSS menu for my webpage for school. I have been developing my site on a Mac and have got it working just the way i want it. I have tested it in safari, firefox and chrome as well as firefox on windows, all of these work fine, i hover over the links menu and it drops down.
css for menu
#menu
{
position:relative;
top:-83px;
left:60%;
font-size:30px;
width:250px;
}
#menu ul
{
position:absolute;
list-style-type:none;
background-image:url('../images/linkBG.png');
background-repeat:no-repeat;
background-position: 38px 0px;
width:250px;
}
#menu li ul
{
display:none;
list-style-type:none;
background-image:url('../images/menuBG.png');
background-repeat:repeat-y;
font-size:20px;
}
#menu a:link {color:rgb(255,0,0);}
#menu a:visited {color:rgb(255,255,0);}
#menu a:hover {color:rgb(255,0,255)}
#menu a:active {color:rgb(255,255,255);}
#menu li:hover > ul
{
display: block;
}
#menu li ul li
{
padding-left:0px;
padding-top:10px;
padding-bottom:10px;
}
When trying it on IE (ver6 and ver8) the links menu repositions it self (moves up about 50px and overlaps the heading), the background image gets moved across to the right by about 30px, and the menu no longer drops down when the mouse hovers over the text. I have heard of IE being a pain to develop for but this is just stupid. I have seen one solution that involved a bit of script to work around the issue but i cannot use script as this is for an assignment (which will be marked on a windows machine so there are high odds of it hitting IE). Along with the faulty menu is a table that i am centering using margin-left:auto and margin-right:auto once again it works fine in all browsers except IE. Is there any way i can get around this? is there an alternative to hover that will work on all browsers.
thanks.
html code for menu
<div id="menu">
<ul>
<li>Links Menu
<ul>
<li>Details</li><!--This may be #details-->
<li>Home town</li>
<li>My Course</li>
<li>Books, Music and Films</li>
<li>Timetable </li>
<li>Search</li>
</ul>
</li>
</ul>
</div>
Take a look at the margins and padding on your menu and the header above it. IE sometimes misinterprets them when objects bordering each other have both margins and padding. If you're able to replace your margins with more padding or different positioning, that might fix it.
Otherwise, the easiest way might to use IE conditional statements to give Explorer different versions of your CSS classes. I doubt they'd be considered script, but I don't honestly know. Example:
<!--[if IE]>
#menu {
/* different positioning for IE only */
top: ____;
left: ____;
}
<![endif]-->