2017-03-04 38 views
1

HTML代碼:我的心不是按鈕工作

<div id="but_2" class="button"> 
    <a href="portfolio.html">Portfolio</a> 
</div> 
<div id="but_1" class="button"><a href="index.html">Home</a></div> 

CSS代碼:

.button { 
    background-color: #ff0000; 
    border: none; 
    color: white; 
    padding: 15px 32px; 
    text-align: center; 
    text-decoration: none; 
    display: inline-block; 
    font-size: 16px; 
    margin: 4px 2px; 
    cursor: pointer; 
} 
#but_1 { 
    position: absolute; 
    right: 50px; 
    top:20px; 
} 

我的CSS按鈕不工作,它帶給我的地方我需要,但它是藍色的,並加下劃線(按鈕中的文字)我沒有文字裝飾,但它仍然沒有消失。

+1

*「的問題尋求幫助調試(」?爲什麼不是這個代碼工作「)必須包括所期望的行爲,一個具體問題或錯誤和在問題本身中重現它所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:如何創建[mcve]。「* –

+0

我們需要查看您的相關HTML。 –

+0

它應該工作..也許你沒有使用onclick方向,但是」a href「...然後嘗試:{text-decoration :none;} –

回答

0

針對a元素刪除下劃線並更改顏色。你可以用.button a {}

.button { 
 
    background-color: #ff0000; 
 
    border: none; 
 
    padding: 15px 32px; 
 
    text-align: center; 
 
    display: inline-block; 
 
    font-size: 16px; 
 
    margin: 4px 2px; 
 
    cursor: pointer; 
 
} 
 

 
#but_1 { 
 
    position: absolute; 
 
    right: 50px; 
 
    top: 20px; 
 
} 
 

 
.button a { 
 
    text-decoration: none; 
 
    color: white; 
 
}
<div id="but_2" class="button"><a href="portfolio.html">Portfolio</a> 
 
</div> 
 
<div id="but_1" class="button"><a href="index.html">Home</a></div>

+0

謝謝,但顏色仍然是藍色的,而且我花了最後半個小時查看了我寫的所有代碼,並且我確信沒有很多錯誤,我怎麼能擺脫? – Wiz

+0

@Wiz是否我的演示不適合你?鏈接是白色的。 –

+0

它努力擺脫下劃線,但我不得不改變它有點爲文本是白色的,在我的屏幕上我不得不使用6位數字的字母會變成白色,但是感謝下劃線,我自己也弄不清楚。 – Wiz

0

你需要更具體和目標href屬性瞄準它。

例如:

.button a { 
    text-decoration: none; 
    color: #000; 
} 

https://jsfiddle.net/xojev64e/

+0

好的,謝謝,我需要添加幾個字符,所以我只寫了這個 – Wiz

0
a {text-decoration: none; color:#FF0000;}  shows unvisited link 
a:visited {color:#FF0000;} shows visited link 
a:hover {color:#FF0000;} shows mouse over link 
a:active {color:#FF0000;} show selected link 

使用的所有屬性來定義你的顏色

0

我想你還沒有清除瀏覽器的瀏覽歷史記錄。首先清除歷史記錄,會話或cookie,然後執行以下步驟。下面給你的CSS文件

.button a { 
    text-decoration: none; 
    color: white; 
} 

並添加此爲吸引更多的鼠標懸停

.button a:hover { 
    text-decoration: none; 
    color: black; 
} 

希望這將幫助你.. :)

0

添加到您的CSS

添加:

/*Makes links in a button look like normal text*/ 
.button a[href]{ 
    color: black; 
    text-decoration: none; 
} 

您還可以擺脫<a>標籤,並添加到代碼:

<div class='button' onclick="window.location = 'url'">Text</div>