-1

I have a page with a container div, this container div has two columns, both inline-blocks. One column (left Hand side (LHS)) is the ticbox selection for a shopping catalogue, the right column is the output of the chosen selection.

The issue I have is that each is assigned a width based on percentage of the parent width, the left - fixed column is 20% width, the right, output column is 79% width (I tend to allow 1% for variability) . BUT: the left column needs a minimum width - defined in px as 155px; The right hand side (RHS) column is filled with inline-blocks for each product displayed by the catalogue search. These blocks are fixed width (140px)

MY ISSUE: When the page loads on my screen it's fine, but when:

LHS: min-width:155px < width:20%

(the browser window is resized)

The whole of the right hand side drops below the content of the left hand side (as the width for it is less than the required 79%.

Some simple example: Please note there is no borders or paddings to be considered when measuring widths.

HTML:

<div id="container">
    <div class="leftsideMenu">Menu column.</div>
    <div class="rightsideShop">Shop Contents</div>
</div> 

CSS:

#container{
    width:80% /* of screen */
    min-width:555px; /*should leave 400px for shop contents */
}

.leftsideMenu {
    display:inline-block;
    width:20%;
    min-width:155px;
    vertical-align:top;
}

.rightsideShop{
    display:inline-block;
    width:79%;
    max-width:calc(100% - 156px) !important; /* fix attempt - doesn't appear to work */
    vertical-align:top;
}

[Some] ATTEMPTED FIXES (not in order of attempt):

1) Calc to make the max-width always less than 100%-155, doesn't appear to work

2) Floats and margins : this does work but presents the problem of layout that the client doesn't want shoes underneath the LHS column and float height = 100% parent is another issue,

3) I have also tried to use https://stackoverflow.com/a/6350781/3536236 answer to a similar question - with the approach of having the RHS relative and using a forced LHS margin but this doesn't work as the solution linked here didn't work for me in this situation.

4) I think flex-box style working is probably a best way forward but I do not know enough about it, and to be brutally honest, I was hoping to avoid a massive reworking of the page CSS. (I had originally expected this issue to be 30minutes!).

5) Setting no width (just max-width) for RHS - to auto defined width, this auto defines to 100% and goes underneath the left hand side column.

I think the answer is pretty simple but I can't see it :(.

To explain parts for the points above, the LHS was originally a float and that worked fine but the client wanted no products appearing underneath the menu in the LHS column, so I thought - ah simple, make it an inline Block....

Any help as to keeping the right hand side giving the left hand side the space it needs, even upon screen resizing?

............

OH FOR FFFFFFFF SAKE -- I have just written this all out, and while I've been writing this have been trying different ideas as they've occured and it's finally worked:

Now after all this effort for writing this out I want to post it anyway, but the Solution is below!!!

Community
  • 1
  • 1
Martin
  • 22,212
  • 11
  • 70
  • 132
  • Yeah I suspect that's best, but its ultra-frustrating as I get the solution just as I'm about to post. Although the solution works, it has it's own curious issue with spare spacing (in my answer below) – Martin Nov 28 '14 at 14:28
  • If you have a new issue and this was solved while typing the question, delete this question (as you never needed an answer) and post a new question about the new issue. Thanks – Simply Craig Nov 28 '14 at 14:29
  • "this question has answers and can not be deleted". I will reformat instead.... although to be honest the newer issue is just a quirk of CSS – Martin Nov 28 '14 at 14:30
  • 2
    Even if was frustrating for U is useless now for SO .... is just your specific case and you already have the answer. – DaniP Nov 28 '14 at 14:31
  • possible duplicate of [How to remove the space between inline-block elements?](http://stackoverflow.com/questions/5078239/how-to-remove-the-space-between-inline-block-elements) – Paulie_D Nov 28 '14 at 15:48
  • I have requested a mod deletes this question. @Paulie_D I was only aware this was the issue, once I'd solved it!! – Martin Nov 28 '14 at 15:52

2 Answers2

3

OH FOR FFFFFFFF SAKE -- I have just written this all out, and while I've been writing this have been trying different ideas as they've occured and it's finally worked:

For some reason my calc works with:

 max-width:calc(100% - 160px); Giving a spare space of 5px . 

Any ideas why this is so, as I say, within the container div standard widths are percentages and there is some padding in the product container (inline-blocks) inside the RHS, but this really shouldn't have influenced having to add more "padding" space in the calc method.

Anyway, it works now. I'm happy. Maybe this will help someone?

Martin
  • 22,212
  • 11
  • 70
  • 132
  • I think that this "5px" is rather equivalent to the 1% leway I give dimensions as percentages. – Martin Nov 28 '14 at 15:37
3

With inline-block you will have some whitespace taking up some space in your layout.

Two inline-block divs with a width of 400px in a container div of 800px won't always render next to each other.

You can fix this by making sure the closing tag of an element is directly next to the opening tag of the next element in the HTML (e.g. </div><div>, no newlines or spaces).

A better option is to apply font-size: 0 to the containing element and then reset the font-size to e.g. 1rem for the inline-block elements.

  • That appears to be the issue in this case, I do leave 1% for layout variability, but I think I need to leave more pixels on pixel width for the same issue. cheers. – Martin Nov 28 '14 at 14:29