简体   繁体   English

为什么我正在编写的CSS规则没有被应用?

[英]Why aren't the CSS rules I am writing being applied?

For some strange reason, I cannot edit or apply styles to html in Sublime Text 2. I cannot do internal styles or link to external styles. 由于某些奇怪的原因,我无法在Sublime Text 2中编辑样式或将样式应用于html。我无法进行内部样式或链接到外部样式。 However, if I take code that I have done into Dreamweaver or Notepad++, the styles are applied and editable? 但是,如果我将已经完成的代码带入Dreamweaver或Notepad ++,是否可以应用和编辑样式? How can I get sublime Text 2 to allow me apply and edit styles? 如何获得Sublime Text 2,以允许我应用和编辑样式?

I have Windows 7 and I'm new to HTML and CSS. 我有Windows 7,并且是HTML和CSS的新手。 I'm trying to learn different code editors, but it's quite difficult when the editors won't work :( 我正在尝试学习不同的代码编辑器,但是当编辑器不起作用时,这是相当困难的:(

Thanks! 谢谢!

ETA: When I mean styles I mean css. ETA:当我指样式时,指CSS。 I can't view any css styling on my html page on Sublime text 2. Only when I use notepad++ or dreamweaver. 我无法在Sublime文本2的html页面上查看任何CSS样式。仅当我使用notepad ++或dreamweaver时。 I can't see css in a browser when I use sublime text 2. 使用崇高文字2时,在浏览器中看不到CSS。

Here's my code: 这是我的代码:

<!DOCTYPE html>
<head>
<meta charset=utf-8" />
<title>Untitled Document</title>
</head>

<style> 
    body{
        background: orange;
    }

</style>

<body>
</body>
</html>

You're issue isn't with the editor; 您的问题与编辑无关; it's likely that there are some errors in the document. 该文档中可能有一些错误。

You're currently missing the opening <html> , <style> elements should be inside either the <head> or <body> rather than between them, and the charset attribute should have a 2nd quotation to surround the value: 你目前缺少开幕<html> <style>元素应该是里面 <head><body>而不是它们之间,和charset属性应该有第二个引号包围的价值:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Untitled Document</title>

    <style> 
        body{
            background: orange;
        }

    </style>
</head>

<body>
</body>
</html>

The issue is not the text editor, it must be your code. 问题不是文本编辑器,它必须是您的代码。 You may be opening an outdated file and looking for the changes in there. 您可能正在打开一个过时的文件并在其中查找更改。 Make sure that you are saving the file in the correct location and opening the correct file when looking for changes. 在寻找更改时,请确保将文件保存在正确的位置并打开正确的文件。

Also, make sure that you are saving it as .html, Sublime Text 2 will not automatically give your files an extension like Dreamweaver or other editors might. 另外,请确保将其另存为.html,Sublime Text 2不会自动为文件提供扩展名,例如Dreamweaver或其他编辑器。

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

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