I am wondering why there is a significant difference in rendering CSS between Chrome and Firefox. In case of Chrome, the child element is not taking full width and height (black color of parent can be seen at top and left side of child). In case of Firefox, the edges are smooth and child's dimensions are the same as of parent. I have no idea why is this happening.
These are the screenshots on Chrome and Firefox to demonstrate:
Chrome:
Firefox:
Below is my code:
* {
margin: 0;
padding: 0;
}
.parent {
position: relative;
width: 200px;
height: 200px;
border: 10px solid white;
background-color: black;
}
.child {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: lightcoral;
}
<div class="parent">
<div class="child">Content</div>
</div>
I just want to know why this is happening and how it can be fixed so that it looks the same in all browsers.
PS: Use hardware acceleration when available is ON
Hey brother there are many transitions and stylings that works on only chrome and not on the Firefox ,
same is the case with firefox , (many transitions work on firefox but not on chrome) so the thing is , chrome and firefox has some different properties so you have to search on official docs or google to check which property will work on chrome and which will work on firefox
hope this makes sense
i will attach a code snippet that shows different transition properties for different browsers
text.identity{
transform: translate(74px,0px);
-ms-transform: translate(74px,0px); /* IE 9 */
-webkit-transform: translate(74px,0px); /* Safari and Chrome */
-moz-transform: translate(74px,0px); /* Firefox */
-o-transform: translate(74px,0px); /* Opera */
}
these are some transition properties for different browsers and this is for just an example
these lines works same but on their respective browser
Happy Coding!!
The black lines seem to occur because of the border being set on the parent.
While I don't entirely understand why this happens on some browsers and not others, and why it happens at some zoom levels and not others (at least on Chrome/Edge on Windows 10 on my laptop) I suspect it's because of the way the browser calculates the boundaries of a CSS border.
We aren't seeing a whole CSS pixel but what looks like a slimmer, perhaps one screen pixel width, line of black. And this can disappear, or one is shown on the right/bottom instead of left/top border, when zoom is increased or decreased. It's as if the algorithm for calculating where the border actually is in terms of screen pixels takes, for example, the n screen pixels used for one CSS pixel and takes the mid-point. I haven't found any explanation of what algorithms are used though.
Anyway, one observation which may or may not help in this practical situation is that if border is replaced with margin then there are no black lines.
* {
margin: 0;
padding: 0;
}
.parent {
position: relative;
width: 200px;
height: 200px;
background-color: black;
/*border: 10px solid white;*/
margin: 10px;
}
.child {
position: absolute;
top: 0%;
left: 0%;
height: 100%;
width: 100%;
background-color: lightcoral;
}
<div class="parent">
<div class="child">Content</div>
</div>
I have faced this issue before, In some cases when we use absolute position so it does not fit into the relative box in some browsers, so the solution for this is that you can add outline property in the element which has absolute position.
Pleas check below code:-
.child {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: lightcoral;
outline: 1px solid #fff;
}
Just replace your child element css with above code and let me know if it works.
Related
my border is moving when you have the download file ?tab? open on chrome (haven't tested it with any other browser). This completely destroys the look of my website, the text is still in the same position but the border and background moves up a bit.... I have tried every position but it didn't work... I'm really annoyed at this problem, any help would be appreciated.
here is the css code
.classA {
border: 5px solid;
text-align: left;
line-height: 0.5;
position: fixed;
height: 11%;
top: 110px;
right: 5px;
left: 5px;
}
This is simply how Chrome works when you start a download. You can work around this with css, but please provide us with some code or a demo with what you've already tried.
A quick thought:
The first thing that comes to mind is to not use percentage for your height property, since it takes 11% of the current height, which depletes when you get the download bar in your screen, since the download bar takes up space of your screen.
If you give the class a fixed height, for example 100 pixels, you will see the class won't decrease in height.
So the code will be:
.classA {
border: 5px solid;
text-align: left;
line-height: 0.5;
position: fixed;
height: 100px; /* just an example, does not need to be 100px */
top: 110px;
right: 5px;
left: 5px;
}
I'm trying to achieve the following in IE9, IE10, and IE11 (works perfectly on Chrome and FF):
In mobile mode, I have a main #container wrapper that holds the entire site contents and a nav side menu div which is inside the #container (cannot be moved out, btw), yet is not visible and is hidden off-screen. When a user clicks a menu open toggle button, it should slide the #container to the right, revealing the nav side menu div directly positioned to its left. The "sliding" is happening using translateX, which gets assigned as soon as the "open" class gets applied to it via the toggle. In the IEs, I'm getting the animation part as expected, but without a visible side nav (empty space only).
#container {
height: 100%;
position: relative;
transition: transform ease .5s;
width: 100%;
}
#container.open {
position: fixed;
transform: translateX(300px);
}
#nav-side-menu {
left: -300px;
height: 100%;
overflow: scroll;
position: fixed;
top: 0;
width: 300px;
}
The problem here is with the use of position: fixed inside a transformed element. Per the specification, when using fixed-positioned elements ...the containing block is established by the viewport. There is a debate as to whether transformed elements should be the containing block of fixed descendants, but Internet Explorer doesn't presently support this.
In this particular instance you could avoid the cross-browser complications by avoiding CSS Transforms altogether. Instead, try moving the containing element laterally using the left property. Below is my markup — which I believe to be a reasonable reflection of yours:
<article>
<nav>
<p>This is the navigation portion.</p>
</nav>
<section>
<p>This is the content portion.</p>
</section>
</article>
As described above, the following approach makes key use of a relatively positioned container, moved side-to-side by transitioning (supported since IE10) the left property. We're also using the calc function (supported since IE9) to determine better dimensions and offsets:
body {
margin: 0;
overflow-x: hidden;
}
article {
left: -300px;
position: relative;
transition: left 2s;
box-sizing: border-box;
width: calc(100% + 300px);
padding: 0 1em 0 calc(300px + 1em);
}
article.open {
left: 0px;
}
nav {
position: fixed;
width: 300px; height: 100%;
margin: -1em auto auto calc(-300px - 1em);
}
This approach yields a more consistent experience across both Internet Explorer, Chrome, and Firefox. The end-result can be viewed online here: http://jsfiddle.net/jonathansampson/vxntq8b1/
Is it ok yet to use this? How do I bullet proof it for older browsers?
height: -moz-calc(100% - 70px);
height: -webkit-calc(100% - 70px);
height: calc(100% - 70px);
Here is specifically what I'm trying to accomplish.
A Full Width / Fixed Height Header
A Slider that stretches full width and full height - minus the height of the header.
A headline block that is centered vertically and horizontally in the slider
A Controls block that is always a fixed height from the bottom of the slider
Here's an image of what I have been able to achieve so far. It's ALMOST perfect, except for the part in bold above. The slider (black area) currently stretches 100% height and flows behind the header, which isn't ok for images.
If I add padding or margin, it extends the slider height beyond 100% and I get a scrollbar. Using the height calculation above seems to fix it, but from my understanding, calc() isn't compatible with IE 7, IE 8, iOS 5 or lower, or Android.
Is there a better fix for this problem? jQuery is ok, but I'd prefer a CSS solution if one exists.
Here's my HTML:
<div class="header">
<h1>Header - Full Width + 70px Height</h1>
</div>
<div class="slider">
<div class="headline">
<div class="headline-container"><!-- for table-cell vertical centering -->
<h1>Headline Block</h1>
<p>Centered Horizontally & Vertically in the Slider Block</p>
</div>
</div>
<div class="controls">
<h2>Controls - Centered Horizontally & 40px from bottom of container</h2>
</div>
</div>
Here's my CSS:
html, body {
width: 100%;
height: 100%;
margin: 0; padding: 0;
}
h1, h2, p {
margin: 0;
padding: 0;
}
.header {
position: absolute;
width: 100%;
height: 70px;
background-color: #888;
z-index: 9999;
}
.header h1 {
color: #fff;
text-align: center;
}
.slider-desc {
color: #fff;
text-align: center;
margin: 15px 0 0;
}
.slider {
width: 100%;
height: 100%;
background-color: #000;
}
.headline {
display: table;
width: 100%;
height: 100%;
}
.headline-container {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.headline-container h1, .headline-container p {
background-color: #fff;
}
.controls {
position: absolute;
width: 100%;
bottom: 40px;
text-align: center;
background-color: yellow;
}
Finally, I made a fiddle in case you want to play around with it. Thanks for the help!
I don't like JavaScript functions to handle sizing/resizing of my HTML elements, but sometimes it's the only possible way.
You could try with a tabular structure, setting:
height: 100% to the table itself;
height: <what you want> to the table header (first row);
height: auto to the table content.
It should work as a fill-parent directive.
Hope it helps! :)
A simple vanilla JS piece could work for this (jQuery is too much of a hassle to load for such a small task):
document.getElementsByClassName("slider")[0].style.height = window.innerHeight - 70;
And obviously you need to position it 70px from the top.
Also remember to listen for window resize:
window.onresize = function () {
// Code above
}
If you really want jQuery,
$(".slider").height($(document).height() - 70);
$(window).resize(function () {
// Code above
});
Calc() is not supported by older browsers, such as IE7 or IE8, but can be emulated in older versions of IE using the non-standard expression() syntax.
Check out the browser support here: http://caniuse.com/calc
I'm a little late to this party, but for anyone looking for a way to get calc() into IE8, there isn't really any alternative to a polyfill. Microsoft removed support for the non-standard expression() statement:
Important Dynamic properties (also called "CSS expressions") are no longer supported in Internet Explorer 8 and later, in IE8 Standards mode and higher. This decision was made for standards compliance, browser performance, and security reasons.
Source here
This polyfill is tested in IE8
<musing>
I'm not entirely sure why MS decided for performance and 'security reasons' to remove the expression statement from IE8, they never really seemed to be concerned with performance before. Of course, it wouldn't even be an issue if they didn't make it necessary for organisations to build apps specifically for and reliant on it. You'd have thought they would have learned their lesson with IE6. Elaboration would be good.</musing>
I have problem with margin: auto - vertical centering
#something {
width: 97%;
height: 300px;
border: 1px solid red;
position: absolute;
top: 0;
bottom: 0;
margin: auto;
}
This work in every modern browser - when the page (viewport) is higher then 300px, its centered vertically, but, when the page(viewport) is lower then 300px stopped it works everywhere except in firefox... In firefox run it good (maybe it is bad functionalitiy, but its logical functionality) in other browsers the top of centered element disappers in the top of viewport.
http://jsfiddle.net/LhHed/2/ Here is god example - when you resize result window, in firefox work it well, in others browsers not. Is posible tu fix it? Or its bad functionality of firefox?
EDIT: live example http://dev8.newlogic.cz
From what I gather, you're wanting the top of the divider to display at the top of the page. This currently isn't happening because you have the position set to top:0; bottom:0;, the top property is conflicted by the bottom property, ultimately positions the divider to the bottom of the page. Simply removing the bottom property prevents the top of the element appearing outside of the viewport:
#something {
width: 97%;
height: 300px;
border: 1px solid red;
position: absolute;
top: 0;
margin: auto;
}
JSFiddle.
I removed the problem in browsers, when i use position: relative to the body element. Now its working in firefox and in other browser too. Live example on http://dev8.newlogic.cz
I have two div-elements, the top one has the height of 40% and the other one 60%.
In my example I have positioned the first one to top: 0; and the second one to bottom: 0;. My issue is that I get a 1px distance between them in Webkit, sometimes!
I have created a jsFiddle that recreates the issue in Webkit (Safari and Chrome, but works fine in Firefox.)
http://jsfiddle.net/bVxDA/ (Resize the window to see the bug in action)
This is the code I'm using.
HTML
<div id="cover-top"></div>
<div id="cover-bottom"></div>
CSS
html, body {
background: red;
height: 100%;
}
#cover-top,
#cover-bottom {
background: #000;
position: absolute;
width: 100%;
}
#cover-top {
height: 40%;
top: 0;
}
#cover-bottom {
height: 60%;
bottom: 0;
}
I would be fine with a solution that uses JavaScript or jQuery.
If the height of html, body height is an odd number there is a 1px line "remainder".
Webkit can't divide 1px and doesn't try.
See: http://jsfiddle.net/iambriansreed/gPu3Y/
You could make the 1px line disappear if you set the following:
#cover-bottom {
height: auto;
top: 40%;
bottom: 0;
}
this happens every time 40% isn't a whole number. lets assume your page is 98px height, so we get:
40% = 39,2px
60% = 58,8px
since we can't draw "half" pixels, the first div gets a height of 39px and the second one gets 58px. also, the second one is drawn 40px from above because both divs can't "overlap" (remember: the first one is 39,2px heigh, so we can't start drawing at 39px - there would be 0.2px overlapping) - and so we end up with this very weird "gap" between them.
just change last rule in
#cover-bottom {
top: 40%;
bottom: 0;
}
so it doesn't matters if the height of the <html> element is odd
http://jsfiddle.net/bVxDA/4/ (I changed background colour just to check the fill behaviour)