• Hi!

    Is it possible for me to add a class to an img tag.

    You know, I want to add a background image behind the picture BUT the background image will resize automatics if the image is smaller.

    S?… Can I add a class to the image?

    Thanks //WebbHelp

Viewing 15 replies - 1 through 15 (of 19 total)
  • Is it possible for me to add a class to an img tag.

    yeah sure, why not?

    Peter

    Thread Starter webbhelp

    (@webbhelp)

    Yes, but how.

    I thougt I was going into the code, but I don?t know the file…

    Let me try then. How would that background image be? Because I suspect resizing could be a real problem, without using lots and lots of (for instance) jQuery stuff.

    If the background is a tile of some sort, a div around the image could do the trick:

    <div class="imgdiv">
      <img src="..." />
    </div>

    and in css:

    .imgdiv {
      background: url(...);
      overflow: hidden;
    }

    Peter

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    What’s wrong with simply <img src="..." class="whatever" />?

    I guess I don’t understand the original question. You can add a class to anything.

    Thread Starter webbhelp

    (@webbhelp)

    yeah but where can i find that in code?

    Beacause everytime the owner will send a new blog post. I want it to be a class before the img tag like:

    <div class=””>

    <img src=”…/”></img>

    </div>

    How can I add that?

    I am new with WordPress and I got no idé how to add an class so I can create a resizable background, with classes.

    That complicates it a little.

    I think I would solve this by using custom fields, but to explain that here would be too lengthy.

    There’s a good screencast on css-tricks.com, where Chris explains the usage of custom fields very well.

    Peter

    Thread Starter webbhelp

    (@webbhelp)

    Ok, so it is that difficult to get a background of an image.

    You know I want to get an image that is behind the image, lika a frame, and the frame will resize it self if the image is bigger…

    Thanks ??

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    I’d say that you’re doing it wrong. You don’t want to style your site such that the author has to put special code into every post just to make the theme work properly.

    Rework your style to address the image in the content directly instead of requiring some weird class.

    Thread Starter webbhelp

    (@webbhelp)

    I don’t really understand now.

    I don’t want that author will be writing html code and that stuff, I want the picture to get a frame behind, automatically, nut I don’t know how and it seems to be very difficult!

    Thread Starter webbhelp

    (@webbhelp)

    Wait wait, This must be easier:

    If I got only one frame that don’t need to be resizeable.

    How can I put it behind the pictures.

    OBS: It don’t need to be resizable!

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    webbhelp: Why is it difficult?

    https://www.google.com/search?q=add+a+frame+to+images+css

    Seems easy enough to me.

    Thread Starter webbhelp

    (@webbhelp)

    Sorry, but I am new with WP.

    I now in CSS how to bring the frame behind the picture, but where shall I put the code?

    I’d say that you’re doing it wrong. You don’t want to style your site such that the author has to put special code into every post just to make the theme work properly.

    That’s a matter of opinion and possibly jumping to conclusions as well, since we didn’t hear from the OP whether the background image would be the same for all foreground images or not.

    Anyhow, those custom fields were designed to put some additional power to authors, and the site builder can decide whether or not to react to a missing custom field.

    Peter

    Thread Starter webbhelp

    (@webbhelp)

    I am not that good at english but I try.

    Have we confirmed that the user/author will add the code for the image frame or?

    You know, I want to add a background image behind the picture BUT the background image will resize automatics if the image is smaller.

    • Will these background images be the same for all pictures?
    • If you refer to ‘the picture’, are those pictures in one or more posts, or also (or even exclusively) outside posts?

    Peter

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Add class to image’ is closed to new replies.