Html 使用内联CSS设置div';s
我的页面页脚中有一些文字有问题。在“我的外部样式表”中,默认情况下文本向左对齐。但据我所知,内联CSS将超越这一点。以下是我对代码所做的操作:Html 使用内联CSS设置div';s,html,css,inline,Html,Css,Inline,我的页面页脚中有一些文字有问题。在“我的外部样式表”中,默认情况下文本向左对齐。但据我所知,内联CSS将超越这一点。以下是我对代码所做的操作: <div id="footer" style="text-align: center; "> <p>Created by John Smith<br>Copyright "Microsoft Inc." 2015</p> </div> 由John Smith创建版权所有“Micro
<div id="footer" style="text-align: center; ">
<p>Created by John Smith<br>Copyright "Microsoft Inc." 2015</p>
</div>
由John Smith创建
版权所有“Microsoft Inc.”2015
但是文本仍然显示在页面的左侧,我的错误是什么
提前谢谢。大家现在习惯了
<div id="footer" >
<p style="text-align: center; ">Created by John Smith<br>Copyright "Microsoft Inc." 2015</p>
</div>
要使以后的声明覆盖以前的声明,请执行以下操作:
/* 0: default */
#footer { text-align:left; }
#footer { text-align:center; }
/* 1: using !important */
#footer { text-align:left; }
#footer { text-align:center !important; }
/* 2: specific selector */
#footer { text-align:left; }
#mainpage #footer { text-align:center; }
/* 3: selector type tag - id - class */
div { text-align:right; }
div.footer { text-align:left; }
div#footer { text-align:center; }
应用具有最高CSS特性的样式。不同元素的特异性定义如下:
!important = is the superior: only !important can override !important
ID attribute = 100
Class attribute = 10
Element = 1
<p id="target" class="target">Hello World</p>
<style>
p#target {color: black} /* Specificity: 101 */
p#target {color: red} /* Specificity: 101 */
p.target {color: blue} /* Specificity: 11 */
p {color: tomato} /* Specificity: 1 */
/* Red color is applied */
</style>
信用:CSS规则优先级:
在外部样式表中尝试此代码。很好,它工作得非常好。这在我的网站上是如此奇怪,它似乎仍然在向左对齐:感谢这一点,我从来没有想到将样式应用于段落而不是div。你可以使用css#footer>p{text align:center;}
!important = is the superior: only !important can override !important
ID attribute = 100
Class attribute = 10
Element = 1
<p id="target" class="target">Hello World</p>
<style>
p#target {color: black} /* Specificity: 101 */
p#target {color: red} /* Specificity: 101 */
p.target {color: blue} /* Specificity: 11 */
p {color: tomato} /* Specificity: 1 */
/* Red color is applied */
</style>
.contents {color: #999 !important;}
section.contents {color: #999;}
body .contents {color: #999;}
#container > .contents {color: #999;}
#footer p {
text-align: center;
}