CSS 只是想给输入文本加粗字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5408292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:59:58  来源:igfitidea点击:

Just trying to give a bold font to an input text

cssinputstylesheet

提问by ziiweb

I'm trying to give a bold font to an input this way below but it doesn't work..

我试图在下面以这种方式为输入提供粗体字体,但它不起作用..

<html>
<head>

</head>

<body>

<style type=”text/css”>

.jander2{

  font-weight: bold;

}

</style>

<form method="post" action="somepage">
        <input id="jander" class="jander2">
</form>

</body>
</html>

回答by Czechnology

Your <style>should be in the <head>section:

<style>应该在以下<head>部分:

<html>
 <head>
  <style type="text/css">
   .jander2{
     font-weight: bold;
   }
 </style>
 </head>
 <body>
  <form method="post" action="somepage">
   <input id="jander" class="jander2">
  </form>
 </body>
</html>


EDIT:To satisfy the commenter: use only standard double quotes, no curly special quotes as you had in your <style>tag.

编辑:为了满足评论者的需求:只使用标准的双引号,不要使用<style>标签中的特殊卷曲引号。

回答by Fareesh Vijayarangam

This works:

这有效:

http://jsfiddle.net/4rAhy/

http://jsfiddle.net/4rAhy/

Code here:

代码在这里:

Inline style: <input type="text" style="font-weight: bold;"></input><br />
<style>
.jander2 {
    font-weight: bold;
}
</style> 
External Style: <input type="text" class="jander2"></input>

回答by Martha

Form controls are strange beasts. Some browsers don't let you style them at all, others only let you do a few limited things. Generally, this is because the browser gets the form controls from the operating system, rather than generating them itself.

表单控件是奇怪的野兽。有些浏览器根本不允许您设置样式,有些浏览器只允许您做一些有限的事情。通常,这是因为浏览器从操作系统获取表单控件,而不是自己生成它们。

That said, bold text should certainly be within the realm of attributes you can style. I think the problem is the curly quotes around "text/css" in your style declaration. (Putting the style declaration in the body can be a validation error depending on your doctype, but it should still work.)

也就是说,粗体文本当然应该在您可以设置样式的属性范围内。我认为问题在于样式声明中“text/css”周围的卷曲引号。(根据您的文档类型,将样式声明放入正文可能是一个验证错误,但它应该仍然有效。)

回答by Clark Superman

And if you want to cheat, then this is another solution:

如果你想作弊,那么这是另一种解决方案:

    <input type='text'  size='35' style='font-size: 16px;font-weight: bold;' value = 'Hi'  />

回答by Chase Florell

This by its self works

这是它自己的作品

<html>
 <head>
  <style type="text/css">
   .jander2{
     font-weight: bold;
   }
 </style>
 </head>
 <body>
  <form method="post" action="somepage">
   <input id="jander" class="jander2">
  </form>
 </body>
</html>

What I'm thinking is that you have something like

我在想的是你有类似的东西

input{font-weight: normal;}

kicking around in your other CSS. Take a look to see if there is any other CSS that might be overriding .jander2

在你的其他 CSS 中踢球。看看是否有任何其他 CSS 可能被覆盖.jander2

Remember CSS is read top to bottom, so styles that are applied later will override styles that are applied earlier.

请记住,CSS 是从上到下读取的,因此稍后应用的样式将覆盖先前应用的样式。

Alternatively you can try

或者你可以试试

  <style type="text/css">
   .jander2{
     font-weight: bold !important;
   }
 </style>

But this isn't recommended since it just masks the problem.

但不建议这样做,因为它只是掩盖了问题。