0

I have to set up this function, which gets a value out of a custom field in a Wordpress article editor. It works and displays the price I inserted in the editor (e.g. 20,00)

BUT I can't style it using css.

<div class="price">
   <p>
      <?php echo '<div class="price">'. get_post_meta( get_the_ID(), 'price', true).'</div>'; ?>€
   </p>
</div>

This is my css file:

.price { font-size:50px; color:#8e8e8e;  }

Why does the css not apply to the code?

1
  • 2
    Paragraphs can't contain div tags, so the browser tries to correct for that and changes the HTML. Commented Oct 17, 2014 at 15:58

1 Answer 1

1

CSS applied with PHP is no different than any other CSS. That's not the problem.

It's probably a matter of some other CSS with a more specific selector overriding your definition for .price. Also, make sure that the path to your CSS file is correct and the code is loading. To diagnose this, load the script in your browser and use the code inspector to look at the div with the .price class. It will show you all the CSS applied to the element and you will be able to see if your .price class rules are being applied and if they are overridden by another rule.

Get to know your code inspector - FireBug for FireFox is a valuable add-on, and Chrome has decent inspector built in. It's a powerful tool to figure out styling problems, among other things.

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

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.