CSS - display:none on hover self - html

I am trying to create an effect where if a user hovers over an element, the element disappears. I have tried the code below, but it seems that the display:none; breaks the CSS. I am wondering why my CSS does not work, and how I would solve my problem.
http://jsfiddle.net/2c42U/
<div class="foo">text</div>
.foo:hover {
color: red;
display: none;
}

Try changing the element's opacity instead: http://jsfiddle.net/XtmVQ/
.foo:hover {
opacity:0;
}

try this instead of display:none
visibility:hidden

Try this:
.foo:hover {
opacity: 0;
}
What is your final intent for this?

as #Richard said, use opacity
also, to be backwards ie, do as follows:
filter:alpha(opacity=0); /* For IE8 and earlier */
and you can also add a transition:
transition: 0.5s
so that it is not instant.

You can do what the others suggested, use opacity: 0; or visibility:hidden;, but if you must have it hidden from the flow of the page. Then do the following:
Use a CSS like this:
.hidden{
display: none !important;
}
You can use the class hidden and apply it to any element to hide it. For the hover behaviour you want, you'll require JavaScript/jQuery to apply the class name. See http://jsfiddle.net/rkH7F/

i think css will not work. use jquery
UPDATE
ohh, my bad. css will work but the jquery will have a better effect
$('#outer').mouseenter(function() {
$("#outer").hide();
}); $('#outer').mouseleave(function() {
$("#outer").show();
});
FIXED
$('#outer').mouseenter(function() {
$("#outer").slideUp();
}); $('#outer').mouseleave(function() {
$("#outer").slideDown();
});

Related

Unhide <img> on :hover

Is it possible to have an image hidden by default and unhide it on :hover? I tried using the visibility property, but invisible elements can't be hovered on.
If you use display or visibility, the element is not there so you can't hover over it. Try it with opacity:0; . You can do it with css:
.img { opacity:0; }
.img:hover { opacity:1; }
I realize that you specifically asked about jquery, but it is possible to do what you're asking just with css, though you may have to use opacity:0 rather than display:none to hide the image.
You can use a css hover event. Start by applying a class to your image:
<img src="theimage.jpg" class="hidden-image"/>
In your css, you can then use the class and a css hover event to show the image when the cursor is over the image:
.hidden-image {
opacity: 0;
}
.hidden-image:hover {
opacity:1;
}
Here's a jsfiddle: http://jsfiddle.net/fZd7J/
Directly you can't mouseover/hover a hidden image that is, its not possible with visibility:hidden; or display:none;, but you can have some tricks to do that.
using css
apply opacity: 0; to the image and :hover change opacity:1;
using js
create a parent <div> to the image and mouseover to that div apply display:block; to image.
Working Fiddle Click here

Issue with visibility: hidden; and transition in HTML

HTML:
<link rel="stylesheet" type="text/css" href="s.css"/>
<div id="xd"><ul>a</ul></div>
CSS:
#xd ul {
visibility: hidden;
transition: all 1s;
}
Under Chrome 27, the "a" appears for 1 second and then dissapears. How can this happen with visibility: hidden; ?
Please expain why this happens.
Thank you.
There is a difference between visability:hidden and display:none in CSS. For what you want, I would do something like this instead to mitigate your issue:
CSS:
#xd ul {
display: none;
transition: all 1s ease-in-out;
}
HTML:
<ul id="xd"><ul><li>a</li></ul></ul>
For an explanation of the difference between the two, here is a link with more info: http://www.w3schools.com/css/css_display_visibility.asp
Essentially, to paraphrase the above link, visability:hidden preserves the space around the element and will still affect the rest of the layout, whereas display:none does not affect the rest of the layout and works as if the element is completely removed from the page. So, there may be a quirk in Chrome which displays the visability:hidden element first before it is hidden because of that.
JSFiddle example: http://jsfiddle.net/JKA8z/

HTML Disabled Button getting :active CSS Pseudo Class

CSS:
button:active {
/* active css */
}
button:disabled {
opacity: 0.5;
}
HTML:
<button disabled="disabled">Ok</button>
When I click the button the browser adds the button:active state making it look like it was clicked (even though it is disabled). I swear I thought :active was only added if the button was enabled. What have I missed?
From what I can tell, :active doesn't exclude :disabled elements. You can read the spec if you'd like.
To solve your problem, you could exclude :disabled elements by targeting only :enabled elements with your :active selector:
button:enabled:active {
/* active css */
}
button:disabled {
opacity: 0.5;
}
Demo: http://jsfiddle.net/Blender/LRvra/1/
According to the CSS3 specification (:disabled is not in CSS2.1) there is no mention that :active and :disabled are mutually exclusive. It's possible that this part of the specification needs clarification so UAs are free to apply the pseudo-classes in combination.
I suggest you modify your selectors to be more explicit:
button:enabled:active {
/* active css */
}
button:disabled {
opacity: 0.5;
}
You could also use the :not()-descriptor of css:
button:active:not(:disabled) {
/* active css */
}
button:disabled {
opacity: 0.5;
}
Wish y'all the best, Patric

How to remove dotted border around the link in IE7

There is border around button and link when click.
How can I remove it?
You can preset it like that :
:focus{
outline:0; /*removes the dotted border*/
}
But remember (for accessibility reasons) to set the style "later" in your CSS file to something more visible. For example :
a:focus, a:active{
color:#ff5500; /*different color than regular*/
}
input[type=submit]:focus, input[type=submit]:active{
background-color:#444; /*different color than regular*/
}
Try this one
a:hover, a:active, a:focus {
outline: 0;
}
It's ugly, but so are most IE fixes.
a:focus, *:focus {
noFocusLine: expression(this.onFocus=this.blur());
}
To start with, I can see one of your tags is IE7-bug, while this is actually more like a feature. The purpose of having this dotted outline is for users to be able to navigate between various controls using their mousewheel or the tab key.
In any case, to define the style of an element when it's "focused" use the CSS :focus selector. The property that styles this outline is, trivially, outline; outline: 0 will prevent the focus outline from appearing.
Note: You might want to apply that rule only on your button, and not on all elements, because some users might be used to seeing something to indicate focus, which makes it easier to navigate using the methods mentioned above.
Hope that helped in any manner.
CSS outline is not supported in IE7. That "browser" requires the following CSS expression:
a {
_noFocusLine: expression(this.hideFocus=true);
}
It works also in newer versions.
This would do the trick
a {
outline:0;
}
This will also work
a
{
outline-style:none;
}
a:link{
outline-style: none;
}`
Try setting the outline property:
a {
outline: 0;
}
Try
a {
outline: none;
}
Always try to use css reset.This will help you to solve the problem like this.I use eric mayer css reset tool.
Apply this rule to the input
input { outline : none ; }
This is all around code to remove outerline and put in your your CSS under the desired class name (className in IE). Example for <a> tags
a{
_noFocusLine:expression(this.hideFocus=true);
outline-style:none;
outline:0;
}
Example for all tags in your html page!
*{
_noFocusLine:expression(this.hideFocus=true);
outline-style:none;
outline:0;
}
Example for a tag with class myClassName in your html page!
.myClassName{
_noFocusLine:expression(this.hideFocus=true);
outline-style:none;
outline:0;
}
Example for a tag with id myidName in your html page!
#myidName{
_noFocusLine:expression(this.hideFocus=true);
outline-style:none;
outline:0;
}
Works in major browsers and if not they are so old so the chance of how many people there still are using this old browsers!
Notes: outline:none 0; does also work in newer browsers but not in all. But outline:0; is universal and in those browsers there don´t understand 'none' and you get there's default value, but 0 understand in all browsers there are using outline:.
And you need this for IE7: _noFocusLine:expression(this.hideFocus=true);
or use JavaScript for the rest!
window.document.getElementById("myidName").blur();
window.document.getElementById("myidName").hideFocus=true;
window.document.getElementById("myidName").style.outline=0;
or
Obj=window.document.getElementById("myidName");
Obj.blur();
Obj.hideFocus=true;
Obj.style.outline=0;
or with check if element exist:
if (window.document.getElementById("myidName")){
Obj=window.document.getElementById("myidName");
Obj.blur();
Obj.hideFocus=true;
Obj.style.outline=0;
}
JavaScript can do the trick for IE6 and IE7 and other CSS can't.
You can do it with this code:
a:focus{
border: none;
}

how to hide the content of the div in css

I have this html code
<div id="mybox"> aaaaaaa </div>
and this is my css
#mybox{
background-color:green;
}
#mybox:hover{
background-color:red;
}
the question is how to hide the content of the div (aaaaaaa) when the mouse hover event by using css only and without changing the structure of the code
I think I should put some code under #mybox:hover but I don't know the code.
Without changing the markup or using JavaScript, you'd pretty much have to alter the text color as knut mentions, or set text-indent: -1000em;
IE6 will not read the :hover selector on anything other than an anchor element, so you will have to use something like Dean Edwards' IE7.
Really though, you're better off putting the text in some kind of element (like p or span or a) and setting that to display: none; on hover.
Here is the simplest way to do it with CSS3:
#mybox:hover {
color: transparent;
}
regardless of the container color you can make the text color transparent on hover.
http://caniuse.com/#feat=css3-colors
Cheers! :)
Hiding through CSS is achieved by using either the "visibility" or the "display" attributes. Though both achieve similar results, it's useful to know the differences.
If you only want to hide the element but retain the space occupied by it, you should use:
#mybox:hover {
visibility: hidden;
}
If you want to hide the element and remove the space occupied by it, so that other elements can take its space, then you should use:
#mybox:hover {
display: none;
}
Also remember that IE6 and below do not respond to :hover for anything except A tags. In which case, you'll need some Javascript to change the classname:
document.getElementById('mybox').className = 'hide';
and define the "hide" class in CSS:
.hide { display: none; }
sounds silly but font-size:0; might just work. It did for me. And you can easily override this with the child element you need to show.
You could make the text color the same as the background color:
#mybox:hover
{
background-color: red;
color: red;
}
What about opacity
#mybox:hover {
opacity: 0;
}
Best way to hide in html/css using display:none;
Example
<div id="divSample" class="hideClass">hi..</div>
<style>
.hideClass
{display:none;}
</style>
This is a late answer but still, guess setting the color to transparent is the best option.
#mybox:hover{
background-color:red;
}
There are many ways to do it:
One way:
#mybox:hover {
display:none;
}
Another way:
#mybox:hover {
visibility: hidden;
}
Or you could just do:
#mybox:hover {
background:transparent;
color:transparent;
}
#mybox:hover { display: none; }
#mybox:hover { visibility: hidden; }
#mybox:hover { background: none; }
#mybox:hover { color: green; }
though it should be noted that IE6 and below wont listen to the hover when it's not on an A tag. For that you have to incorporate JavaScript to add a class to the div during the hover.
I would say:
#mybox{
background:green;
}
#mybox:hover{
color:transparent;
}
<div id="mybox">
This text will disappear on hover
</div>
This will hide text, but of course, it still contains the text, but it is a tricky way to hide the text (make in invisible), but it will work well
Sorry to be 7 years late but this could be achieved by using the below:
.your-block{
visibility: hidden;
width: 0px;
height: 0px;
}
This will keep the content on the page and won't occupy any space whereas display:none will completely hide the content.
Using the above code can be useful if you need to reference code in a div but don't need it to display.
.button {
width: 40px;
height: 40px;
font-size: 0;
background: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%20viewBox%3D%221284%20207%2024%2024%22%3E%3Cg%20fill%3D%22none%22%3E%3Cpath%20d%3D%22M1298.5%20222.9C1297.5%20223.6%201296.3%20224%201295%20224%201291.7%20224%201289%20221.3%201289%20218%201289%20214.7%201291.7%20212%201295%20212%201298.3%20212%201301%20214.7%201301%20218%201301%20219.3%201300.6%20220.5%201299.9%20221.5L1302.7%20224.2C1303%20224.6%201303.1%20225.3%201302.7%20225.7%201302.3%20226%201301.6%20226%201301.2%20225.7L1298.5%20222.9ZM1295%20222C1297.2%20222%201299%20220.2%201299%20218%201299%20215.8%201297.2%20214%201295%20214%201292.8%20214%201291%20215.8%201291%20218%201291%20220.2%201292.8%20222%201295%20222Z%22%20fill%3D%22%239299A6%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E") #f0f2f5 no-repeat 50%;
}
<button class="button">Поиск</button>