使用 CSS 和 HTML 为不同的段落设计不同的样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17266501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Styling different paragraphs with different styles using CSS and HTML
提问by MikanPotatos
I have a question on using the class tag on paragraph tags. I want the external Css file to style a paragraph a certain way while leaving all the other paragraphs to the default style.I did some googling and reading and found if i add <p class="somename" >
then in the css file i can change that paragraph using p.somename{ color: blue;}
But what i found is p{color: red;}
seems to be affecting them all.
我有一个关于在段落标签上使用 class 标签的问题。我希望外部 Css 文件以某种方式设置段落样式,同时将所有其他段落保留为默认样式。我做了一些谷歌搜索和阅读,发现如果我<p class="somename" >
在 css 文件中添加,我可以使用p.somename{ color: blue;}
但我发现的内容更改该段落是p{color: red;}
似乎影响到他们的所有。
This was just a example problem. The main problem im facing is that i dont want p.somename to have a background border.And the default <p>
has borders.
这只是一个示例问题。我面临的主要问题是我不希望 p.somename 有背景<p>
边框。默认有边框。
回答by Tepken Vannkorn
Put p.somename{ color: blue }
to the bottom comparing to p{ color: red}
or you can use !important
to foce your style to overwrite. for example,
放在p.somename{ color: blue }
底部比较p{ color: red}
或者你可以!important
用来集中你的风格来覆盖。例如,
p.somename {
color: blue !important;
}
回答by Sarathlal N
In HTML,
在 HTML 中,
<p id="colorblue">some lorem ipsum here</p>
In CSS,
在 CSS 中,
p #colorblue{
color: blue
}
Or tepkenvannkorn's answer will work.
或者 tepkenvannkorn 的答案会起作用。
p.somename { color: blue !important; }
回答by raul
Only use that id on the paragraph that you want to change, while keeping others at default
仅在要更改的段落上使用该 ID,而其他保持默认
p #colorred{
color:red
}
<p id="colorred">
回答by Belinux
/* In HTML,
/* 在 HTML 中,
<p id="colorblue">some lorem ipsum here</p>
In CSS,
在 CSS 中,
#colorblue {
color:blue;
}
This works. You do not need to explain that is a paragraph in CSS. Only write the ID of the paragraph in CSS.*/
这有效。您不需要解释这是 CSS 中的一个段落。CSS中只写段落ID。*/