Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong margin-bottom value when use offset #382

Open
pryann opened this issue Jun 30, 2017 · 8 comments
Open

Wrong margin-bottom value when use offset #382

pryann opened this issue Jun 30, 2017 · 8 comments

Comments

@pryann
Copy link

pryann commented Jun 30, 2017

Is this a feature request or a bug report?
Bug

Hello,

If I create a simple grid:

<div class="main"> 
        <div>lorem</div> 
        <div>lorem</div> 
</div> 

Than I format them:

.main {
  lost-center: 1000px 15px;
  height: 100%;
}

.main > div {
  lost-row: 1/3;
}

.main div:first-child {
  lost-offset: 1/3 column;
}

The second div is out of the main div.
I attached a file.

Thanks.
lostgrid

@peterramsing
Copy link
Owner

@pryann Could you do us a favor and do some cross-browser testing on that and determine that it does that for other browsers?

@pryann
Copy link
Author

pryann commented Jun 30, 2017

@peterramsing Yes of course. I checked in Chrome 58, Firefox 53, Opera 46, Edge, the result is same, but if you would like, I will create a complex cross bowser test.

@peterramsing
Copy link
Owner

@pryann That's good enough. Just wanted to make sure it wasn't a browser specific rounding.

@pryann
Copy link
Author

pryann commented Jul 1, 2017

@peterramsing No, it doesn't a browser specific issue. If I make 3 row (lost-row: 1/3) everything if perfect, but if I use offfset, the margin-bottom value is wrong (calc(99.9% * 1/3 - (30px - 30px * 1/3) + (30px * 2)) !important).

@peterramsing
Copy link
Owner

@pryann If you want to jump start the fix could you write some failing tests for this?

@peterramsing peterramsing self-assigned this Jul 2, 2017
@pryann
Copy link
Author

pryann commented Jul 2, 2017

@peterramsing I found what is the problem, and I know the solution.

The example:

<div class="main"> 
        <div>lorem</div> 
        <div>lorem</div> 
</div> 
@lost rounder 100;

.main {
  lost-center: 1000px 15px;
  height: 100%;
  background: #faa;
}

.main > div {
  lost-row: 1/3;
  background: #aaf;
}

.main div:first-child {
  lost-offset: 1/3 column;
}

The height of the main div is 100% (in this case 974px).
The height of the child divs are: calc(100% * 1/3 - (30px - 30px * 1/3)) = 304.656px
The margin-bottom of the first div is: calc(100% * 1/3 - (30px - 30px * 1/3) + (30px * 2)) = 373.328px;
So: 2 * 304.656px + 373.328px = 982,64px. It is too much.

You use the next formula in the lost-offset.js file, line 83:

 value: 'calc(' + lostOffsetRounder + '% * '
            + lostOffset + ' - (' + lostOffsetGutter + ' - '
            + lostOffsetGutter + ' * ' + lostOffset + ') + ('
            + lostOffsetGutter + ' * 2)) !important'
          });

A the third row causes the problem. ((30px - 30px * 1/3)). If you subtract only just the gutter, the problem is solved. This works for me.
Just modify in to the next:

value: 'calc(' + lostOffsetRounder + '% * '
            + lostOffset + ' - ' + lostOffsetGutter + ' + ( '
            + lostOffsetGutter + ' * 2)) !important'
          });

I cheked the negative offset value too.

Example:

.main > div {
  lost-row: 1/3;
  background: #aaf;
}

.main div:first-child {
  lost-offset: -1/3 column;
}

The problem is same.
The margin-top value is: calc(100% * (-1/3 * -1) - (30px - 30px * (-1/3 * -1)) + 30px)

You use the next formula in the lost-offset.js file, line 97:

value: 'calc(' + lostOffsetRounder + '% * ('
            + lostOffset + ' * -1) - (' + lostOffsetGutter + ' - '
            + lostOffsetGutter + ' * (' + lostOffset + ' * -1)) + '
            + lostOffsetGutter + ') !important'
          });

But the next works perfectly for me:

 value: 'calc(' + lostOffsetRounder + '% * ('
            + lostOffset + ' * -1) + '
            + lostOffsetGutter + ') !important'
          });

Please check it. I hope it will work.
Thanks.

@peterramsing
Copy link
Owner

It looks like there might be something more wrong here... I'm not able to replicate your issue but instead am getting something worse.

I'm thinking I might need to tear up that code and figure out what the heck is going on...the maths is all wrong.

<div class="main">
  <div>first</div>
  <div>second</div>
</div> 
@lost rounder 100;

.main {
  lost-center: 1000px 15px;
  height: 500px;
  background: #faa;
}

.main > div {
  lost-row: 1/3;
  background: #aaf;
}

.main div:first-child {
  lost-offset: 1/3 column;
}

screen shot 2018-03-17 at 10 56 31

@peterramsing
Copy link
Owner

The update on this is that I spent several plane rides trying to figure out what's what w/o any CSS documentation to read about what is actually happening. My next steps are to see how Bootstrap and other grids do the same thing and see if I can figure it out that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants