CSS和样式的顺序 [英] CSS and order of styles

查看:83
本文介绍了CSS和样式的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图想出这一点,请考虑这些样式:

Im trying to figure this out, please consider these styles:

.text_left
{
text-align:left;
}

.text_right
{
text-align:right;
}

.text_cen
{
text-align:center;
}

.form_container_header
{

width:95%;
margin-left: auto ;  
margin-right: auto ;
margin-bottom:35px;
text-align:center;
}

现在,当我将这些样式应用于我的DIV时:

Now , when I apply these styles to my DIV like so:

<div class="form_container_header text_left">

有人可以向我解释为什么DIV的内容居中而不是左对齐?

Can someone explain to me why The content of the DIV is centered and not left aligned?

BUT
当我将text_left类移动到样式表中的form_container_header类之下,然后左对齐?

BUT when I move the "text_left" class below the "form_container_header" class in the style sheet it then left aligns?

谢谢

推荐答案

当你写一个像text_left的样式时,你可能想使用!important。这将覆盖设置该值的任何其他样式。

When you write a style like "text_left", you might want to use !important. This will override any other styles that set that value.

以下作品。



.text_left
{
text-align:left !important;
}

.text_right
{
text-align:right !important;
}

.text_cen
{
text-align:center !important;
}

.form_container_header
{

width:95%;
margin-left: auto ;  
margin-right: auto ;
margin-bottom:35px;
text-align:center;
}

<div class="form_container_header text_left">


EDIT: Please read the comments on this answer before doing this. There are some concerns about using !important recklessly.

这篇关于CSS和样式的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆