0

I try to override the <h1> style in WordPress using class but failed.

.block-h1  { font-size:13px; font-size:1.1em; line-height:13px; position:absolute; top:13%; left:6%; z-index:99; color: #E35094; !important;}

There is a tag <h1 class="block-h1">Hello</h1> in page, all style of block-h1 are removed when loading by WordPress and style is kept as the .post-content h1.

I do use the !important but not work.

3
  • 3
    I don't recommend using !important but the way you're using it is incorrect. It needs to be after each rule. For example, color: #E35094 !important; Commented Sep 19, 2014 at 17:33
  • 1
    you have a typo, just delete the semicolon before !important . Then again, @j08691 is right, try to avoid !important and use more specific classes Commented Sep 19, 2014 at 18:11
  • j08691 and Fabio, thanks for your comment, I wrongly declare above style in the header, I declare them in the footer and all work. Commented Sep 20, 2014 at 1:05

2 Answers 2

1

Never use !important, it's a blunt tool and makes it difficult to override the new declaration. Make your declaration more specific.

Use a class of:

h1.block-h1 { ... }

h1.block-h1 is more specific than .block-h1 alone.

See: http://css-tricks.com/specifics-on-css-specificity/

Sign up to request clarification or add additional context in comments.

Comments

1

Just replace your css with:

h1.block-h1  { 
  font-size: 13px;
  font-size: 1.1em;
  line-height: 13px;
  position: absolute;
  top: 13%;
  left: 6%;
  z-index: 99;
  color: #E35094 !important;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.