简体   繁体   English

使用 css 在站点范围内缩进段落后,如何从该规则中排除居中文本?

[英]After using css to indent paragraphs site wide, how do I exclude centered text from this rule?

I have used css to indent every parapgraph in wordpress by 30px.我使用 css 将 wordpress 中的每个段落缩进 30px。 This was going great until I noticed that it also indented my centered aligned text by 30px.这一切都很好,直到我注意到它还将居中对齐的文本缩进了 30 像素。 That makes this centered text off centered.这使得这个居中的文本不居中。 It's even more noticible when I look at it on mobile and I want the text to be easy and professional to read on the go.当我在移动设备上查看它时,它更加引人注目,我希望文本在旅途中易于阅读且专业。 So, I want to exclude "text-align:center;"所以,我想排除“text-align:center;” from the 30px indents for every center aligned text.从每个居中对齐的文本的 30px 缩进开始。

I don't have access to the entire code of my theme with my wordpress premium account.我无法使用我的 wordpress 高级帐户访问我的主题的整个代码。 I can only edit the css using a blank css editor in a menu option.我只能在菜单选项中使用空白 css 编辑器来编辑 css。 Is this possible without being able to see the whole code?如果无法看到整个代码,这可能吗?

I have tried looking this up on stackoverflow before posting and using this code...在发布和使用此代码之前,我曾尝试在 stackoverflow 上查找此内容...

#article p {
    display: block;
    text-align:center;
    text-indent:0!important;
}

I now know that this "#workskin p.chapter" ID selector will not work because I have not added it to my code because I do not have access to the full themes code.我现在知道这个“#workskin p.chapter”ID 选择器将不起作用,因为我没有将它添加到我的代码中,因为我无法访问完整的主题代码。

This is the css code that I am using to make the indents and the only code that I have in my css editor for wordpress "p" paragraph element...这是我用来制作缩进的 css 代码,也是我在 css 编辑器中为 wordpress“p”段落元素所拥有的唯一代码...

article p {
    text-indent: 30px;
}

I could not get any changes in making my indents disappear for the text that was center aligned.对于居中对齐的文本,我无法使缩进消失。

I'd like to make my center aligned text centered with my site and not indented an extra 30px from the center.我想让我的居中对齐文本以我的网站为中心,而不是从中心额外缩进 30 像素。 For example:例如:

  • Title-centered with no indents以标题为中心,无缩进
  • Paragraph one-indented第一段缩进
  • Paragraph two-indented段落二缩进
  • Break in paragraph-centered no indents打破以段落为中心的无缩进
  • Paragraph three-indented段落三缩进
  • Paragraph four-indented段落四缩进
  • Break in paragraph-centered with no indents...etc以段落为中心打断,没有缩进......等

This is the first time I am using css.这是我第一次使用 css。 Usually I have a full theme to look at the code and I am able to make small edits using color# and changing the src of images but that is the extent of my coding knowledge and I'm learning a little more with each google search and comment.通常我有一个完整的主题来查看代码,并且我能够使用 color# 进行小的编辑并更改图像的 src ,但这是我编码知识的范围,我在每次谷歌搜索和评论。 This is the last code edit I need on my site and I appreciate everyones comments and help.这是我需要在我的网站上进行的最后一次代码编辑,我感谢大家的评论和帮助。

you can put class on the p that you want to exclude from it like:您可以将类放在要从中排除的 p 上,例如:

article p {
    text-indent: 30px;
}

// try changing it to this remember exclude is class on p tags you want to exclude
// Dont forget the dot (.) before exclude
// and the !important is after the value
article .exclude {
    text-indent: 10px !important; // you put !important here
    color: red !important; // like this
    padding: 10px !important; // like this
}

MAKE SURE TO MAKE EXCLUDED P UNDER THE NONE EXCLUDED TO REWRITE IT确保在 NONE EXCLUDED 下排除 P 来重写它
LOOK AT CODE COMMENTS CAREFULLY仔细查看代码注释

Hope it was hepfull希望它是hepfull

The specificity in CSS is in the order of Type selector(h1, p ,div...) < Class selector(rules with a period .) < ID selector(rules with #) but the rules defined with ! important CSS 中的特殊性的顺序是 Type selector(h1, p ,div...) < Class selector(rules with a period .) < ID selector(rules with #) 但规则定义为! important ! important overrides any other declaration ofcourse ;) As discussed above if different set of rules are added for a same element ie rules targeting elements with same specificity then the CSS will use the rules defined later on (ie the latest one) Example: ! important覆盖当然的任何其他声明;) 如上所述,如果为同一元素添加不同的规则集,即针对具有相同特性的元素的规则,那么 CSS 将使用稍后定义的规则(即最新的规则)示例:

    p{
        color : red ;
    }
    p{
        color : green ;
    }

In this example the color of the text in paragraphs will be green and not red as rule with green color is defined after the red one.在这个例子中,段落中文本的颜色将是绿色而不是红色,因为绿色是在红色之后定义的规则。

    p{
        color : red ! important;
    }
    p{
        color : green ;
    }

But here because of ! important但这里是因为! important ! important is added to red the color of text inside the p will be red. ! important是添加到红色p内的文本颜色将是红色。

So in your case you can go with either defining the text-align: center ! important因此,在您的情况下,您可以定义text-align: center ! important text-align: center ! important or just define the rules overiding the ones you don't want in the specific p tag but this can be done by defining it's specific CSS rules after the rules for normal p tags text-align: center ! important或只是定义规则覆盖您在特定p tag不想要的规则,但这可以通过在普通p标签的规则之后定义它的特定 CSS 规则来完成

first define the normal or default rules as首先将正常或默认规则定义为

article p { 
    text-indent: 30px; 
    }

After this add the specific rules在此之后添加特定规则

#worskin p .chapter {
    display: block;
    text-align:center; 
    text-indent:0; 
    }

Thanks AuxTaco for your suggestion.感谢 AuxTaco 的建议。

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

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