为什么我的CSS代码不能在我的HTML文件中工作?

问题描述:

我试图把我的CSS代码放在与我的HTML代码相同的文件中,但它不能正确显示(我不想只将我的CSS链接到我的HTML,我已经得到了它的工作)。我试图复制和粘贴代码,但这不起作用。当它在同一个文件中时,我必须以不同的方式做它吗?为什么我的CSS代码不能在我的HTML文件中工作?

下面是相关代码:

<head> 

    <title> Example </title> 

    <style type="text/css"> 

     input: textarea{ 
      resize: none; 
     } 
     input[type=button]{//set the sizes for all of the input buttons 
      width: 5em; 
      height: 2em; 
      font-size: 15px; 
      font-weight: bold; 
     } 
    </style> 
</head> 

<body> 

    <form id = "mainForm" name="mainForm" method="get" action="" onsubmit=" return checkForm()"> 


     Type something: <br> <textarea id="info" name="info" > </textarea> 


     <input type="button" value="1" id="button1"> </input> 
     <input type="button" value="2" id="button2"> </input> 
     <input type="button" value="3" id="button3"> </input> 

     <input type="submit" id="submit" name="submit" class="btn" value="Submit" /> 
     <input type="reset" id="reset" name="reset" class="btn" value="Clear" /> 
    </form> 
</body> 

这里是它的外观,当我将其链接 enter image description here

一个PIC这里是一个事先知情同意当我尝试将CS​​S放入HTLM文件时它的外观如何变化 enter image description here

+0

注意,CSS仅定义['/ * ... * /'征求意见(https://developer.mozilla.org/en-US/docs/Web/CSS/Comments)。 '// ...'不被它支持。 –

+0

谢谢,是它! –

无需指定input只是textarea。你甚至可以使用inline css作为textarea。

<style type="text/css"> 

     textarea{ 
      resize: none; 
     } 
     input[type=button]{ 
     width: 5em; height: 2em; 
      font-size: 15px; 
      font-weight: bold; 
     } 
    </style> 
+0

请看看我上传的图片 –

+0

@bobdylan现在更新,它会按预期工作。删除/ /设置所有输入按钮的大小(因为/ /不是一个CSS评论) – bakki

+0

谢谢你是对的! –

适合我。我看到的唯一问题是input: textarea无效。改用textarea即可。

<head> 
 
    <title> Example </title> 
 
    <style type="text/css"> 
 
     textarea{ 
 
      resize: none; 
 
     } 
 
     input[type=button]{ //set the sizes for all of the input buttons 
 
      width: 5em; 
 
      height: 2em; 
 
      font-size: 15px; 
 
      font-weight: bold; 
 
     } 
 
    </style> 
 
</head> 
 
<body> 
 
    <form id="mainForm" name="mainForm" method="get" action="" onsubmit="return checkForm()"> 
 
     Type something: <br> <textarea id="info" name="info" > </textarea> 
 
     <input type="button" value="1" id="button1"> 
 
     <input type="button" value="2" id="button2"> 
 
     <input type="button" value="3" id="button3"> 
 
     <input type="submit" id="submit" name="submit" class="btn" value="Submit"> 
 
     <input type="reset" id="reset" name="reset" class="btn" value="Clear"> 
 
    </form> 
 
</body>