CSS on IE vs CSS on Google Chrome - css

I just used the following technique:
http://webdesign.about.com/od/css3/f/blfaqbgsize.htm
to try to get a background picture to be the exact size of the page no matter what I do, it works fine in Google Chrome but not it IE. The example that they provide works fine in IE and GC but I see no differences in the two sites. Here is my code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html> <head> <title> National Balloon Festival! </title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <style type="text/css"> html, body {
height: 100%;
margin: 0;
padding: 0; } img#bg {
position:fixed;
top:0;
left:0;
width:100%;
height:100%; } #content {
position:relative;
z-index:1;
top:0px;
left:0px; } </style> <!--[if IE 6]> <style type="text/css"> html { overflow-y: hidden; } body { overflow-y: auto; } img#bg { position:absolute; z-index:-1; } #content { position:static; } </style> <![endif]--> </head> <body style=''> <body> <img src="images/Field1.jpg" alt="background image" id="bg" /> <div id="content">All your content here - including headers, paragraphs, etc.</div> </body>
</body> </html>

Hmm, when i use your code (with a picture of my own) everything seems to be fine. I'm curious, what version of IE are you using?

Hmm... Apparently changing the positioning to "absolute" allowed it on top.

Related

Padding in CSS not consistent in Web vs. Mobile

I have the following html code for a page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Buy, Sell Anywhere!</title>
<?php
$bgimglist = array(
"1419761599136.jpg",
"123.jpg",
"6Edng.jpg",
"second-hand-smoke-2-390x285.jpg",
"AllSmoke.jpg",
"best-air-purifier-for-smoke.jpg",
"HTB1pZmkG.jpg",
"images.jpg",
"index.jpg",
"SmokerBearded.jpg",
"sygareta.jpg"
);
$bgimg = $bgimglist[array_rand($bgimglist)];
?>
<style type="text/css">
body {
background-image: url(images/<?php echo $bgimg;?>);
background-repeat:no-repeat;
background-size:cover;
}
</style>
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
</head>
<body>
<script language="JavaScript">
... removed...
</script>
<div id="top">
<div class="ad">
<?php include 'Ad728x90.inc';?>
</div>
<div id="TC">
<p>By using this site, you agree to the terms and conditions. You also agree that your government, local or national permits you to engage in activities relating to... <removed>...</p>
<p>You must be at least 18 years to use this site, regardless of your local laws. We do not encourage children to be associated in any way with this site.</p>
</div>
<div id="main">
And I have the following CSS:
.large {
font-size:30px;
}
body {
font-family:Arial, Helvetica, sans-serif;
}
#top {
font-size:300%;
font-weight:bold;
text-align:center;
padding:19px 0 6px 0;
}
.ad {
margin:auto;
padding:10px;
text-align:center;
}
.links a{
color:#FFF;
text-decoration:none!important;
}
#TC {
margin:auto;
width:90%;
height: 50px;
text-align:center;
font-size:12px;
background-color:#F0F0F0;
padding:12px;
}
#main {
margin:auto;
width:90%;
height: 500px;
text-align:center;
font-size:12px;
background-color:#FFFFFF;
padding: 10px;
}
Most of the CSS may not be relevant, but I have included it for completeness. The problem is that the DIV with the id "TC" appears to have bottom padding on the web using Firefox, Chrome and IE; but not on my mobile using Chrome. In fact, some text is cutoff, so it appears to have a negative padding!
Slightly troubling (maybe this is a different issue) is that the padding on top looks bigger than the padding at the bottom on all browsers, but using Inspect Element in Firefox, the Box Model shows a 10px border for bottom and top.
Any inputs appreciated as always.
It's doing that on smaller screens because the content is overflowing the #TC div,
you can make that div bigger, or use overflow: hidden, or overfow-y: scroll in your css.
For demonstration purposes I have included overflow-y: scroll
#TC {
margin:auto;
width:90%;
height: 60px;
text-align:center;
font-size:12px;
background-color:#F0F0F0;
padding:12px;
overflow-y:scroll;
}
CODEPEN DEMO

How to center my entire webpage including the background

i want the part with the border to be centered on all screen resoultions. is this possible with the margin-top and margin-bottom properties?
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple Site</title>
</head>
<body>
<div id="container">
<div id="body">
<img src="2.png" width="1000" height="100" />
<center>
<ul class="navbar">
<li>Home</li><li>About</li><li>Contact</li><li>Services</li><li>Biography</li>
</ul>
</center>
</div>
</div>
</body>
</html>
CSS:
#charset "utf-8";
html {
text-align: center
}
#container {
margin-left:auto;
margin-right:auto;
margin-top:50 auto;
margin-bottom:50 auto;
width:960px;
background-color:#666666;
}
#body {
background-color:#666666;
width:1000px;
height:1000px;
border:3px solid #FFFFFF;
margin-top:50px auto;
}
.navbar {
margin:0px;
background-color:#66FF33;
text-align:center;
list-style:none;
border-bottom:none;
padding-left:0px;
}
ul.navbar li {
width:20%;
display:inline-block;
}
ul.navbar a {
display:block;
width:100%;
margin:0px;
padding:10px 0px;
text-decoration:none;
}
ul.navbar a:hover {
background-color:#33FFD7;
}
body {
background-color:#333333;
}
Try:
#container{
width:960px;
margin:0 auto;
/*more CSS*/
}
You can change 0 to whatever, like 50px. Your image width is larger than 960px though.
Maybe you want something like this:
var pre = onload; // window is implicit
onload = function(){ // I personally don't indent directly inside the onload
if(pre)pre(); // execute old window.onload if it existed
var doc = document, IE = parseFloat(navigator.appVersion.split('MSIE')[1]);
function E(e){
return doc.getElementById(e);
}
function alignTop(id){
var e = E(id), w, h;
if(IE){
h = parseInt(e.currentStyle.height);
}
else{
h = parseInt(getComputedStyle(e).getPropertyValue('height'));
}
w = innerHeight || doc.documentElement.clientHeight || doc.body.clientHeight;
e.style.marginTop = w/2-h/2+'px';
}
alignTop('container');
}
You should put your script tag in the head so the body is defined in some older Browsers. I would use external JavaScript, so it's cached, like:
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<title>Your Title Here</title>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<meta name='keywords' content='some words to help SEO here' />
<style type='text/css'>
#import 'common.css'; #import 'thisPage.css';
</style>
<script type='text/javascript' scr='someName.js'></script>
</head>
<body>
<div>
<div id='container'>Example Only</div>
</div>
</body>
</html>
To see a working model, visit http://jsfiddle.net/MeMQz/2/ .
i know that centers it but i want the top to be equal to the bottom by centering the whole page.not just left and right – HeyItsProdigy
Based on your comment above I guess you are trying to make the height of the content is 100% equal based on the height of the browser. You can use this trick:
html, body{
height: 100%;
}
#container{
display: block;
height: 100%;
}
Have a look at the result here http://jsfiddle.net/qiqiabaziz/GB4W2/1/

how to make div beside div

HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> This is my site </title>
<link rel="stylesheet" type="text/css" href="StyleSheet.css">
</head>
<body>
<div id="bigger">
<div id="header">
<div id="adv">
</div>
<div id="flag">
</div>
</div>
</div>
</body>
</html>
CSS
#bigger
{
height:1280px;
width:880px;
margin:0px 0px 0px 0px;
position:absolute
}
#header
{
background-color:Blue;
height:10%;
width:100%;
position:absolute
}
#adv
{
background-color:Yellow;
height:100%;
width:35%
}
#flag
{
background-color:Red;
height:100%;
width:65%;
float:right
}
How do you make the flag div appear beside the adv div inside the header div?
#adv needs float:left, so it floats to the left (and #flag floats to the right, next to it, because of float: right).
try this
#header
{
background-color:Blue;
height:10%;
width:100%;
position:relative
}
#flag
{
background-color:Red;
height:100%;
width:65%;
position:absolute;
top:0;
right:0;
}
Try this:
Normally: (somebody please correct me if I'm wrong on this):
Widths and heights should be set in pixel height-width from the beginning instead of percentages because the code will be easier to work with later. Also, I'm sure both elements should float left because then the code will be again, easier to work with and will follow better code conventions. Also, I added margins for easier viewing. You can always delete them if you wish. Code:
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> This is my site </title>
<link rel="stylesheet" type="text/css" href="example1.css">
</head>
<body>
<div id="bigger">
<div id="header">
<div id="adv">
</div>
<div id="flag">
</div>
</div>
</div>
</body>
</html>
CSS:
#bigger
{
height:1280px;
width:880px;
margin:0px 0px 0px 0px;
position:absolute
}
#header
{
background-color:Blue;
height:90px;
width:1290px;
overflow: hidden;
}
#adv
{
background-color:Yellow;
height:80px;
width:840px;
margin: 5px;
float: left;
}
#flag
{
background-color:Red;
height:80px;
width:420px;
margin: 5px;
float:left;
}

Vertical space after scrollbar in Internet Explorer with iframe, how to remove it?

I am trying to embed a URL in my webpage using iframe. The page is working properly on FireFox and Chrome, but on IE a vertical space is left after the scroll bar, how do I remove it ?
Here is the code along with CSS,
<html>
<head>
<style type="text/css">
html, body {
margin: 0;
padding 0;
}
iframe {
height: 100%;
width: 100%;
}
h1 {
text-align: center;
}
</style>
</head>
<body>
<iframe src="http://abc.org" frameborder="0" scrolling="auto" ></iframe>
</body>
</html>
Regards,
Timothy
This is you're complete solution :
<head>
<style type="text/css">
html {height:100%}
body {
margin:0;
height:100%;
overflow:hidden
}
</style>
</head>
<body>
<iframe allowtransparency=true frameborder=0 id=rf sandbox="allow-same-origin allow-forms allow-scripts" scrolling=auto src="http://www.abc.org" style="width:100%;height:100%"></iframe>
</body>

Div width 100% opera without scrollbar

I want IE8, FF's effect:
My code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DIV width 100% opera without scrollbar</title>
<style type="text/css">
<!--
html,* {margin:0px; padding:0px; }
html,body {width:100%; height:100%; overflow:hidden;}
-->
</style>
</head>
<body>
<div style="position:relative; height:100%; width:100%; background:#dee; overflow:auto;">
<div style="position:absolute; top:0px; left:0px; height:100%; width:100px; background:#e46;"></div>
<div style="position:absolute; top:0px; left:0px; height:100px; width:2000px; background:#98a;"></div>
</div>
</body>
</html>
You need to learn how to use CSS Level 1. Positioning is not necessary for this type of layout.
I've created a tutorial to visually demonstrate how CSS works with the float and margin properties here...
http://www.jabcreations.com/web/css/nested-divisible-elements
Keep in mind if you want to create a padding effect you will save yourself a TON of pain by instead adding margin to a child element like so...
/* Bad */
div.class1 {padding: 4px;}
/* Good */
div.class1 > div {margin: 4px;}
Note that the > operator limits the selector to first generation division elements in my example. So if you have a third generation division element the margin would not be applied. It's highly compatible and you should only consider compatibility for IE 8.0+ at this point.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DIV width 100% opera without scrollbar</title>
<style type="text/css">
body, html {border: 0px; margin: 0px; padding: 0px;}
#content
{
background-color: #dee;
}
#head
{
background-color: #98a;
height: 100px;
}
#side
{
background-color: #e46;
float: left;
width: 10%;
}
</style>
</head>
<body>
<div id="head">#head</div>
<div id="side">#side</div>
<div id="content">#content</div>
</body>
</html>

Resources