2015-02-12 12 views
0

問題的一個按鈕的背景顏色按鈕的背景顏色後vsited問題與後vsited

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

如何獲得按鈕的背景顏色走訪

<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; 
} 

回答

1

嘗試<a>因爲<button>工作無關與: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

注:谷歌瀏覽器有問題設置a:visited財產。查看更多herehere

希望有幫助。

+0

是否有任何其他方式顯示選定的按鈕。 – vivek 2015-02-12 07:26:20

+0

@VIVEKRAJ你也可以添加一個類到選定的按鈕,並按照你想要的樣式。不過,我會爲此使用JavaScript/jQuery。 – balintpekker 2015-02-12 07:29:37

+0

Ohh kk thts fyn!謝謝你。 – vivek 2015-02-12 07:32:05

0

你可以試試這個: - S M L XL

<style> 



.size_btn { 
    height:27px; 
    width: 27px; 
    background: none; 
    border: solid 1px #ccc; 
} 
/* unvisited link */ 
.size_btn:link { 
    background-color: green; 
} 

/* visited link */ 
.size_btn:visited { 
    background-color: green; 
} 

/* mouse over link */ 
.size_btn:hover { 
    background-color: red; 
} 

/* selected link */ 
.size_btn:active { 
    background-color: yellow; 
} 
</style> 
1

在css :visited選擇器僅用於鏈接元素。因此,而不是:訪問您或者使用:活動選擇器。