One pixel wide artefact using Bootstrap grid with backgrounds - css

I'm not going to try to explain this in words, just have a look at this fiddle:
https://jsfiddle.net/fhf8rwno/4/
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="myBox" style="height:100px;background-color:#000;">
<div class="row no-gutter">
<div class="col-xs-7">
blbalbalabla
</div>
<div class="col-xs-5" style="height:100px;background-color:red;">
wowowowo
</div>
</div>
</div>
</div>
</div>
</div>
In either Chrome or Firefox (possibly other browsers too), watch the red column as you resize the browser width. You should notice that on every other change in browser side a one-pixel-wide gap appears at the right edge of the parent container, allowing the parent background to come through.
If I instead use col-xs-6 instead of col-xs-7 and col-xs-5, the issue disappears. So it seems the browser's pixel math may cause this due to the odd/even mix of column ratios.
This may not seem like much, but the site I'm working on uses this pattern a lot and half the users are seeing some very noticeable and unsightly dark lines.
Any thoughts or suggested hacks?

Edit: here's a hacky way of achieving this. http://jsfiddle.net/fhf8rwno/8/
CSS
.row.no-gutter {
margin-left: 0;
margin-right: 0
}
.row.no-gutter [class*='col-'],
.row.no-gutter [class*='col-'] {
padding-right: 0;
padding-left: 0;
}
HTML
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="myBox" style="height:100px;background-color:#000;">
<div class="row no-gutter">
<div class="col-xs-7">
blbalbalabla
</div>
<div class="col-xs-5" style="height:100px;background-color:red; position: relative; right: -1px;">
wowowowo
</div>
</div>
</div>
</div>
</div>
</div>

A colleague and I have come to a semi-solution, but I'm not going to accept this answer just yet in case someone comes up with something less hack-y.
Shifting the last column's margins by one seems to help the issue:
.row.no-gutter [class*='col-']:last-child {
margin-right:-1px;
margin-left:1px;
}
https://jsfiddle.net/fhf8rwno/6/

Related

Canvas positioning

I build a small app using Bootstrap 5. There are 10 columns col-lg-10 on the left and 2 columns col-lg-2 on the right on the desktop view. The canvas clock is to be located in the centre of the most right columns. At the moment the clock is not centred and any CSS I apply does not seem to work. Please see the HTML code:
'''
<section>
<div class="container-fluid">
<div class="row">
<div class="col-lg-10 col-md-6 col-sm-12">
</div>
<div class="col-lg-2 col-md-6 col-sm-12 mx-auto">
<!-- analog clock location -->
<div id="clockContainer">
<canvas id="analogClock"></canvas>
</div>
</div>
</div>
</div>
</section>
'''
I tried to centre the canvas clock using bootstrap classes. The class="mx-auto" class was applied on the div with an id="clockContainer". But this does seem to solve the problem.
Later, I linked the CSS file and tried to do the following (non of the below solution worked):
#clockContainer{
margin: auto;
width: 250px;
}
#analogClock{
width: 250px;
}
I tried also:
#clockContainer{
width: 250px;
margin: auto;
}
Any hints on how to resolve it?
Thanks!

Flex content width not calculated correctly inside a position: fixed container in IE11

I'm building a custom tooltip that uses position: fixed and a dynamic top and left to follow your mouse cursor around. The tooltip has a relatively complex layout built with flexbox. I'm having an issue with IE11 (which otherwise supports flexbox just fine using autoprefixer) where the width of the tooltip is getting collapsed down as if it had no content.
I made a Codepen stripping out all my implementation details except for the most basic Bootstrap layout and CSS, and the issue is still present. You can see it in action here https://codepen.io/ryangiglio/pen/xajLJr. Here is the code:
HTML
<!-- Regular content -->
<div class="container-fluid">
<div class="row">
<div class="col-4 text-center">
Column
</div>
<div class="col-4 text-center">
Column
</div>
<div class="col-4 text-center">
Column
</div>
</div>
</div>
<!-- Tooltip content -->
<div class="custom-tooltip">
<div class="container-fluid">
<div class="row">
<div class="col-12 text-center">
Tooltip Title
</div>
</div>
<div class="row">
<div class="col-4 text-center">
Column
</div>
<div class="col-4 text-center">
Column
</div>
<div class="col-4 text-center">
Column
</div>
</div>
</div>
</div>
CSS
.custom-tooltip {
position: fixed;
top: 50px;
left: 50px;
background: white;
box-shadow: 0 0 5px 1px black;
}
This is how it looks in Chrome
And how it looks in IE11
Unfortunately, I didn't care enough about the underlying issue here to spend too much more time solving it, so I ended up hard-coding a width on the .custom-tooltip class which solved the problem enough for me to ship it.
The link you provided was not valid cause I'm not a pro member.
On another note, I'm not sure, but it could be that when you set the box shadow property it changed the display, but I'm not sure and wanted to test that theory out but couldn't.
--- Edited
Try the below code you have to also make sure you correctly set the flex-direction property.
div.custom-tooltip{
display: flex;
flex-direction:column;
}
div.row{
display: flex;
flex-direction:row;
}
--- EDITED ANSWER ---
/*
I set the tooltip box containers
width to be a percentage, I don't
know if this a documented issue
with ie11 or not, where ie 11
doesn't realize that flex is being
used on a fixed element and goes with
default values for width.
*/
div[data-tooltip-boxwidth="300"] {
width: 20%;
}

How to create two rows in a bootstrap without scrolling using one with pixel and another with percentage?

How to create two rows in a bootstrap without scrolling using one with pixel and another with percentage ?
<div class="container-fluid">
<div class="row main_header">
sadf
</div>
<div class="row main_second">
<div class="col-lg-2 main_left">
test
</div>
<div class="col-lg-10 main_right">
test
</div>
</div>
</div>
How to create two rows in a bootstrap without scrolling using one with pixel and another with percentage ?
.main_header{
height: 80px;
background-color: #606060;
color: #fff
}
.main_left{
height: 100%;
background-color: #D8D8D8;
} .main_right{
height: 100%;
}
.main_second{
height: 100%;
}
I think you don't need to use any additional CSS to achieve what you want as Bootstrap already have a very established Grid System. Please see my following example in the following fiddle!
All what I have used is the following lines with Twitter Bootstrap V3.3.4:
<div class="row">
<div class="row">
<div class="col-sm-4" style="background-color:red;">.col-sm-4</div>
</div>
<div class="row">
<div class="col-sm-4" style="background-color:lavender;">.col-sm-4</div>
</div>
</div>
And you can add any additional divs within those two divs.
Learn about the Grid System very well to use this via these kind of tutorials.
And it's better to look at the following StackOverflow answer, I guess.

Contents in a vertical table-style div arrangement

I have some divs that should take the entire height of a page. I managed to get this working as i needed. (Some fixed rows and some flexible rows) like in a html table.
I took the solution from one of my other questions here:
Layout divs in css like table cells in HTML Tables
Today i had to add a div inside the flexible row which should take 100% of the height of the flexible row. Which works great in all major browsers. Muahaha that was a good joke wasn't it? Of course this doesn't work as expected in IE see my js fiddle:
<div class="tableContainer">
<div class="row rowA">
<div class="cell">Test</div>
</div>
<div class="row rowB">
<div class="cell">Test</div>
</div>
<div class="row rowC">
<div class="cell">Test</div>
</div>
<div class="row rowD">
<div class="cell testcell">
<div class="testcontent">Test</div>
</div>
</div>
<div class="row rowE">
<div class="cell">Test</div>
</div>
</div>
http://jsfiddle.net/7ewEJ/3/
the ie seems to take the "100%" from the page and not from the enclosing flexible table row. So the blue div should take the whole space of the purble table row.
Am i doing anything wrong?
Could this be a bug in ie's height calculation?
http://jsfiddle.net/7ewEJ/5/
div.testcell{
height: 100%;
width: 100%;
min-width: 1px;
min-height: 1px;
/*background: #fff;*/
align: center;
display: block;
}

CSS background diappearing when Overflow is Visible

I have a site that has the following basic structure. This site should have a background that is white, with an image that apears once, but instead it just inherits the colour from the html{ } declaration in CSS. All elements below the element that should have the background are transparent, and even though the background is being added (checked in Firebug), it seems that this is below the background defined in html{ }.
This has only happened since I removed the declaration overflow: none; from #content-container, where as before that it worked. I need to remove this however, as changes that are occuring to the site require the nav menu to have dropdowns, so the container below has to allow overflow.
Is there a specific CSS reason why this is happening? Or anything else I need to provide for someone to be able to help? Thanks.
<div id="main-container">
<div id="header-container">
<div id="header-top">
{Code}
</div>
<div id="header-middle">
{Code}
</div>
<div id="header-nav">
{Code}
</div>
</div>
<div id="content-container">
<div id="content-left" class="index">
{Code}
</div>
<div id="content-right">
{Code}
</div>
</div>
<div id="footer-container">
{Code}
</div>
</div>
I'm guessing that #content-left and #content-right elements are floated? In which case the overflow: none on the #content-container was causing the element to self-clear. Without this, the element will not have a height because all the elements within it are floated, and therefore the containers' height cannot be calculated.
If you must use overflow: visible, the workaround is to place a div at the end of the containing element with clear: both set on it:
<div id="content-container">
<div id="content-left" class="index">
{Code}
</div>
<div id="content-right">
{Code}
</div>
<div class="clear"></div>
</div>
.clear { clear: both; }

Resources