這是解決此簡單請求的正確方法嗎?使用'text'類型的表單輸入具有灰色背景
輸入[類型=「文本」] {背景:灰色;}
當我刷新我的HTML,即我靶向不改變輸入框。
下面是HTML標記:
<input type="text" name="name" />
我在做什麼錯?
這是解決此簡單請求的正確方法嗎?使用'text'類型的表單輸入具有灰色背景
輸入[類型=「文本」] {背景:灰色;}
當我刷新我的HTML,即我靶向不改變輸入框。
下面是HTML標記:
<input type="text" name="name" />
我在做什麼錯?
你只需要刪除內input
input[type="text"] {
background: gray;
}
input
否則後包含的樣式應用於[type="text"]
空間的額外信息
<a href="#" class="button">Text</a>
錨元素中的位上面有一類.button,以便讓文本變紅,你需要下面的內容翼:
a.button {
//No space
color: red;
}
如果你現在添加a
和.button
選擇,這將不再工作,因爲你基本上說之間的空間「望a
元素中的.button
」。
a .button {
//Space
color: red;
}
但是下面會工作,因爲.button
現在嵌套在a
元素中。
<a href="#"><span class="button">Text</span></a>
我還通過zfrisch附的jsfiddle: https://jsfiddle.net/0kcvb3d6/
好的答案!這只是一個小提琴,因爲https://jsfiddle.net/0kcvb3d6/ – zfrisch
下面是一些詳細的例子。
<!DOCTYPE html>
<html>
<head>
<style>
input[type=text] {
width: 200px;
display: block;
margin-top: 10px;
margin-bottom: 10px;
background-color: gray;
color: white;
}
input[type=button] {
width: 120px;
margin-left: 80px;
display: block;
}
</style>
</head>
<body>
<form name="input" action="" method="post">
Name:
<input type="text" name="Name" value="Your Name" size="20">
<input type="button" value="Submit">
</form>
</body>
</html>
注:輸入標籤沒有在HTML中結束斜槓。這不是一個錯誤,但它不是必需的,被瀏覽器忽略,並且沒有在HTML文檔中調用。 – Rob