简体   繁体   English

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

[英]Why is my CSS code not working in my HTML file?

I am trying to put my CSS code in the same file as my HTML code, but it does not display properly (I do not want to just link my CSS to my HTML, I already got that to work). 我试图将CSS代码与HTML代码放在同一文件中,但是无法正确显示(我不想仅将CSS链接到HTML,我已经可以使用它了)。 I have tried copying and pasting the code, but that does not work. 我曾尝试复制和粘贴代码,但这不起作用。 Do I have to do it differently when it is in the same file? 当它在同一文件中时,我是否必须做不同的事情?

Here is the relevant code: 以下是相关代码:

<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>

Here is a pic of how it looks when I link it 这是我链接时的外观图片 在此处输入图片说明

And here is a pic of how it looks when I try putting the CSS in the HTLM file 这是我尝试将CS​​S放入HTLM文件时的外观图片 在此处输入图片说明

Works for me. 为我工作。 Only problem I see is input: textarea is invalid. 我看到的唯一问题是input: textarea无效。 Just use textarea instead. 只需使用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> 

no need to specify input just textarea . 无需仅指定input textarea you can even use inline css for 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM