SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Vertical align button in different height <li's>

    I have a listing made with a unsorted list in three columns. Every <li> is holding an image, a <h2>, a <p> and a form holding a button. What I would like to accomplish is that the <h2's> are neatly lined up under the images and the same for the buttons at the bottom of each <li>. But because not all images have the same height neither the <h2> nor the images are lined as you can see here. Is there a way that I have all <h2's> and the buttons in the different colums lined up?

    Thank you in advance.
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,269
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Hi,

    It can be done easily by using a table row philosophy but then you have to dis-associate the text from the images and contain each in a new row which isn't semantically very good.

    There are some things you can do if you want to keep things logical but you may have to make compromises in some way.

    You could for example align the text neatly but that would mean the top of the images would be uneven as you would simply vertically-align them to the bottom (using inline-block instead of floats). This just changes the uneven aspect to the top of the images rather than the text.

    You also have to consider whether the text under the image is going to run to two lines and that would again mess up the alignment unless they were all in separate cells and rows as mentioned firstly.

    So what else can you do?

    1)You could set min-heights for the elements so that that they line up and then control your data to be within those limits.

    2) Assuming your text under the image is only one line you could create some padding-top above the image and absolutely place the image into the padding and that would mean the text would line up but you would need to keep the images within those constraints (or hide the overflow).

    Code:
    .list_item{
    position:relative;
    padding-top:210px;/* arbitrary height */
    }
    .list_item img{
    position:absolute;
    top:0;
    left:0;
    right:0;
    display:block;
    margin:auto;
    }
    3) Use display:table and table-cell but you would need to do it in separate rows so all images go n the first row and then text on the second row and buttons in the third row. Something like this example but you need an extra row and align the images vertical-align:top;

    4) The flexible box model allows for things like this but support is minimal at the moment so I would wait unless you have a fall-back for other browsers.

    The easiest solution would be as shown in Number 2 above but of course does not allow for full flexibility.

    Years ago I did a few examples that might be of interest but they possibly need updating.

    http://www.pmob.co.uk/search-this/stcaption1.htm
    http://www.pmob.co.uk/search-this/stcaption2.htm
    http://www.pmob.co.uk/search-this/stcaption3.htm
    http://www.pmob.co.uk/search-this/stcaption4.htm
    http://www.pmob.co.uk/search-this/stcaption5.htm
    http://www.pmob.co.uk/search-this/stcaption6.htm
    http://www.pmob.co.uk/temp/caption100.htm
    http://www.pmob.co.uk/temp/caption-150.htm
    http://www.pmob.co.uk/temp/caption-151.htm
    http://www.pmob.co.uk/temp/caption152.htm

  3. #3
    SitePoint Wizard donboe's Avatar
    Join Date
    Jun 2010
    Location
    Netherlands
    Posts
    2,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Paul. I will go for the second option. Although in the example are all portrait images, most of the images from other categories are landscape so the second option gives me enough flexibility. Thanks a lot
    “Good artists copy, great artists steal” (Pablo Picasso - 1934)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •