I have a header element with the following CSS. IE7 and 8 are ignoring the max-width property. If I change the header to be a div then it does work.
.header {
display: block;
width: inherit;
max-width: 1200px;
position: relative;
margin: 0 auto;
float: none;
}
This isnt working:
<header class="header">
//stuff
</header>
This is working:
<div class="header">
//stuff
</div>
It's not max-width that's being ignored. It's header, which is an HTML 5 element and, therefore, not supported by IE 7 & 8.
Check http://www.caniuse.com for browser compatibility.
Consider modernizr.com as a workaround. From the website:
All web developers come up against differences between browsers and
devices. That’s largely due to different feature sets: the latest
versions of the popular browsers can do some awesome things which
older browsers can’t – but we still have to support the older ones.
Modernizr makes it easy to deliver tiered experiences: make use of the
latest and greatest features in browsers which support them, without
leaving less fortunate users high and dry.
you can always check this site for browser compatibility - http://caniuse.com/.
The New HTML 5 tags are not supported in IE8, so it will not work.
I forgot I needed a javascript polyfill to make HTML5 elements work properly on old IE. The following works or you can use modernizr.
<script>
'article aside footer header nav section time'.replace(/\w+/g,function(n){document.createElement(n)})
</script>
Related
I have display: flow-root; on my responsive css script. Works perfectly on the browser responsive test but fails on my device.
shows invalid on my device am able to know this when i inspect through remote device in chrome. Any alternatives i can use ??.
If you don't need to support IE9 or lower, you can use flexbox freely, and don't need to use floated layouts.
It's worth noting that today, the use of floated elements for layout is getting more and more discouraged with the use of better alternatives.
display: inline-block - Better
Flexbox - Best (but limited browser support)
Flexbox is supported from Firefox 18, Chrome 21, Opera 12.10, and Internet Explorer 10, Safari 6.1 (including Mobile Safari) and Android's default browser 4.4.
For a detailed browser list see: http://caniuse.com/flexbox.
(Perhaps once its position is established completely, it may be the absolutely recommended way of laying out elements.)
A clearfix is a way for an element to automatically clear its child elements, so that you don't need to add additional markup. It's generally used in float layouts where elements are floated to be stacked horizontally.
The clearfix is a way to combat the zero-height container problem for floated elements
A clearfix is performed as follows:
.clearfix:after {
content: " "; /* Older browser do not support empty content */
visibility: hidden;
display: block;
height: 0;
clear: both;
}
Or, if you don't require IE<8 support, the following is fine too:
.clearfix:after {
content: "";
display: table;
clear: both;
}
Normally you would need to do something as follows:
<div>
<div style="float: left;">Sidebar</div>
<div style="clear: both;"></div> <!-- Clear the float -->
</div>
With clearfix, you only need the following:
<div class="clearfix">
<div style="float: left;" class="clearfix">Sidebar</div>
<!-- No Clearing div! -->
</div>
Read about it in this article - by Chris Coyer # CSS-Tricks
display: flow-root; Needs Chrome Canary or Firefox Nightlies.
sets it to display: table; or display: block;
May be you can use overflow: visiible to contain float-ed elements.
At the moment I have a setup similar to this:
<a href="#">
<div style="width: 50px; height: 20px;">
<span>Blah</span>
</div>
</a>
Which works perfectly well in Chrome. It fails W3C validation, however - IE apparently has issues with it.
I've considered using JavaScript to do it, but I know a lot of older web-users disable JavaScript for security concerns (personally, I'd just stop using old versions of IE. the pains)
But I was wondering, what's the HTML5 approved way to do this?
Before anyone downvotes, I'd like to reiterate that I'm asking specific to HTML 5.
It's perfectly valid HTML5 if you fix the missing quotation mark in your style attribute. Try putting this in the HTML5 validator:
<!DOCTYPE html>
<head><meta charset="utf-8"><title>Something</title></head>
<body><a href="#">
<div style="width: 50px; height: 20px;">
<span>Blah</span>
</div>
</a>
</body>
Just use CSS to make the anchor a block or inline block element so it can be given a height and width. Use either a CSS selector or an inline style attribute to assign display:block or display:inline-block, set the height and width, and get rid of the div.
<a href="#" style="display:block;width: 50px; height: 20px;">
<span>Blah</span>
</a>
If you're not sure about block vs inline-block, there are lots of articles on the web. However, block elements exist on their own line (barring things like float), but may have a height and width (amongst other things). inline-block can also be assigned height and width, but can exist inline with other elements. Caveat, some browsers cougholdversionsofIEcough don't understand inline-block or have bugs with it (there are ways around that). inline (the default for a), technically can't be given a height or width. And obviously the insinuation here is you can make inline elements behave like block elements, and vise versa.
EDIT
As per the comments, here's a CSS hack to make inline-block work reasonably well for proper browsers and also IE7-8.
.my-inline-block-element {
display:inline-block;
zoom:1;
*display:inline;
width: 50px;
height: 20px;
}
Good browsers will see display and use inline-block. IE7-8 will say WTF is that and do something stupid. But it'll see zoom which will trigger hasLayout, and because of a bug, it'll process *display:inline (but other browsers won't because * isn't allowed) and set display back to inline. But since we've got hasLayout, it'll now use the height and width but remain inline. Confused? Annoyed? Good... IE sucks.
I have the html5 element in my project and given it a padding. Firefox and Chrome show the padding correctly, but unfortunately Opera, Safari and IE don't.
Do you have any experience with this issue and know how to solve it?
It is not happening due to my reset.css, and I was able to reproduce the error in a simple fiddle. Just check it in the named browsers to see the difference.
FIDDLE
And here is the example code.
HTML:
<section class="wrapper">gets padding everywhere</section>
<main class="wrapper">gets no padding in the mentioned Browsers</main>
<section class="wrapper">gets padding everywhere</section>
CSS:
.wrapper {
padding: 8em 0;
}
Thank you!
It looks like IE, Opera etc don't treat the <main> tag as display block. I added css to force it and it worked in all the browsers you talked about here
main.wrapper{
display: block;
}
I'm having trouble getting this working in most browsers, except for IE (it even works correctly in IE6) and Opera.
Firefox separates the divs correctly but only prints the first page.
Chrome and Safari only applies the page break to the last div.
How can I get this working across all browsers correctly?
The HTML:
<div id="leftNav">
<ul>
<!--links etc-->
</ul>
</div>
<div id="mainBody">
<div id="container">
<div class="pageBreak">
<!--content-->
</div>
<div class="pageBreak">
<!--content-->
</div>
<div class="pageBreak">
<!--content-->
</div>
</div>
</div>
The divs with the IDs #leftNav and #mainBody are are set to float:left, so they display nicely.
I only want to print the .pageBreak classes, hiding the #leftNav and the rest of the #mainBody with CSS.
The CSS:
#media print
{
#leftNav
{
display:none;
}
#mainBody
{
border:none;
margin:none;
padding:none;
}
}
Parent elements can not have float on them.
Setting float:none on all parent elements makes page-break-before:always work correctly.
Other things that can break page-break are:
using page-break inside tables
floating elements
inline-block elements
block elements with borders
For the sake of completion, and for the benefit of others who are having the same problem, I just want to add that I also had to add overflow: visible to the body tag in order for FireFox to obey the page breaks and even to print more than just the first page.
I've found that Twitter Bootstrap classes add a bunch of stuff to the page which has made it difficult to get page-breaks working. Firefox worked right away, but I've had to follow various suggestions to get it to work in Chrome and, finally, IE (11).
I followed the suggestions here and elsewhere. The only property I "discovered" that I haven't seen yet mentioned is "box-sizing". Bootstrap can set this property to "box-sizing: border-box", which broke IE. An IE-friendly setting is "box-sizing: content-box". I was led to this by the caveat about "block elements with borders" made by Richard Parnaby-King https://stackoverflow.com/a/5314590/3397752.
It looks like it's a bit of an arms race to discover the next property that might break page-breaks.
This is the setting that worked for me (Chrome, FF, IE 11). Basically, it tries to override all the problematic settings on all divs on the printed page. Of course, this might also break your formatting, and that would mean that you'll have to find another way to set up the page.
#media print {
div { float: none !important; position: static !important; display: inline;
box-sizing: content-box !important;
}
}
There is a solution if the parent has float . For the element to which you applied the page-break, make the element overflow:hidden. Thats all. It worked for me.
<div style='float:left'>
<p style='overflow:hidden;page-break-before:always;'></p>
</div>
Although this is not prominently documented, it should be noted that the page-break properties cannot be applied to table elements. If you have any elements that have a display: table; or display:table-cell; applied to them (common in many templates under the clearfix class) then contained elements will ignore the page-break rules. Just cancel out the the rule in your print stylesheet and you should be OK (after the floats have also been removed, of course).
Here is an example of how to do this for the popular clearfix problem.
.clearfix:before, .clearfix:after{
display: block!important;
}
The other place I have run into this is when the template declared the entire page (usually called main or main wrapper) with display:inline-block;
If the section is inside of an inline-block, it will not work so keep your eyes open for those as well. Changing or overwriting display:inline-block; with display:block should work.
I had a position: absolute; in the div printing that caused this not to work.
Make sure the parent element has display:block; rather than display: flex;. This helped me fix the issue
"Firefox versions up to and including 3.5 don’t support the avoid, left, or right values."
IE support is also partial
you can achieve what needed by :page-break-before:always; which is supported in all browsers
"but only print the first page" : I don't think it is css related , I suppose it's sth on print window of browser :)
what's your code?
like this?:
<style>
#media print
{
table {page-break-after:always}
}
#media print
{
table {page-break-before:always}
}
</style>
I am using yaml for layout and famous clearfix css to make sure container with floats get extended.
Everything works fine with Firefox 3, IE6, IE7, IE8, Opera 9 and Google Chrome, but I have issue with Firefox 1, Firefox 2 and SeaMonkey. The problem is that clearfix container gets extended too much, as you can see on the website:
http://www.slagalica.tv/game/mojbroj
Here are screenshots of Firefox 2 and Firefox 3 rendering.
Update: Screenshots on BrowserShots.org
Unfortunately, stats show that more than 10% of my visitors are using FF2, so I cannot simply ignore the problem. I tried removing or tweaking some parts of clearfix CSS, but no matter what I do, the timer DIV (green) is separated by a large margin from the rest of the page.
Does anyone have an idea how to solve this?
Update2: I finally gave up and put TABLE tag and solved the issue in few minutes. So, don't try to look into HTML source - problem is not evident anymore.
So if you look at the original article that promotes clearfix on positioniseverything, you will note that the author recommends that since the fix is out of date the reader should look at an article on sitepoint. This sitepoint article points out a method which I have been using for a long time now.
Very simply if you give the parent overflow: hidden and make sure it has 'layout' in IE then this will clear the internal floats.
<div id="wrapper">
<div id="leftcol">
Text
</div>
<div id="rightcol">
text
</div>
</div>
and then the corresponding CSS:
#wrapper{
overflow:hidden;
width: 100%;
}
#leftcol{
float:left;
width: 50%;
}
#rightcol{
float:right;
width: 50%;
}
In the above example I have used width: 100% to give layout to IE, but you could just as easily use zoom: 1 or height: 1% if you would rather.
Try replacing clearfix with this technique and your problem should be solved.
Things to bear in mind with this technique, be careful of your internal widths otherwise you may get clipping and it is important to override the wrapper in your print stylesheet as overflow: visible otherwise it will only print the first page. but I have been using this method in production successfully for years now and I have never had any unresolvable issues with it.
clearfix is just a hack for the lazy or obsessive purist. Put a clearing div where you need it (at the bottom of your div) and get on with life.
<div>
... floated content ...
<div style="clear:both"></div>
</div>
BTW. Purist who claim this breaks semantics are incorrect. The HTML specification defines no semantic meaning for <div>. At worst it mixes style/structure but it's hardly a burden to remove when the site is redesign in the future and a pure css solution becomes practical.
I looked at it using browsershots, and I'm trying really really hard to figure out what the difference between it in FF2, 3, and chrome is. I'm not seeing it.
Looking at your page though, why not do something along these lines?
<div id='wrapper'>
<div id="leftcol">
Text
</div>
<div id="rightcol">
text
</div>
<div id="foot">
text
</div>
</div>
And the CSS:
#wrapper{
min-height:1%; //to fix IE6 floats escaping ancestor div
}
#leftcol{
float:left;
}
#rightcol{
float:left;
}
#foot{
clear:both;
}
Seems like this is a bug, and is fixed in newer versions. However, to maintain compatibility, tables have to be used instead of CSS.