Percentage padding/width off in safari - css

I'm trying to create a fluid grid layout with different columns. I have one wrapper with 2 50% columns and one wrapper with 4 25% columns. This is working well in all browsers exept safari there is a tiny gab (1 pixel?) after the last column. After adding margin and padding its getting worse, the gab is much bigger and different width when resizing the browser.
I can't find what is causing this behaviour, what am I doing wrong here??
The HTML:
<div id="column2">
<div class="left">left</div>
<div class="right">right</div>
<div class="clear"></div>
</div>
<div id="column4">
<div class="box1">box1</div>
<div class="box2">box2</div>
<div class="box3">box3</div>
<div class="box4">box4</div>
<div class="clear"></div>
</div>
CSS (I left out the reset css it's included in the fiddle):
#column2 {
width:84%;
height:auto;
padding-left:8%;
padding-right:8%;
margin-left:auto;
margin-right:auto;
background-color:#FFFFCC;
}
.left {
float:left;
width:50%;
height:100px;
background-color:#FFFF66
}
.right {
float:left;
width:50%;
height:100px;
background-color:#FF9900;
}
#column4 {
width:84%;
height:auto;
padding-left:8%;
padding-right:8%;
margin-left:auto;
margin-right:auto;
background-color:#66FFFF;
}
#column4 .box1, #column4 .box2, #column4 .box3, #column4 .box4{
float:left;
width:22.25%;
height:100px;
padding-left:1%;
padding-right:1%;
margin-left:1%;
}
#column4 .box1 {
background-color: #FF3300;
margin-left:0;
}
.box2 {
background-color: #333399;
}
.box3 {
background-color: #3366FF;
}
.box4 {
background-color: #009900;
}
.clear {
clear:both;
}
I've setup a quick basic fiddle here: http://jsfiddle.net/emmetje/7ttsE/2/
Many thanks in advance for your help!

its not working 100%
but this better : http://jsfiddle.net/7ttsE/4/
<div id="column2">
<div id="spaces">%8</div>
<div class="left">left</div>
<div class="right">right</div>
<div id="spaces">%8</div>
<div class="clear"></div>
</div>
<div id="column4">
<div id="spaces">%8</div>
<div class="box1">box1</div>
<div id="margin"> </div>
<div class="box2">box2</div>
<div id="margin"> </div>
<div class="box3">box3</div>
<div id="margin"> </div>
<div class="box4">box4</div>
<div id="spaces">%8</div>
<div class="clear"></div>
</div>
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
}
#spaces {
width:8%;
float:left;
}
#margin {
float:left;
width:1%;
}
#column2 {
width:100%;
height:auto;
margin-left:auto;
margin-right:auto;
background-color:#FFFFCC;
}
.left {
float:left;
width:42%;
height:100px;
background-color:#FFFF66
}
.right {
float:left;
width:42%;
height:100px;
background-color:#FF9900;
}
#column4 {
height:auto;
margin-left:auto;
margin-right:auto;
background-color:#66FFFF;
}
#column4 .box1, #column4 .box2, #column4 .box3, #column4 .box4{
float:left;
width:20.25%;
height:100px;
}
#column4 .box1 {
background-color: #FF3300;
margin-left:0;
}
.box2 {
background-color: #333399;
}
.box3 {
background-color: #3366FF;
}
.box4 {
background-color: #009900;
}
.clear {
clear:both;
}

Related

Objects Don't go in right place below div

I can't work out why any object will not go straight under the 3 divs.
Here is the HTML
<!doctype html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="style.css">
<meta charset="utf-8">
<title>The Trek</title>
</head><body>
<div id="wrap">
<div id="main">
<div id="bucket"><img src="img/golf.png" width="100%"><div id="button">Text</div></div>
<div id="bucket"><img src="img/4wd.png" width="100%"><div id="button">Text</div></div>
<div id="bucket"><img src="img/mara.png" width="100%"><div id="button">Text</div></div>
<p>Text</p>
</div>
</div>
</div>
</body>
</html>
Here is the CSS
*{padding:0px;margin:0px;font-family:geneva;}
body{background-image:url(img/bg.png);background-repeat:repeat;}
#wrap{padding:50px;}
#main{margin:auto;padding:40px; width:900px;height:850px; position:relative;}
#bucket{width:30.2%;float:left; margin-right:40px;height:auto;display:block;}
#main div:last-child{margin-right:0px;}
#button {float:left;width:100%;height:auto;text-decoration:none;text-align:center;color:#eee;width:96.5%;height:100%; background:#633;text-decoration:none; padding:5px; font-size:20px;}
Any help will be appreciated!
First of all you are using the same ID for multiple elements... Change this to a class. An ID must always be unique.
Clearing the floating is one way, but i don't like it as it becomes a bit messy later on.
My suggestion is to wrap your "bucket" elements into a div. This will solve your problem.
EXAMPLE
HTML
<div id="wrap">
<div id="main">
<div id="buckets">
<div class="bucket">
<img src="img/golf.png" width="100%" />
<div class="button">Text</div>
</div>
<div class="bucket">
<img src="img/4wd.png" width="100%" />
<div class="button">Text</div>
</div>
<div class="bucket">
<img src="img/mara.png" width="100%" />
<div class="button">Text</div>
</div>
</div>
<p>Text</p>
</div>
</div>
CSS
* {
padding:0px;
margin:0px;
font-family:geneva;
}
body {
background-image:url(img/bg.png);
background-repeat:repeat;
}
#wrap {
padding:50px;
}
#main {
margin:auto;
padding:40px;
width:900px;
height:850px;
position:relative;
}
.bucket {
width:30.2%;
float:left;
margin-right:40px;
height:auto;
display:block;
}
#main div:last-child {
margin-right:0px;
}
.button {
float:left;
width:100%;
height:auto;
text-decoration:none;
text-align:center;
color:#eee;
width:96.5%;
height:100%;
background:#633;
text-decoration:none;
padding:5px;
font-size:20px;
}
Hope this helps
So there's a few suggestions I'll make about your code first, id="" is only used on a element that is only used once, typically you don't use them, instead use class="" which can be used as many times as needed on a page, you can select this by . instead of # in your CSS. The reason your <p> element was going beside is was because there was room for it next to the 3 <div>. Obviously a quick fix to this could be like #plalx said use clear: both; property but that's just covering up your error and not really fixing it. You could also use display: block on what ever element you want to go below. To really fix this issue you need to make use that the 3 <div> fill the width of it's container. I've cleaned up your code let me know if you have any questions, good luck!
EXAMPLE
HTML
<div class="wrap">
<div class="main">
<div class="bucket">
<img src="http://placehold.it/350x150"/>
<div class="button">Text</div>
</div>
<div class="bucket">
<img src="http://placehold.it/350x150"/>
<div class="button">Text</div>
</div>
<div class="bucket">
<img src="http://placehold.it/350x150"/>
<div class="button">Text</div>
</div>
<p>Text</p>
</div>
</div>
CSS
/* RESET */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center, dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
ol, ul {
list-style: none;
}
strong {
font-weight: bold;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
*,*:before,*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
background-image: url(img/bg.png);
background-repeat: repeat;
font-family: geneva;
}
img {
display: block;
max-width: 100%;
}
.wrap {
padding: 20px;
width: 960px;
}
.main {
margin: 0 auto;
padding: 20px;
}
.bucket {
display: inline-block;
width: 31.33%;
margin-right: 20px;
}
.bucket:last-of-type { margin-right: 0;}
.button {
width:100%;
text-decoration:none;
text-align:center;
color:#eee;
background:#633;
padding:5px;
font-size:20px;
}
It's because you did not cleared the left floating. There are several ways to achieve this, like:
#main p {
clear: both;
}
This will prevent floated elements to the left or right of all p tags withing the #main element.

display image a text inline with each other

i have this CSS:
<style type="text/css">
#box {
width:100%;
height:80px;
background-color:#eeeeee;
}
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:center;
}
#text, #text a {
font-size:16px;
color:#F36F25;
margin:10px;
}
#text:hover, #text a:hover {
color:#666666;
text-decoration:none;
}
#text img {
vertical-align: middle;
margin-right:20px;
}
</style>
its currently displaying the image and text inline but i have multiple images/text below each other. how can i make all the images align in the same position below each other?
here is a fiddle: http://jsfiddle.net/8dsTu/
http://jsfiddle.net/8dsTu/4/
<div id="text">
<img src="../images/icons/address.png" height="60" />
<div style="display:inline-block;">
Address 1,<br />
Address 2,<br />
County Post Code
</div>
</div>
Edit css:
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:left;
margin-left:100px;
}
Your HTML is invalid, id property is meant to be unique and you have a few <div> elements with id="text". To get what you want you'll have to: (jsFiddle)
replace all id="text" with class="text" and add <div class="caption"> to wrap each of the captions:
<div id="box">
<div class="box-inner">
<div class="text">
<img src="../images/icons/telephone.png" height="60" />
<div class="caption">00000 00 00 00</div>
</div>
<div class="text">
<img src="../images/icons/email.png" height="60" />
<div class="caption">sales#domain.co.uk</div>
</div>
<div class="text">
<img src="../images/icons/address.png" height="60" />
<div class="caption">Address 1,<br />Address 2,<br />County Post Code</div>
</div>
</div>
</div>
Adjust the css:
#box {
width:100%;
height:80px;
background-color:#eeeeee;
}
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:center;
}
.text, .text a {
font-size:16px;
color:#F36F25;
margin:10px;
}
.text:hover, .text a:hover {
color:#666666;
text-decoration:none;
}
.text img {
vertical-align: middle;
margin-right:20px;
}
.caption{ /* This is the new bit - display:inline-block does the trick. adjust margin-top to your needs */
display:inline-block;
vertical-align:top;
margin-top:15px;
}
#box {
width:100%;
background-color:#eeeeee;
}
.box-inner {
width:80%;
margin:0 auto 0 auto;
text-align:center;
}
.text, .text a {
font-size:16px;
color:#F36F25;
}
.text:hover, .text a:hover {
color:#666666;
text-decoration:none;
}
.text img {
vertical-align: middle;
margin-right:20px;
width: 60px;
background: black;
float: left;
}
.text {
overflow: hidden;
width: 250px;
margin: 10px auto;
}
Something like this? But you must replace your id's with classes.

z-index not layering as it should

I was after a little help with z-index...
I'm playing with the code and need my id="hidebar" to sit on top of the "content" and "content-inner" divs. Sorry if this seems really basic, but I struggle =D
My CSS structure file:
body
{
margin: 0;
padding: 0;
height:100%;
width:100%;
background-color: #FFF;
z-index:-1;
}
#content
{
width: 100%;
height: 640px;
background-color:#060;
position:relative;
z-index:-1;
}
#content-inner
{
width: 960px;
height: 640px;
background-color:#666;
margin-left:auto;
margin-right:auto;
position:relative;
z-index:-1;
}
#hidebar
{
width: 100%;
height: 50px;
background-color:#0FF;
position:relative;
z-index:2;
}
#navbar
{
width: 100%;
height: 257px;
background-color:#F00;
position:relative;
}
#navbar-inner
{
width: 960px;
height: 257px;
background-color:#666;
margin-left:auto;
margin-right:auto;
position:relative;
}
#footer
{
width: 100%;
height: 181px;
background-image:url(images/gray-pixel.png);
position:relative;
}
#footer-inner
{
width: 960px;
height: 181px;
background-color:#666;
margin-left:auto;
margin-right:auto;
position:relative;
}
#footer-small
{
width:230px;
float:left;
height:100%;
background-color:#999;
position:relative;
}
#footer-large
{
width:500px;
float:left;
height:100%;
background-color:#CCC;
position:relative;
}
#colour-bar
{
width: 100%;
height: 13px;
background-color:#639;
position:relative;
}
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, details, figcaption, figure, footer, header, hgroup, mark, menu, meter, nav, output, progress, section, summary, time {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
ul {
list-style-type:none;
}
ul li a{
font:700 49px/1.2em Arial, Helvetica, sans-serif;
color:#fff;
text-decoration:none;
height:59px;
display:inline-block;
list-style-type:none;
text-align:center;
position::relative;
vertical-align: baseline;
}
ul li a:hover{
color:#e25709;
}
div.table
{
border: 0px solid black;
display: table;
margin-left:auto;
margin-right:auto;
}
div.tr {border: 0px solid black; display: table-row; }
div.td {border: 0px solid black; display: table-cell; }
h3
{
color:#FFF;
font-size:22px;
font-family:Arial, Helvetica, sans-serif;
padding-top:30px;
padding-left:25px;
padding-bottom:20px;
}
h4
{
color:#FFF;
font-size:13px;
font-style:normal;
font-family:Arial, Helvetica, sans-serif;
padding-left:25px;
padding-right:25px;
line-height:1.2em;
}
My Source Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="css/structure.css"/>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="content">
<div id="content-inner">
<a href="index.html">
<img src="images/logo.jpg"/ alt>
</a>
</div>
</div>
<div id="hidebar">
</div>
<div id="colour-bar"></div>
<div id="navbar">
<div id="navbar-inner">
<ul>
<li><button1>About us</button1></li>
<li><button2>Partners</button2></li>
<li><button3>Solutions</button3></li>
<li><button4>Services</button4></li>
</ul>
</div>
</div>
<div id="footer">
<div id="footer-inner">
<div id="footer-small"></div>
<div id="footer-large">
<div class="table">
<div class="tr">
<div class="td">
<h3>Contact Us:</h3>
</div>
<div class="td">
</div>
</div>
<div class="tr">
<div class="td">
<h4>AUS - Melbourne<br />
101 Main Street<br />
Glen Iris VIC 3146</h4>
</div>
<div class="td">
<h4>Email: mail#website.com<br />
Phone: (03) 9888 8888<br />
Fax: (03) 9888 8888</h4>
</div>
</div>
</div>
</div>
<div id="footer-small"></div>
</div>
</div>
<script>
$("button1").click(function () {
$("h4").toggle("slow");
$("button1").toggle();
$("button2").show();
$("button3").show();
$("button4").show();
});
$("button2").click(function () {
$("h4").toggle("slow");
$("button2").toggle();
$("button1").show();
$("button3").show();
$("button4").show();
});
$("button3").click(function () {
$("h4").toggle("slow");
$("button3").toggle();
$("button1").show();
$("button2").show();
$("button4").show();
});
$("button4").click(function () {
$("h4").toggle("slow");
$("button4").toggle();
$("button1").show();
$("button2").show();
$("button3").show();
});
</script>
</body>
</html>
Any help would be amazing <3
If you want #hidebar to be on top of #contents and #content-inner then just reposition the #hidebar.
<div id="content">
<div id="content-inner">
<div id="hidebar">
</div>
<a href="index.html">
<img src="images/logo.jpg" />
</a>
</div>
</div>

CSS layout zoom issue

My issue is that when I zoom in or out of the page (in all the browsers I tried), only some parts of it are displayed as zoomed (the contents that are in the divs, but not the divs themselves). I put the borders to show it easily.
When I searched for a solution, all of them mentioned that it is because of fixed width values by using pixels (px). So, I used % when putting values to width and height; but still, the issue remains...
Here are some screenshots to illustrate my problem:
When zoomed-in:
When zoomed-out:
Here is my code:
HTML:
<html>
<head>
<link href="style.css" type="text/css" rel="stylesheet"/>
</head>
<body>
<div id="title_bar">
some txt here
<div id="title_img"></div>
<div id="title_txt"></div>
<div id="menu_navigation"></div>
</div>
<div id="title_bar_2">
some txt here
</div>
<div id="container_columns">
<div id="column_1">
<span id="column_1_content">some txt here</span>
</div>
<div id="column_2">
<span id="column_2_content">some txt here</span>
</div>
</div>
</body>
</html>
CSS:
html body
{
margin: 0;
width: 100%;
height: 100%;
background-color:#f2f2f2;
}
div#title_bar
{
height:4%;
width:76%;
margin:auto;
margin-top:4%;
border-style:solid;
border-color:blue;
}
div#title_bar_2
{
text-align:center;
height:44%;
width:76%;
margin:auto;
margin-top:2%;
border-style:solid;
border-color:blue;
}
div#title_bar img
{
margin-top:1%;
float:left;
}
div#title_txt
{
float:left;
margin-left:2%;
margin-top:1.4%;
font-style: italic;
font-family:verdana;
font-size: 16px;
}
div#menu_navigation
{
float:left;
margin-left:35%;
margin-top:1.4%;
font-size:19px;
}
div#container_columns
{
margin:auto;
width:76.5%;
margin-top:2%;
height:27%;
border-style:solid;
border-color:blue;
}
div#column_1
{
height:100%;
width:49%;
float:left;
border-style:solid;
border-color:blue;
}
div#column_2
{
margin-left:1%;
width:48%;
float:left;
height:100%;
}
Hi This is happening because you are using the property height. try not to use it, if you want this property.
html body{
margin: 0;
width: 100%;
background-color:#f2f2f2;}
div#title_bar{
width:76%;
margin:auto;
margin-top:4%;
border-style:solid;
border-color:blue;}
div#title_bar_2{
text-align:center;
width:76%;
margin:auto;
margin-top:2%;
border-style:solid;
border-color:blue;}
div#title_bar img{
margin-top:1%;
float:left;}
div#title_txt{
float:left;
margin-left:2%;
margin-top:1.4%;
font-style: italic;
font-family:verdana;
font-size: 16px;}
div#menu_navigation{
float:left;
margin-left:35%;
margin-top:1.4%;
font-size:19px;}
div#container_columns{
margin:auto;
width:76.5%;
margin-top:2%;
border-style:solid;
border-color:blue;
display:block;}
div#column_1{
width:48%;
float:left;
border-style:solid;
border-color:blue;}
div#column_2{
margin-left:1%;
width:48%;
float:left;}

div content over spilling, inline-block useless

Im a self learner for web designing, so i might missed out some fundamentals coding.
So the problem is the content is overspilling the div from the right in one line.
The code as below
THE HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title></title>
</head>
<body>
<div id="bg">
<div id="mainwrapper">
<div id="header">
<div id="logo"></div>
</div>
<div id="contentwrapper">
<div id="leftwrapper">
<div id="contentspacing">
<div id="content">
<p>
asdfasdfasdfasdvvasdvasdvasdvfasdvsdasdas
dfasdfasdfasdvvasdvasdvasdvfasdvsdasdasdfasdfas
</p>
</div>
</div>
</div>
<div id="rightwrapper">
asdfasdf
</div>
</div>
</div>
</div>
</body>
</html>
THE CSS AS BELOW
/* ---------------------------------------------------------------*/
/* ---------------------> RESET <<<-------------------------*/
/* ---------------------------------------------------------------*/
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td {
margin:0;
padding:0;
border:0;
outline:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}
body {
line-height:1;
}
body {
font-family:Arial,sans-serif;
font-size:100%;
line-height:1.3em;
_font-size:16px;
color:#504e45;
background:#ebe9e1 url(pics/bg.jpg) top left repeat-x;
}
#bg {
float:left;
display:block;
height:600px;
width:100%;
background:url(pics/hotel-bg.jpg) top center no-repeat;
margin:0 0 0 0;
}
#mainwrapper {
float:left;
display:block;
width:1000px;
margin:0 auto;
}
#header {
float:left;
display:block;
}
#logo {
width:274px;
height:44px;
background:url(pics/logo.png) no-repeat;
margin:50 0 0 100;
}
p {
float:left;
display:inline-block;
line-height:1.7em;
margin:1em 0;
-webkit-margin-before:1em;
-webkit-margin-after:1em;
-webkit-margin-start:0px;
-webkit-margin-end:0px;
}
#contentwrapper {
float:left;
display:block;
width:1000px;
}
#leftwrapper {
float:left;
display:block;
width:593px;
}
#contentspacing {
float:left;
display:block;
margin:0;
padding:0;
border:0;
outline:0;
font-size:100%;
vertical-align:baseline;
background:transparent;
}
#content {
float:left;
display:block;
height:auto;
width:593px;
border:1px solid #bdc9f4;
background:url(pics/bg2.png) top left repeat-x;
margin:35 120;
}
#rightwrapper {
float:left;
display:block;
}
Add word-wrap: break-word; word-break: break-all; to #content
Demo here http://jsfiddle.net/ZK6yR/
This occurs when you are using rather long words. Try this:
word-wrap: no-break;

Resources