Table borders not properly rendered when td is position:relative - html

I'm having problems with table borders not always rendering correctly when the following conditions are met:
The table is contained within a div with overflow-y:scroll
Borders are collapsed on the table
elements are styled position:relative
As near as I can tell, this is occurring only on Chrome (Version 54.0.2840.98 on Mac OS 10.11.6). I've tested on Safari and Firefox with no issues.
I've managed a minimal case in JSFiddle (https://jsfiddle.net/5a0a4sL1/24/). The code looks like this:
.scroll {
background-color:white;
overflow-y: scroll;
width: 300px;
height: 200px;
}
.wrapper {
height: auto;
width: 280px;
padding: 10px;
margin: 0px;
}
table {
width:90%;
margin:0px 5%;
border-collapse:collapse;
}
td {
position:relative;
border:1px solid black;
}
<div class="scroll">
<div class="wrapper">
<table>
<tbody>
<tr><td style="height:39px;"></td></tr>
<tr><td style="height:75px;"></td></tr>
<tr><td style="height:111px;"></td></tr>
<tr><td style="height:39px;"></td></tr>
</tbody>
</table>
</div>
</div>
The page looks like this when there's an issue:
Here the borders for the bottom row-and-a-bit of the table are failing to render, though table contents would show if there were any. The presence and severity of the issue depend on the size of the Chrome window, which make me think this is a bug in the browser.
My question is this: Is there anything in the code that looks like I'm obviously abusing the browser? Any tweaks that might accomplish the same task (the position:relative is required for the placement of resizing handles) without making Chrome angry? Or is this just a clear browser bug?
Edit: I believe this isn't the "table borders disappear with position:relative" issue discussed here, for example. Borders for table cells are often partially rendered, and the issue disappears if (for example) scrolling in the y direction is removed.

I replicated the problem. The rendering is different in each browser. It could be a browser bug.
A simple workaround to get it to work perfectly in all browsers would be to add <div> inside each td and style them with position: relative. And if you want the div to take same height as the td, then also give them height: 100%.
Here's a demo.
Off-Topic Note (kind of relavant to the cause of the problem):
When you give padding 10px to an element with width 300px, the actual width becomes 320px. And if you give it border 1px, the actual width will be 322px (border left 1px and border right 1px). To get an actual 300px with padding 10px and border 1px, give the element this attribute: box-sizing: border-box;. Same concept applies for "height".
For example, when you gave an element height 39px and border 1px, the actual height is 41px (1px top border + 1px bottom border). If you add box-sizing: border-box to the td, then the height would be 39px.

Related

written Border vs shown Border

I've got a Problem with simple plain html/css Borders.
If i do something like that:
#demoDiv {
border: solid 1px black;
background-color: green;
width: 100px;
height: 100px;
margin: 0;
padding: 0;
}
This cssText will style the div-element with the ID "demoDiv" to a green box with black border. The Box should be 102 px heigh and 102 px width, right?
But now comes my Problem.... Firefox tells me, that this box is 101,6px heigh and width.
The only border-width, that is working is "0" - the others had to be multiply by 0.8.
This is because you didn't set the box-sizing: border-box to your page. By default all Html pages content-box set in the box-sizing which simply means that it calculates the all sizes from the margin box to content area box. Make sure to learn more about it as it will useful for in the future.You learn more about border-box from the Mozilla- Mdn.
I found the solution here:
What could make Firefox render an incorrect border width? to sum it up: Firefox renders the border-width on zoom.Thanks for responding

Table width 100% is off by a single pixel (depending on actual width)

I have a table in a div inside another div. The direct container has a width of 40%, and I want the table to be as wide as this div, by setting width: 100%.
Relevant Markup
This works most of the time, however depending on the width of the browser window, the width of the table is sometimes off by a single pixel:
As you can see to the right, the border is a pixel to the left of that of the sibling div .info. These borders should align.
Relevant CSS
#userListContainer{width: 40%; float: left; }
.info{display:block;line-height:22px; height:22px; padding-left:10px; }
#userListContainer .info {border-right: 1px solid #999999;}
.userList {
width: 100%;
border-right: 1px solid #999999;
word-break: break-all; border-spacing: 0;
border-collapse: separate;
}
Seems like a rendering bug to me. It occurs in Chrome 34.0.1847.131, not in IE10. I can't reproduce it in IE10 or the current version of FireFox.
The error replicates here for me on CHROME.
I inspected the element, and what I noticed is, the width of the table box was 217.443 px (obviously due to the % widths)
in the inspect element HTML section, it defines the width of the table as 218 px, and the containing div as 217px..
When I expand the broswer window slightly, thus making the table width increase past 217.443 px, to 217.680 px,
the HTML section displays BOTH the table width and the containing div as 218 px.
so im guessing the browser is rounding the pixels off to the nearest whole pixel.
could this be the right route to investigate?
edit: Try this and see if this works for you. I have fixed the problem (I think) in this jfiddle
http://jsfiddle.net/E2mUQ/3/
I simply removed the width on the .table class, and relaced it with DISPLAY:block
I had the same problem and managed to solve it by setting the width slightly higher:
width: 100.12%
I made an attempt to make the extra percentage small enough to solve most cases, but not create an overflow of 1 px.
It worked for me. This is somewhat of a dirty fix though.
I think it's to do with inset/outset borders - which are different between browsers. Try applying a border to the parent div instead of the table. This should sort it out.

Fluid layout with margin-bottom and nested div 100% height issues

I'm in the process of transforming an existing fixed layout to be "fluid".
I've got 2 issues:
When #content contains a lot of data, which makes it expand over the viewport I can't find a way to have a margin at the bottom.
The #content seems to "loose" it's height when position:relative; is added, which is necessary to place #content on to of #topgradient. I need #test (blue border) to fill #content and #content needs to fill #contentwrapper.
I've got an existing fixed layout which works great, the issues began after I added/changed height: auto; min-height: 100%; on the divs.
See this sort of messy/prototyping jsfiddle: http://jsfiddle.net/bQeu3/2/ (click in the white area (#content) to change content)
The optimal solution on issue 1 would look like:
The optimal solution on issue 2 would look like:
Hope you can help?
for the first question:
http://jsfiddle.net/bQeu3/7/
remove height:100% from #page
add padding:1px to #page
add margin-bottom:100px to #contentwrapper
to keep the size of #contentwrapper when you clicked something:
#test{
min-height: 300px;
border: 5px solid blue;
margin: 5px;
}
you might need to correct the 300px considering borders and such...

CSS Border radius not trimming image on Webkit

I'm having trouble figuring out why border-radius is gone from my #screen element when using chrome but not firefox or ie9?
I have all the different prefixes for each browser plus the standard border-radius:
www.cenquizqui.com
The upper content box that holds the pictures, called #screen
a copy paste of screen's css:
#screen {background: none repeat scroll 0 0 #EEEEEE;
display: block;
height: 300px;
position: relative;
width: 960px;
overflow:hidden;
-moz-border-radius:10px;
-webkit-border-radius:10px;
-o-border-radius:10px;
border-radius:10px;}
Is it because chrome does not handle the 'trimming' of the images properly? I thought it was only a problem when you had the actual tags inside the rounded corner container, not when the img is called as background-image through css.
Regards
G.Campos
Here's a workaround that will fix the current chrome bug:
.element-that-holds-pictures {
perspective: 1px; /* any non-zero value will work */
}
This won't affect the display at all (unlike the opacity:0.99 workaround - which is great workaround, too, by the way).
Webkit cannot handle border-radius cropping for children and grand-children+. It's just that bad. If you want border cropping, it has to be directly on the div the image is placed on without going any deeper down the hierarchy.
There is a much simpler solution.
Just add overflow:hidden to the container that has the border-radius and holds the child elements. This prevents the children 'flowing' over the container.. Thus fixing the problem and showing the border-radius
Try the following css to the child elements of the element with border-radius set:
opacity:0.99;
It solves the problem and doesn't change the opacity much.
This worked perfectly for me.
It looks like you need to apply the border radius to the li element:
#slides li {
display: block;
float: left;
height: 300px;
width: 960px;
position: relative;
border-radius: 10px;
}
It very much does have a border radius:
(I just added a border with Chrome's dev toolbar.)
The border radius doesn't restrict its contents to within the resulting area—the space outside the corners are still occupiable by the element's contents.
My recommendation would be to overlay an image that had the corners cut out like that (and then use a map or whatever you feel comfortable with to still enable the left/right arrows).

How to create a 3 columns fluid fixed fluid layout?

I'm looking for a 3 column css layout, with 1 fixed section at the middle and 2 fluid sidebar around it:
http://www.uploadup.com/di-UEFI.png
middle has 250px width (for example) and sidebars have (at minimum) 150px width. if browser width was longer than 550px (250+300), sidebars should have a longer width. (and middle always is 250px)
What is the CSS can do it? with compatibility in all browsers.
note: i saw this page, but i don't know how to change it for my wish
You can try to use inline-blocks for it. They are used rather rarely, but sometimes they are pretty good for layouts.
So, look at this: http://jsfiddle.net/kizu/UUzE9/ — with inline-blocks you can create layouts with any number of fixed and fluid columns. The algorithm:
At first, you add the padding equal to the sum of all the fixed columns to the wrapper. In your case — 250px.
Then, you add min-width to the wrapper equal to the sum of all the fluid columns' min-width.
Then, you add white-space: nowrap to the wrapper, so the columns won't jump.
And then just add the all columns that you need.
If you need support for IE7 and lesser, there are some additional things to know except for common inline-block fix:
You must return white-space: normal to the inner child of a column, or the columns won't stay on one line.
There can appear a phantom scroll in IE, maybe there is a better way to remove it, but I just use overflow: hidden on some wrapper.
Enjoy :)
To make this work in IE6/7 without JavaScript, the easiest way to do this is with a table.
I know, I know. It's not that bad in this case, all considered.
See: http://jsfiddle.net/thirtydot/Q2Qxz/
Tested in IE6/7 + Chrome, and it will just work in all other modern browsers.
HTML:
<table id="container" cellspacing="0" cellpadding="0">
<tr>
<td id="left">fluid</td>
<td id="mid">fixed</td>
<td id="right">fluid</td>
</tr>
</table>
CSS:
html, body {
margin: 0;
padding: 0;
border: 0
}
#container {
border: 0;
table-layout: fixed;
width: 100%
}
#container td {
vertical-align: top
}
#mid {
width: 250px;
background: #ccc
}
#left {
background: #f0f
}
#right {
background: #f0f
}
If you don't use one of the ready templates out there,
You can start by three div floated left, the middle with width: 250px and the outside ones with
min-width: 150px
You might want to replace it with the <section> tag, just give it a display: block