vivek vivek - 3 months ago 10
CSS Question

Issue with background color of a button after vsited

Issue with background color of a button after vsited

https://jsfiddle.net/vivekraj_kr/wxokhpy4/

how to get a background color on button visited

<button type="button" class="size_btn">S</button>
<button type="button" class="size_btn">M</button>
<button type="button" class="size_btn">L</button>
<button type="button" class="size_btn">XL</button>



.size_btn {
height:27px;
width: 27px;
background: none;
border: solid 1px #ccc;
}

.size_btn:visited {
background-color: #479c3d;
}

Answer

Try working with <a> because <button> has nothing to do with :visited

a.button {
    height:27px;
    width: 27px;
    background: none;
    border: solid 1px #ccc;
    padding: 5px 8px;
    text-decoration: none;
    color: #444;
    font: 80% Arial, sans-serif;
    outline: none;
    background-color: white;
}

a.button:visited {
     background-color: red;   
}
<a href="#" class="button">S</a>
<a href="#" class="button">M</a>
<a href="#" class="button">L</a>
<a href="#" class="button">XL</a>

JSFiddle

Note: Google Chrome has an issue setting a:visited property. Check out more here and here.

Hope that helps.

Comments