html - 为什么我的 CSS 样式会覆盖我的内联样式?

标签 html css

我的 <input type=image>内联宽度/高度被我的 input 覆盖了样式。有没有办法纠正这个问题?还是内联样式在这种情况下不起作用?

HTML:

<form id="search" name="search" form method="get" action="find_search.php">
    <input type=  "text" name=     "q" value=""  />
    <input type="hidden" name=   "cat" value=""  />
    <input type="hidden" name=  "time" value="0" />
    <input type="hidden" name="letter" value=""  />
    <input type="hidden" name="offset" value="0" />
    <input type="hidden" name=  "type" value="quick" />
    <input type= "image" src="images/search_button.png" value="Search" width="200" height="50" />
</form>

CSS:

input {
   width:50%;
   padding:0px;
   outline:none;
   height:36px;
   font-size:24px;
}

最佳答案

您可以使用更具体的 CSS 选择器(例如 input[type=text])来完成此操作和 input[type=image] .因此,如果您希望问题中指定的高度/宽度仅适用于 <input type="text"> ,你会做这样的事情:

将非高度/宽度属性保留在不太具体的 input 中选择器:

input {
   padding:0px;
   outline:none;
   font-size:24px;
}

然后使用 input[type=text] 中的高度/宽度属性选择器:

input[type=text] {
   width:50%;
   height:36px;
}

然后您可以为 input[type=image] 添加不同的高度/宽度选择器:

input[type=image] {
   width: 200px;
   height: 50px;
}

此外,请记住,如果使用 id,您可以使选择器更加具体。的 form在你的选择器中,像这样:

  • #search input
  • #search input[type=text]
  • #search input[type=image]

关于html - 为什么我的 CSS 样式会覆盖我的内联样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14965453/

相关文章:

php - 右上角标题内容上的登录表单

html - 什么是 CSS 聚合?

css - 如何在没有伪元素的情况下使用css添加文本

html - tbody before thead 有效吗

javascript - 将字符串文本替换为 HTML

javascript - IE 中的选择箭头下拉列表不同

javascript - 从下拉多个选中的复选框中获取多个值

html - h3 元素未正确填充带有水平滚动条的 div

css - 我如何将一个div置于父div之上?

php - div样式高度不起作用