User-select not working on a:visited - html

I'm working on a Math website, and it has some exercises on it with solutions on the bottom of the page. I want to make so solutions are hidden when the user scrolls by them, and needs to click on the block for it to show the answer. I want to achieve this using only css and html. Here's what I have made so far:
HTML:
<div class="solution s1">
2+2=4
</div>
CSS:
.solution {
width:80%;
margin:25px auto;
}
.solution a:visited{
color:black;
background-color:white;
user-select:text;
}
.solution a{
background-color:#49FF59;
display:block;
width:100%;
padding:25px;
text-align:center;
color:#49FF59;
text-decoration:none;
user-select: none;
}
This code works great, except for the user-select. I want it so that the user can't copy the solution, before the block is clicked on. But the a:visited won't apply the user-select:text; I have tried to add more classes, but i wasn't able too fix it. Keep in mind most of the CSS is for asterisk.

If I'm correct, the approach you're trying to take is to prevent someone from doing a select all and seeing the solutions on screen due to the text being highlighted.
If that's the case there are better style properties to use for this, particularly visibility or display.
For example you can use visibility: hidden or display: none to hide the solution until a specific condition is met.
I'd also advise against using :visited for something like this, unless you have specific urls for each question that you plan to override (if you use href='#') for everything, then once you click one, they are all 'visited'). You're going to also have struggles with browser caches when using :visited.
As an example, you could alter your container to be the clickable element, and hide your content using visibility, then show the answer on the :active state as opposed to the :visited state. This will show the answer while the mouse button is pressed. Under normal circumstances the text isn't selectable because it's hidden. If you want to keep it shown after a click but not use :visited you'll need a javascript solution.
Worth stating that this solution will not hide answers in the source code, but as you mentioned above that is not a concern for you.
.solution {
width:80%;
margin:25px auto;
background-color:#49FF59;
display:block;
width:100%;
padding:25px;
text-align:center;
}
.solution:active {
color:black;
background-color:white;
user-select:text;
}
.solution:active a {
color:black;
background-color:white;
visibility:visible;
}
.solution a{
text-align:center;
text-decoration:none;
visibility: hidden;
}
<div class="solution s1">
2+2=4
</div>

Related

CSS – link:hover color inheritance issue

I am really confused by what is happening here. I am wondering why the link is white when the cursor is within the button but NOT directly on the link? I want it to be red while cursor is within button boundaries.
I think that this happening is because at that point, the page is inheriting from the declared .links:a color value, but I am wondering how do I get it to override that? The .links:hover doesn't seem to transfer inheritance to .links a:hover (?)
Any help would be greatly appreciated!!
.links a{
color:white;
text-decoration:none;
}
.links:hover{
background-color:white;
color:red;
}
.links a:hover{
background-color:white;
color:red;
}
https://jsfiddle.net/3dujymLk/1/
Your rules are working exactly the way you wrote them. If you want the a text to be red while hovering over the entire div, you need a rule for that. Add something like this:
.links:hover a {
color: red;
}
If it isn't obvious, this controls the text-color of the link while hovering over the div.

Show "Accessible" button on tab

I am trying to show a button to access Accessibility options on the top of the page - normally hidden - when the user tabs to them.
HTML:
Accessbility Options
Style:
.access {display:none; position:fixed; top:0; left:0; padding:10px; font-size:25px; background:#eaeaea;}
.access:focus {display:block;}
However when you use the tab button once the page has first loaded, nothing shows. I have tried using :hover rather than focus etc; but I am struggling to find similar answers which handle it without any jQuery / over complicate it.
Instead of
display:none;
you could use
.access {opacity:0; position:fixed; top:0; left:0; padding:10px; font-size:25px; background:#eaeaea;}
.access:focus {opacity:1;}
Something with display:none will not be given an actual tabindex.
An Element with
display: none;
is not able to get focus!
You have to use another way to get the element invisible.
For example positioning it outside of the page, or opacity (note that it is clickable even if it is not visible).
Try using display: hidden or look into this question for a JavaScript solution

CSS Sibling Selector Alternative

I'm trying to cause one element to change when another element is hovered. I know this can be done using the sibling selector (~) but it doesn't seem to be working. I tried to find an alternative to using the sibling selector but only found solutions in javascript which I don't know.
I think the problem may come from the fact that I'm trying to tie multiple elements to one sibling, that is to say, hovering over 3 different divs all change one div in three different ways. I don't think there's a mistake though I could be wrong, the code is here...
CSS
#internalContainer {
width:900px;
height:400px;
}
#sectionLeft {
float:left;
height:400px;
width:300px;
}
.leftInternal {
height:100px;
width:300px;
text-align:right;
}
#titleA {
font-size:11pt;
font-weight: bold;
text-transform: uppercase;
letter-spacing:1px;
position:relative;
top:40%;
transition:.2s
}
#sectionRight {
float:left;
width:568px;
height:400px;
margin-left:32px;
background-color:#f2f2f2;
}
#titleA:hover {
top:45%;
transition:.2s
}
#titleA:hover ~ #sectionRight {
background: #ccc;
}
HTML
<div id="internalContainer">
<div id="sectionLeft">
<div class="leftInternal"><div id="titleA">Title of One</div></div>
<div class="leftInternal"><div id="titleA">Title of Two</div></div>
<div class="leftInternal"><div id="titleA">Title of Three</div></div>
<div class="leftInternal"><div id="titleA">Title of Four</div></div>
</div>
<div id="sectionRight">
</div>
</div>
http://jsfiddle.net/xs7h8/
Currently nothing changes when the links are hovered but they're all set to do the same thing right now. I was going to make subclasses for titleA and connect each to the sectionRight but that didn't work either.
You cannot have duplicate IDs. It simply won't work. That is your problem
Also, the #titleAs are not siblings of #sectionRight so the sibling selector will not work. #sectionRight is an uncle to them and, since there is no parent selector at the moment, there is no way to select it using CSS on hover
You also don't need to repeat the transition in the hover, it is inherited from the default state
This is the closest you can get using your current setup and no javascript, applying the hover to #sectionLeft instead

Anchor tag background changes after a:hover but not stays after visiting link

I'm using anchor tag as a menu item in my web page. I used css for designing anchor tag like a menu look. I have three anchor tag on my page.
my css design in as follows-
div.menu
{
margin:0px;
height:30px;
background-color:Gray;
}
span.menu a:link
{
display:inline-block;
font-weight:bold;
color:#0000CC;
background-color:#E8EEFD;
text-align:center;
padding:4px;
text-decoration:none;
width:70px;
padding:5px;
margin:0px;
}
span.menu a:visited
{
display:inline-block;
font-weight:bold;
color:#0000CC;
background-color:#D3D5EB;
text-align:center;
padding:4px;
text-decoration:none;
width:70px;
padding:5px;
margin:0px;
}
span.menu a:hover
{
background-color:#D3D5EB;
}
above is my css design for anchor tag. I want to change the background color after clicking on the tag & color should stay up to the next selection of the menu item. I have tried throw above css. but it shows me the same background color after setting :visited style too.
When i run my page that time it is initially showing me the visited color & not the link color.
How to solve this?
thanks.
You can't do it with :visited. It applies to all links that you previously opened, not only clicked.
For example: If you target http://google.com in you link, then if browser rememver you ever visiting google.com in the past, it will apply :visited styles to the link. (Even if you never clicked this particular link)
To indicate selected item in menu you will need to apply another class to it as suggested above. For example make class "current" and apply it to the current link.
You'll have to set or swap style classes using JavaScript to achieve this. Here's an example in jQuery (http://api.jquery.com/toggleClass/) and you can also use plain JavaScript.
document.getElementById("MyElement").className += " MyClass";

CSS - :hover is slow/laggy in IE7

This is really strange. I've got this site where I have a list menu with a simple :hover effect on each item in the menu.
http://w3box.com/mat/
In Firefox it works just fine. But i IE7 atleast there's a lag. I haven't tested it in IE8 but my guess is that it's there as well.
Now, I've been trying out veriations to the code to see what might cause the issue. And I've seen alot of posts about similar scenarios. But none of them seemed to apply to my case.
So just now I noticed that in my css stylesheet, I've got this:
li:hover {
background-image: url(img/TopLine.png);
Height:29px;
}
Strange enough, if I remove the height specifications, there is no lag! What could be causing this? Could it be layers of padding and margins to the parent li class? Or the parent class above that one?
This is the code of these items. The rest of the css you can under /main.css of the site
#header {
padding-right:7%;
height: 57px;
background-image:url(img/TopLine.png); }
.header a {
font-family:georgia;
font-size:22px;
color:#ebebeb;
text-decoration:none; }
.header li {
float:right;
list-style: none;
margin-top:10px;
padding-top:18px;
padding-left: 23px;
padding-right: 23px;
height:23px; }
li:hover {
background-image: url(img/TopLine.png);
Height:29px; }
Any ideas on how I can improve this?
I'm not really getting any lag. The first time there is a slight delay though - this is most likely because the background image is loading.
You'd be better off setting a background on the list item proper then changing the background position on hover. (There are plenty of questions on SO about this.)