1

I'm creating a menu bar on my website. My issue is that there is a small margin at the side of one of my menu items. (I have highlighted this by adding background-color: black; to the container.) I am using safari.

margin issue

The CSS:

.testMenuOption{
  width: calc(100%  /3);
  height: 100%;
  float: left;
  margin:auto;
  background-color: white;
  display: table;
}

Can somebody tell me what my issue is? I have tried removing the text and it is not the issue.

2 Answers 2

4

Since you calculate the width by using 100/3, there will be rounding errors, where as a result the widths wont add up 100% again. What you can do to fix it is to set the width of two of the .menuOptionsWraps to 33% and one to 34%.

For example by doing so:

.menuOptionSelectedWrap {
    float: left;
    width: 33%;
    height: 100%;
    margin: auto;
    margin-right: -4px;
    background-color: #d6eef2;
    display: table;
}
.menuOptionSelectedWrap:last-of-type {
    width: 34%;
}
3
  • 1
    width: 33.33333333% should work as well, Bootstrap does that for example.
    – AlexG
    Commented Aug 2, 2016 at 11:34
  • Surely 33.33333333% is never going to be completely accurate?
    – x3nr0s
    Commented Aug 2, 2016 at 11:38
  • 1
    That depends on the total size of the container. If the remaining 0.0000001% of space is less then what it takes the browser to render it as a pixel, i shouldn't be visible. But you can probably already guess how absurdely big such a container must be to render that pixel.
    – Fabian S
    Commented Aug 2, 2016 at 11:43
1

I'm not sure what you say,that black line change when window resize.check your css, width: calc(100% /3); change the value 3,you will get idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.