WordPress.org

Ready to get started?Download WordPress

Forums

image height/width query into CSS (5 posts)

  1. seanik
    Member
    Posted 4 years ago #

    Hi!

    I am customizing my own photoblog theme using custom Single Post Templates to define layouts for landscape and portrait orientation. In each template, I am using a small amount of inline CSS to define the templates' unique parameters, specifically the width/height of the page and wrapper divs.

    My question: is there a way to set up a query for these values for each image and insert them into the CSS dynamically (so that the container divs size accordingly)? Or do I need to set up custom fields for this and enter the width/height manually for each post?

    Also, I am using PhotoQ (if that helps).

    BTW: I've Googled like mad, but I'm totally at the novice level with the vernacular so if anyone has any ideas, they would be among the first. Thanks!

  2. seanik
    Member
    Posted 4 years ago #

    I was thinking something to the effect of:

    <style type="text/css">
    
    #page {width: <?php xxxxx(); ?>px;}
    #imagewrap {width: <?php xxxxx(); ?>px; position: relative}
    #image {height: <?php xxxxx(); ?>px; width: <?php xxxxx(); ?>px;}
    
    </style>

    Can this be done (or is there a better way)?

  3. seanik
    Member
    Posted 4 years ago #

    Thank you for all your help.

  4. pmek
    Member
    Posted 3 years ago #

    You can't use php within CSS really.

    You could possibly write some javascript that applies CSS, though.

  5. Jeremy Clark
    Moderator
    Posted 3 years ago #

    @pmek the way seanik is suggested would work fine, since the style will be inline on the php page it will work fine.

    It would probalby be simplier to use custom fields, but there is php GD function called getimagesize that will return height and width.

Topic Closed

This topic has been closed to new replies.

About this Topic