第一种CSS样式不会响应HTML [英] First CSS style will not respond to HTML
问题描述
第一个网站,我无法弄清楚为什么我的第一个CSS样式块不适用于我的HTML编译器。
无论我提出哪种风格首先(通过重新排序类)顶部的那个将不起作用。
当标题位于顶部时,我丢失了标题文本的所有样式。
当nav位于顶部时,我失去了所有的导航风格。等等。
< style>
#something {
}
#header {
background-color:black;
颜色:白色;
text-align:center;
}
#nav {
line-height:30px;
background-color:#eeeeee;
身高:300px;
宽度:100px;
float:left;
填充:5px;
}
#section {
宽度:700px;
float:left;
填充:10px;
}
#footer {
background-color:black;
颜色:白色;
clear:both;
text-align:center;
填充:5px;
}
< / style>
所以,我把风格东西放进去,以使它成为不属于的类但是,b
虽然这是一个理由,也是一个更好的解决方案。
编辑:这里是HTML,
<!DOCTYPE html PUBLICMy First>
< html>
< body>
< head>
< link rel =stylesheethref =styles / style2.css>
< / head>
< div id =header>
< h1>启动< / h1>
< / div>
< div id =nav>
< li>< a href =othersite.html>主页< / a> <峰; br>
< li>< a href =webdev.html>最新帖子< / a> <峰; br>
< li>< a href =town.html> Web Dev< / a> <峰; br>
< li>< a href =links.html>复制写入< / a> <峰; br>
< li>< a href =links.html>旧帖子< / a>
< / div>
< div id =section>
< h1>启动< / h1>
< p>内容......< / p>
< p>内容......< / p>
< / div>
< div id =footer>
12月23日,
我的名字
< / div>
我的< style>
标签是问题。仍然不确定为什么它会导致这个问题 - 这看起来很奇怪。
我删除了< style>
标签,它运行正常。
谢谢大家!
< style> ;
标记将在 html
的< head>
标记内使用, 不在CSS文件中。
所以你要把CSS放在 html中的
或在外部引用文件(css)中,与< style>
标签内< link>
相关联,在这种情况下,它只应包含 CSS
,没有任何 HTML
标签。
First website, and I can't figure out why my first CSS style block won't work with my HTML compiler.
No matter which style I put up first (by reordering the classes) the one on top won't work. When "header" was on top, I lost all style for the header text. When "nav" was on top, I lost all nav style. Etc.
<style>
#something {
}
#header {
background-color:black;
color:white;
text-align:center;
}
#nav {
line-height:30px;
background-color:#eeeeee;
height:300px;
width:100px;
float:left;
padding:5px;
}
#section {
width:700px;
float:left;
padding:10px;
}
#footer {
background-color:black;
color:white;
clear:both;
text-align:center;
padding:5px;
}
</style>
So, I put in the style "something" in order to make it the class that doesn't work.
There has to be a reason for this though, and a better solution.
Edit: Here's the HTML,
<!DOCTYPE html PUBLIC "My First">
<html>
<body>
<head>
<link rel="stylesheet" href="styles/style2.css" >
</head>
<div id="header">
<h1>Launch</h1>
</div>
<div id="nav">
<li><a href="othersite.html">Home page</a> <br>
<li><a href="webdev.html">Latest Post</a> <br>
<li><a href="town.html">Web Dev</a> <br>
<li><a href="links.html">Copy Write</a> <br>
<li><a href="links.html">Old Posts</a>
</div>
<div id="section">
<h1>Launch</h1>
<p>Content...</p>
<p>Content...</p>
</div>
<div id="footer">
December 23rd,
my name
</div>
My <style>
tags were the issue. Still not sure why it caused THAT problem- which seems odd.
I removed the <style>
tags, and it is working fine.
Thanks guys!
<style>
tag is to be used inside the <head>
tag of your html
, not inside a CSS file.
So you either place your CSS inside a <style>
tag in the html
or in an external referenced file (css), linked with a <link>
, in which case it should only contain CSS
, without any HTML
tags.
这篇关于第一种CSS样式不会响应HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!