Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1344
  • Last Modified:

How to make images within a container div scale with the div in a fluid layout

Hello,

I have a fluid page with 3 column divs, they are fluid (30%) of page width which is also fluid with a minimum size of 1024px.

I'm just trying, and failing miserably, to get the images to scale with the divs both up and down as the window is resized. The images are 700px wide so I want to make that themaximum the columns can scale too also if possible so the overall page never exceeds about 2140px or so.

I am using this withing a POD (PODS CMS) in wordpress. So the images are each callled through a PODS template which is below. IT won't let me apply the style directly onto the image so I am trying to add it as a wrapper div, I think this may be my problem here??


Can anyone suggest the best method for this please?

Cheers :)


This is what I have so far (the divs scale well with the their text content, the images are just full size and cut off):


/* CONTAINER DIV */

#profileBoxes{width:100%;min-width:1020px;margin:70px auto;height:auto;overflow: hidden;}



/* COLUMNS */

#profileLeft{width:31%;max-width:700px;height:auto;float:left;overflow:hidden;}

#profileMiddle{width:31%;max-width:700px;height:auto;float:left;margin-left:3%;display:inline;overflow:hidden;}

#profileRight{width:31%;max-width:700px;height:auto;float:left;margin-left:3%;display:inline;overflow:hidden;}


/* IMAGE CLASS*/

.profileImg {float:left;height:auto;max-width:100%;position: relative;overflow:hidden;}



/*PODS TEMPLATE */

<div class="profileImg" ">
<?php
foreach ($this->get_field('image') as $image) {
  echo "<img src=\"{$image['guid']}\" />";
}
?>
</div>
<div class="profileText">{@text}</div>
0
igloobob
Asked:
igloobob
  • 4
  • 2
1 Solution
 
Kyle HamiltonData ScientistCommented:
The max-width has to applied to the image. You can do this:

.profileImg img{
max-width:100%:
}

This will target images inside the prifileImg div.

However, what do you mean it won't allow you to access the image?

What you should really do is get rid of the wrapper div and add a class to the image that is being generated from the template. Then apply the max-width to that class.
0
 
igloobobAuthor Commented:
D'oh of course! Thanks kozaiwaniec, sometimes I just get too close to something and miss the obvious!

It is in the code for the PODS template I cannot apply a class to the image code as I would normally as it causes errors. I would imagine I could do this but it doesn't work (unless there's another way to do it in this template code?):


<?php
foreach ($this->get_field('image') as $image) {
  echo "<img class="profileImg" src=\"{$image['guid']}\" />";
}
?>

<div class="profileText">{@text}</div>


So I have kept it like this:

<div class="profileImg" ">
<?php
foreach ($this->get_field('image') as $image) {
  echo "<img src=\"{$image['guid']}\" />";
}
?>
</div>
<div class="profileText">{@text}</div>

and added

.profileImg img{
max-width:100%:
}


as you pointed out.

Thanks!!
0
 
Kyle HamiltonData ScientistCommented:
you're using the wrong type of quotes.

<?php
foreach ($this->get_field('image') as $image) {
  echo "<img class='profileImg' src=\"{$image['guid']}\" />";
}
?>

Open in new window


or the other way is to escape the quotes:

<?php
foreach ($this->get_field('image') as $image) {
  echo "<img class=\"profileImg\" src=\"{$image['guid']}\" />";
}
?>

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
igloobobAuthor Commented:
Brilliant thanks!!
0
 
Jason C. LevineNo oneCommented:
@kozaiwaniec Nicely done.  Good work...
0
 
Kyle HamiltonData ScientistCommented:
Thanks guys.. :)))
0
 
Kyle HamiltonData ScientistCommented:
/*PODS TEMPLATE */

<!-- <div class="profileImg" "> -->
<?php
foreach ($this->get_field('image') as $image) {
  echo "<img class="profileImg" src=\"{$image['guid']}\" />";
}
?>
<!-- </div> -->
<div class="profileText">{@text}</div>
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now