【问题标题】:CSS: size property in class for input tagsCSS:输入标签的类中的大小属性
【发布时间】:2017-10-18 05:13:59
【问题描述】:

我有以下代码:

<!doctype html>
<html>
<head>
  <title>Rich Home</title>  
  <meta charset="utf-8"> 
  <style>
    body { background-color: Black; color: White; }
    h1 {text-align: center}
    .st{ color: Green; background-color: Yellow; size: "80"; type:"text" }
  </style>    
</head>

<body>
  <h1>Rich's Home Page</h1>
  <form action="https://google.com/search" method="get">
    Google: <input class=st name="q" autofocus>
    <input type="submit" value="=>">
  </form>
  <form action="https://duckduckgo.com" method="get">
    Duck: <input class=st name="q">
    <input type="submit" value="=>">
  </form>  
</body>
</html>

我在 Firefox、Chrome 和 Chromium 中打开过。 color 和 background-color 应用于两个输入框,但 size 不是。这是为什么呢?

编辑以响应各种答案 cmets。改为使用以下行无效:

.st{ color: Green; background-color: Yellow; width: "600px"; type:"text" } 

【问题讨论】:

  • 您需要在值之后指定 px - 目前它正在达到 80 并且就像“很棒 - 80 什么?”所以它什么都不做
  • @ThisGuyHasTwoThumbs 我尝试将大小更改为“400px”,但没有效果。
  • 然后尝试使用宽度 - 在 css 中几乎不使用尺寸 - 更多的是 html 属性..
  • @RichOliver 将 "600px" 更改为简单的 600px(无引号)。
  • @HiddenHobbes 做到了。在发布带引号和不带引号的问题和大小之前,我尝试过宽度,但没有引号的宽度。

标签: css html-input


【解决方案1】:

勾选此项,您可以简单地为其他文本类型定义类,例如“input[type="number"]”

input[type="text"] {
  display: block;
  margin: 0;
  width: 60%;
  font-family: sans-serif;
  font-size: 25px;
  appearance: none;
  box-shadow: none;
  border-radius: 5px;
}
input[type="text"]:focus {
  outline: none;
}
&lt;input type="text" placeholder="name" /&gt;

【讨论】:

    【解决方案2】:

    CSS 中不存在“size”属性, 你必须指定width and height .st{ color: Green; background-color: Yellow; width: 80px; type:"text" }

    应该可以。

    【讨论】:

    • 不正确 - 尺寸存在但不是标准的,因为它几乎不工作.. 但它确实存在
    【解决方案3】:

    CSS 中没有“大小”属性。它是标签属性。 如果您想使用 CSS 指定元素的宽度或高度 - 使用:

    .st {
        width: 80px;
    }
    

    而且您不能使用 CSS 设置元素类型。改为设置属性:

    <input class=st name="q" type="text" autofocus>
    

    你也可以用属性指定宽度:

    <input class=st name="q" type="text" width="50" autofocus>
    

    【讨论】:

    • 不正确 - 尺寸存在但不是标准的,因为它几乎不工作.. 但它确实存在
    • 它是标准的,它是存在的。正如您在我的示例中看到的那样。但这完全取决于您如何将样式与结构分开。我建议不要使用“宽度”作为属性。
    • 这就是我所说的......你的第一行说“CSS中没有'大小'属性。”......
    猜你喜欢
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 2018-01-03
    相关资源
    最近更新 更多