0

This is probably much easier than I'm making it sound.

Basically I have 6 Images, each with a button underneath... This is what it looks like: Images with Buttons Underneath

I just place them like this:

<img src="Image.png" width="350" height="208" style="margin: 0px 16px">
<img src="Image.png.png" width="350" height="208" style="margin: 0px 16px">
<img src="Button.png" width="282" height="84" style="margin: 0px 16px">
<img src="Button.png" width="282" height="84" style="margin: 0px 16px">

It looks great on a typical browser window. But when I make the window narrower, it goes like this: 2 Images, then 2 Buttons

Which makes sense give how I list my images/buttons.

But I want them to look like this when the window is narrowed: Nice and in order

What can I add to my very basic HTML to keep this in a nice and format no matter how wide the window is?

Ideally I'd like to go from a 2 by x grid as max, down to a 1 by x grid as seen in the first and final images.

A push in the right direction would be amazing.

I did look HERE on Stackoverflow, but it's far more complex as only works with squares.

I look forward to your help :D

UPDATE

https://jsfiddle.net/du6Lu4ge/

looks like this: enter image description here

when resized, looks like this: enter image description here

:(

Community
  • 1
  • 1
Reanimation
  • 3,151
  • 10
  • 50
  • 88

2 Answers2

1

I would do something like this:

https://jsfiddle.net/du6Lu4ge/3/

Hope it helps you out!

What I did was to wrap the image and the button in a div .img-wrapper styled with display: inline-block

Alejo Anibal
  • 361
  • 2
  • 8
1

this example is working full responsive, you can simply edit the css and add viewports.

html:

<div class="imageContainer">
  <div class="imageBlock">
    <!--<img class="image" src="image.png">-->
    <div class="image">
       your image
    </div>
  </div>
  <div class="buttonBlock">
    <!--<img class="button" srck="button.png">-->
    <div class="button">
       your button
    </div>
  </div>
</div>
<div class="imageContainer">
  <div class="imageBlock">
    <!--<img class="image" src="image.png">-->
    <div class="image">
       your image
    </div>
  </div>
  <div class="buttonBlock">
    <!--<img class="button" srck="button.png">-->
    <div class="button">
       your button
    </div>
  </div>
</div>
<div class="imageContainer">
  <div class="imageBlock">
    <!--<img class="image" src="image.png">-->
    <div class="image">
       your image
    </div>
  </div>
  <div class="buttonBlock">
    <!--<img class="button" srck="button.png">-->
    <div class="button">
       your button
    </div>
  </div>
</div>
<div class="imageContainer">
  <div class="imageBlock">
    <!--<img class="image" src="image.png">-->
    <div class="image">
       your image
    </div>
  </div>
  <div class="buttonBlock">
    <!--<img class="button" srck="button.png">-->
    <div class="button">
       your button
    </div>
  </div>
</div>

css:

.imageContainer {
  width: 400px;
  display: inline-block; 
}

.imageContainer .imageBlock {
   display: inline-block;    
}

.imageContainer .imageBlock .image {
  display: inline-block;
  width: 400px;
  height: 300px;
  background-color: darkred;  
}

.imageContainer .buttonBlock {
  display: inline-block;
  text-align: center;
}

.imageContainer .buttonBlock .button {
  display: inline-block;
  width: 300px;
  margin: 10px 50px; /* simple way to center it */
  height: 100px;
  background-color: cyan;
}

you can test it on https://jsfiddle.net/q10fbesm/

edit: if you need a 2 line grid, simply put a container arround this html, style it with max-widht: 801px;

mtizziani
  • 956
  • 10
  • 23