Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to add inline css code inside a page of my blog. This css code calls an image as background of a div.

Is this possible? and how to do that?

I have tried to add the image as a Media resource, and got a URL for it, but using this URL does not seem to work.

Example of code that I paste to my page html:

    <p><a href="http://mysite.com/wp-signup.php" style="width: 90%;
        font-family: Helvetica, Arial, sans-serif;
        background: #0e710d url(http://mysite.com/wp-content/uploads/2012/03/image.png) 0 0 repeat-x;
       font-size: 1.6em;
    ">
    Click here &raquo;</a></p>
share|improve this question
    
I realized the problem was that I had some space in the middle of my inline css code which prevented the code from working. –  tucson Mar 20 '12 at 10:14
add comment

2 Answers

up vote 2 down vote accepted

cant you just give that link a class? why touch your template files?..
anyhow i see no reason why you can't to that... the css should work..

The only change i would do when editing a template file is
using php to get the folder url (where you image is) like so:

<style type="text/css">
.specialLink a {
    width: 90%;
    font-family: Helvetica, Arial, sans-serif;
    background: #0e710d url("<?php get_bloginfo('url'); ?>/wp-content/uploads/2012/03/image.png") repeat-x 0 0;
    font-size: 1.6em;
}
</style>

<p class="specialLink"><a href="http://mysite.com/wp-signup.php">Click here &raquo;</a></p>

Again... i reccomend you use your style.css to load that css and not in
template files.. if you need it just for a specific page say so... i have
a better solution for that.

Hope this helps, Sagive.

share|improve this answer
    
I realized the problem was that I had some space in the middle of my inline css code which prevented the code from working. –  tucson Mar 20 '12 at 10:14
    
glad you solved that. that kinda stuff can get a designer crazy while searching for a solution ;) –  Sagive SEO Mar 20 '12 at 12:52
    
You're asking for a broken image link down the road by using the path to the file. It would work better to use wp_get_attachment_image_src(). –  JPollock Jun 20 '13 at 21:50
add comment

There's no reason this technique shouldn't work in general, although your specific code example won't work the way you say you want: you're adding the style attribute to an A tag, not to a DIV tag, which is what you say you want to do. So the A tag should be styled as shown, not the DIV tag.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.