为什么我的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>
答
无需指定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>
答
适合我。我看到的唯一问题是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>
注意,CSS仅定义['/ * ... * /'征求意见(https://developer.mozilla.org/en-US/docs/Web/CSS/Comments)。 '// ...'不被它支持。 –
谢谢,是它! –