As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

Any CSS pros out there?

RothgarrRothgarr Registered User regular
edited February 2010 in Help / Advice Forum
Hey, guys. I have a CSS question and I figured there are a lot of smart people here...

My dilemma has to do with column and row heights -- specifically, getting things to line up when they wrap. For example, here's a simple example:
http://www.prwmusic.com/misc/columns-test-even.html
if you drag the browser window wider and narrower the elements will properly wrap to the next line. because everything is the same height.

But what to do you do in scenarios where the content differs in each bucket like this?
http://www.prwmusic.com/misc/columns-test-odd.html
If you drag the browser window wider and narrower you'll see what I mean.

Some additional points:
- I can not define a universal height, because sometimes the content might be really short in a row, or sometimes the content may be a lot.
- My layout isn't liquid, this is just for demonstrative purposes. But if I have a two rows of four columns I need to ensure that things will wrap correctly.

Any way in CSS to say "make the row as tall as the tallest item". Or would some voodoo javascript even be able to do something like this?

Rothgarr on

Posts

  • Options
    RyeRye Registered User regular
    edited January 2010
    CSS is not capable of achieving what you want without knowing the tallest object beforehand. CSS is not a programming language and therefore won't accept any arguments other than enumerated values and literals.

    You're asking CSS to solve a puzzle for you which is "fit these elements into a square as best as possible."

    There might be something javascript-y.

    What's the practical application of this if not demonstrative?

    Rye on
  • Options
    RothgarrRothgarr Registered User regular
    edited January 2010
    I sort of had a feeling it wasn't possible with CSS...

    For now, I'm just doing proof of concepts before coming up with a new design that'll be hard to implement and upkeep. I can always ask one of the coders to come up with a script if I go in this direction. I was just curious if there was a way of doing this by telling something to be 100% height and it would inherit the height of the tallest item in a row or something.

    No biggie. Just a thought.

    Rothgarr on
  • Options
    RyeRye Registered User regular
    edited January 2010
    CSS heights can only grab heights relative to their parent container. In the case of wrapping, 100% means the total new height, and the non-wrapped height is overwritten.

    No CSS element is aware of the dimensions or properties of other elements, only their parents.

    Rye on
  • Options
    JacksWastedLifeJacksWastedLife Registered User regular
    edited January 2010
    If you layout isn't liquid and you want to keep 2 rows of 4 columns always, wrap the first row in a <div> and the second row in a <div>

    JacksWastedLife on
  • Options
    darkgruedarkgrue Registered User regular
    edited January 2010
    Wait... I've actually done this (actually, what I was attempting was a scrollable table, but the core need was basically the same). And no, it can't be done with only CSS. I researched the crap out of this, I don't think the answer's changed.

    My solution involved Javascript, and the secret sauce was using 1px blank images as shims to force the table renderer to make the column widths actual. Basically, the Javascript iterates over the columns (or rows, or both - same solution just more looping really), finds the largest column width, then rewrites the DOM to resize the columns. inserting a tiny image shim to force the page renderer to heel ensures it looks right.

    It was a BITCH to code. Especially since at the time I wasn't all that great at Javascript. I think it took a month of refining to make it work, and the cross-browser solution was painful. There were all sorts of peculiarities and glitches before I got it working right. Tables are not intuitive or implemented consistently.

    It wasn't fun, but I did end up with a pretty unique solution that I was happy with.

    darkgrue on
  • Options
    flatlinegraphicsflatlinegraphics Registered User regular
    edited January 2010
    the closest pure css solution you are going to find will involve using a height somewhere:
    <style>
    #container{overflow:auto;background:#cff;height:200px;}
    #container div{float:left;height:inherit;width:100px;background:#ccc;margin:0 10px}
    </style>
    <div id="container">
    <div>fedmsiougnfuisg nuifbg jfig fngs nfyurvb ufzob </div>
    <div>fedmsiougnfuisg nuifbg jfig fngs nfyurvb ufzob fedmsiougnfuisg nuifbg jfig fngs nfyurvb ufzob </div>
    <div>fedmsiougnfuisg nuifbg jfig fngs nfyurvb ufzob fedmsiougnfuisg nuifbg jfig fngs nfyurvb ufzob fedmsiougnfuisg nuifbg jfig fngs nfyurvb ufzob </div>
    <div>fedmsiougnfuisg nuifbg jfig fngs nfyurvb ufzob </div>
    </div>

    otherwise, you are looking at massively stupid hacks.

    in the case of tabular data, use a table! i'll forgive you!

    flatlinegraphics on
  • Options
    protozoiderprotozoider Registered User regular
    edited January 2010
    I don't know who started this concept of everything has to be CSS but it's stupid. Just make a table. It's not worth rattling your brain over and over thinking there just has to be a way. I've tried to do insane things with CSS that aren't supposed to happen but it took massive amounts of time. Just use a table. Do yourself a huge favor and use tables for things like this. CSS just doesn't have enough control over page spacing and layout and it differs too much between browsers. Tables are easy and consistent. I'm not saying do the whole page in tables, just the elements that would be difficult in CSS.

    protozoider on
  • Options
    RothgarrRothgarr Registered User regular
    edited February 2010
    The reason I can't use a table is because although it's not a liquid layout I need the lists (that output is a list) to wrap depending on where its being viewed.

    For example, on screen that list might be three listings across. When printed, it might be four. When viewed on a mobile device, it might only be two across. So it needs to wrap dynamically.

    It looks like I'll be able to do this dynamically with some javascript -- even without shims no less. (I can't do it but one of the coders on the team can do it). But I wanted to see if there was a way with CSS -- i thought maybe there was some min/max height that could be inherited somehow but it makes sense that it can not.

    Thanks, guys!

    Rothgarr on
  • Options
    TejsTejs Registered User regular
    edited February 2010
    I'm trying to understand the reasoning for this. Why not just force your element containers to be the same height? You can fill the containers with whatever you want, but the containers themselves would all be the same height and thus wrap easily.

    Tejs on
  • Options
    darkgruedarkgrue Registered User regular
    edited February 2010
    Tejs wrote: »
    I'm trying to understand the reasoning for this. Why not just force your element containers to be the same height? You can fill the containers with whatever you want, but the containers themselves would all be the same height and thus wrap easily.

    Works great if you know what the maximum height/width is in advance. Getting this to work for static pages is trivial, true.

    However, if the content is generated dymanically, you have to calculate it, which is what you use the Javascript for. That's when the more exotic, and painful work comes in.

    darkgrue on
Sign In or Register to comment.