How do I replicate this effect in CSS? - html

http://i.imgur.com/Ta7cZ.png
The portion to the right of Who with the ----------
Is it a background to the li? I'm really drawing a blank as how to create something like that.

Here you go mess around with this.
http://jsfiddle.net/fjZfL/3/
HTML:
<div id="box">
<h2>who?</h2>
<p>I am 22 Year old designer …</p>
</div>
CSS:
#box {
width: 200px;
height: 150px;
background: #eee;
padding: 0 8px;
}
h2 {
display: inline-block;
padding: 18px 4px 0 10px;
margin: 0;
background: #eee;
}
p {
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
padding: 20px 10px;
margin-top: -10px;
}

Alternatively - there IS the HR solution
http://jsfiddle.net/UYYh5/4/

Isn't that just a horizontal rule? aka <hr />?
Well, just searched the text in the image, and found the website. This CSS style applied to the p block in question is how it's done I guess.
border-top: 1px solid rgba(0, 0, 0, 0.1)

Here you go: http://jsfiddle.net/x63x2/
The CSS:
body { font-family:arial,helvetica,sans-serif ;
}
.block-item { width:350px ;
height:300px ;
padding:10px ;
margin:auto ;
background:#D4D4D4 ;
}
p { font-size:13px ;
margin-top:14px ;
margin-bottom:14px ;
line-height:18px ;
}
.block-item h1 { display:block ;
background:#D4D4D4 ;
font-size:18px ;
color:red ;
padding:0px 5px 0px 0px ;
position:absolute ;
top:3px ;
}
and the HTML:
<div class="block-item">
<hr>
<h1>Who?</h1>
<p>Nulla porttitor sodales quam, et molestie mi euismod vel. Nunc iaculis ligula ac dolor congue consequat. Cras tristique vulputate auctor. Pellentesque mattis massa vel arcu auctor tristique. Mauris rhoncus porta diam, sit amet euismod turpis viverra eu. Nulla in ligula sed nibh tristique laoreet. Nullam id magna erat. Sed porttitor mauris vel diam pharetra a volutpat tellus volutpat. Quisque placerat laoreet odio sit amet posuere. Duis id libero nisl.</p>
</div>​
If you want to dress up the line, you can style your HR w/ CSS. This is just a basic example.

Here is another alternative.
http://jsfiddle.net/PZxA7/
.title{
background-color:white;
position:absolute;
z-index:10;
}
.bar
{
border-bottom:1px solid;
position:absolute;
display:inline-block;
color:#b5b5b5;
margin-top:-10px;
width:350px;
}
.container
{
width:350px;
}
<div class="container">
<div class="title">W H O?</div>
<div class="bar"/> </div>
<p><br/>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>

An easy way to replicate this effect is something like:
div.wrapper{ width: 300px;
font-family: 'Times New Roman';
font-size: 13px;
color: #3b3a3a;
}
div.wrapper div{
margin: 0px 0px;
}
div.header span{
font-size: 14px;
font-family: Verdana;
font-weight: 300;
display: inline-block;
margin: 0px;
width: 60px;
background-color: #fff;
}
div.content p
{
margin: 3px;
}
div.content p span
{
background:url('http://i.imgur.com/Ta7cZ.png') no-repeat -150px -140px;
height: 7px;
width: 30px;
display: inline-block;
}
div.wrapper div.header{
background:url('http://i.imgur.com/Ta7cZ.png') no-repeat 0px -10px;
}
div.wrapper div.footer{
background:url('http://i.imgur.com/Ta7cZ.png') no-repeat -10px -170px;
height: 18px;
}
<div class="wrapper">
<div class="header"><span>Who?</span></div>
<div class="content"><p>I'm a 22 year old designer who spends more time on the internet than I should.
I am currently living in Upstate NY, but would love to someday move away from the cold. I am a sucker
for Apple products and enjoy a well-brewed beer.<span></span></p>
</div>
<div class="footer"></div>
</div>
To me, images always look cleaner for a background that thin. In my example, you'd obviously cut the images down, but you get the idea.

Related

css square border with gap in border bottom

I'm trying to replicate this mock up design.
Design:
Current:
Is there a way to make sure the "Shop All" ignores the overflow:hidden, but the before and after obey the overflow:hidden?
Or is there another method I can try to implement this?
Html
<div id="outer">
<div id="opaq">
<div id="inner">
<h1>Performance Parts</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi efficitur in arcu at placerat. Aenean sed lorem tincidunt, maximus purus eget, ornare metus. Nam interdum lobortis imperdiet. Nunc gravida urna urna. Vestibulum vitae lectus leo. Etiam fermentum nunc vel nulla tincidunt, sit amet molestie lectus pulvinar.</p>
<div id="shop">Shop all</div>
</div>
</div>
</div>
Css
#outer{
max-width:500px;
text-align:center;
background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNyPOuKMHtvXNa5dnlc8xGXvW-nVfguLdlj9sj4-K6cTA0Zbf7");
}
#opaq{
background-color: rgba(48, 44, 44, 0.7);
padding:5px;
}
#inner{
border:1px solid red;
margin:10px;
color:white;
border-bottom:none;
overflow:hidden;
}
#shop{
position:relative;
top:8px;
display: inline-block;
}
#shop:after{
content: "";
position: absolute;
border-bottom: 1px solid white;
top: 9px;
width: 600px;
left: 100%;
margin-left: 15px;
}
#shop:before{
content: "";
position: absolute;
border-bottom: 1px solid white;
top: 9px;
width: 600px;
right: 100%;
margin-right: 15px;
}
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
.wrapper {
background-image: linear-gradient(rgba(0, 0, 0, .3), rgba(0, 0, 0, .3)), url(http://beerhold.it/400/300);
background-repeat: no-repeat;
background-size: cover;
width: 400px;
height: 200px;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
}
fieldset {
width: 90%;
height: 90%;
margin-top: .7em;
transform: rotate3d(0, 0, 1, 180deg);
border: 3px solid rgba(255, 255, 255, .4);
}
legend {
font-size: 1.4em;
font-weight: 700;
}
legend span,
fieldset .text {
display: block;
transform: rotate3d(0, 0, 1, 180deg);
color: white;
text-shadow: 0 0 4px black;
padding: 0 1em;
}
legend span {
color: yellow;
}
fieldset .text {
height: 100%;
}
fieldset .text h1 {
padding: .3em 0;
text-align: center;
}
fieldset .text p {
line-height: 1;
}
<div class="wrapper">
<fieldset>
<legend align="center"><span>SHOP ALL</span>
</legend>
<div class="text">
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut a justo nisl. Phasellus consequat tincidunt elit, sed interdum nibh blandit ut. Nunc augue erat, rutrum ac vehicula nec, pulvinar in eros.
</p>
</div>
</fieldset>
</div>
Use this css; notice i have added comments to the code i change or added
#outer{
max-width:500px;
text-align:center;
background-image: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNyPOuKMHtvXNa5dnlc8xGXvW-nVfguLdlj9sj4-K6cTA0Zbf7");
}
#opaq{
background-color: rgba(48, 44, 44, 0.7);
padding:5px;
}
#inner{
border:1px solid red;
margin:10px;
color:white;
border-bottom:none;
}
#shop{
position:relative;
top:8px;
display: inline-block;
z-index:200; /*added*/
}
#shop:after{
content: "";
position: absolute;
border-bottom: 1px solid white;
top: 9px;
width: 364%; /* changed */
left: 100%;
margin-left: 15px;
}
#shop:before{
content: "";
position: absolute;
border-bottom: 1px solid white;
top: 9px;
width: 364%; /* changed */
right: 100%;
margin-right: 15px;
}
border split into table cells:
body
{
font-family:arial;
background-image:url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNyPOuKMHtvXNa5dnlc8xGXvW-nVfguLdlj9sj4-K6cTA0Zbf7");
background-size:cover;
margin:0px;
}
.box div
{
border:0px solid RGBa(255,255,255,0.5);
}
.shade
{
background-color:RGBa(50,50,50,0.7);
padding:20px;
position:fixed;
top:0px;
right:0px;
bottom:0px;
left:0px;
}
h1
{
text-align:center;
text-transform:uppercase;
}
.bottomborder
{
display:table;
table-layout:fixed;
}
.box .left
{
width:50%;
border-width:0px 0px 2px 2px;
}
.box .right
{
width:50%;
border-width:0px 2px 2px 0px;
}
.box .col
{
display:table-cell;
}
.shopall
{
padding: 0px 15px;
white-space: nowrap;
position: relative;
top: 10px;
color:RGB(200,150,0);
font-weight:bold;
font-size:20px;
text-transform:uppercase;
}
.box
{
margin-left:auto;
margin-right:auto;
width:1100px;
margin-top:15px;
max-width: 100%;
}
.box .content
{
padding:5px 55px 10px 55px;
border-width:2px 2px 0px 2px;
border-top-left-radius:0px;
border-top-right-radius:0px;
color:white;
}
<body>
<div class="shade">
<div class="box">
<div class="content">
<h1>Performance & Parts </h1>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi efficitur in arcu at placerat. Aenean sed lorem tincidunt, maximus purus eget, ornare metus. Nam interdum lobortis imperdiet.
</div>
<div class="bottomborder">
<div class="left col">
</div>
<div class="col">
<div class="shopall">
shop all
</div>
</div>
<div class="right col">
</div>
</div>
</div>
</div>
</body>
You may try a negative margin and some flex to draw side borders, and it will keep a coherent HTML with title coming first in the code :
div {
margin:2em;
display:flex;
flex-flow:column;
text-align:center;
border:solid;
border-bottom-color:transparent;
background:rgba(0,0,0,0.2);
box-shadow: 0 0 0 2em rgba(0,0,0,0.2);
}
div h2 {
order:1;
display:flex;
margin:0 0 -0.6em 0;
font-variant:small-caps;
}
h2:before,
h2:after {
content:'';
flex:1;
border-bottom:solid;
margin:auto 1em auto -3px ;
}
h2:after {
margin: auto -3px auto 1em;
}
p {padding:0.25em 0.5em;}
html {background:url(http://lorempixel.com/800/600/city/6);
background-size:cover;
color:white;
text-shadow:0 0 1px black;
}
<div>
<h1>HTML Ipsum Presents</h1>
<h2>shop all</h2>
<p><strong>Pellentesque habitant morbi tristique</strong> senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. <em>Aenean ultricies mi vitae est.</em> Mauris
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, <code>commodo vitae</code>, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis
tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.</p>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
Mauris placerat eleifend leo.</p>
</div>

CSS - how to put divs in the correct position on a webpage [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to put three divs on my webpage, like this, the pink div is the container for two other divs and I want to center the div on the webpage (vertically and horizontally). I prepared some jsfiddle, but obviously I suck at css, so the effect is far from the expected one... So far my css looks like this:
#intro2{
background-color: #b0e0e6;
width: 50%;
margin: 0 auto;
font-size: 1.5em;
}
#intro2 .image{
position: absolute;
left: 0px;
background-color: #aaaae6;
}
#intro2 .text{
position: relative;
right: 0px;
background-color: #cccccc;
}
}
Could you help me with that?
Thanks.
Try like this:-
#intro2{
background-color: #b0e0e6;
width: 50%;
margin: 0 auto;
font-size: 1.5em;
padding: 5px;
}
.clear{
clear: both;
}
#intro2 .image{
float:left;
width:50%;
background-color: #aaaae6;
}
#intro2 .text{
float: right;
width:50%;
background-color: #cccccc;
}
<div class="intro" id="intro2">
<div class="image" id="image1">
<img src="http://www.cdc.gov/animalimportation/images/dog2.jpg" alt="simple" />
</div>
<div class="text" id="text1">
<h1>Simple</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis sodales sit amet mauris in blandit. Aenean sodales in dui eget facilisis. Vestibulum tempor risus dui, sed pharetra nulla auctor id. Sed purus odio, tempus et volutpat a, fermentum sit amet ante. Etiam eros mauris, rutrum at vehicula a, vehicula vitae nulla. Suspendisse non mattis turpis. Donec non convallis lacus. Nullam gravida diam et leo tempor vestibulum. Vivamus lorem nunc, bibendum eu lacinia quis, porta vel nisl. Sed vitae euismod augue. In at est lacinia ipsum feugiat feugiat. Praesent mollis posuere ante, eget maximus est mollis suscipit. Donec ullamcorper elit quis cursus gravida. Quisque leo risus, bibendum sed nisi ut, facilisis iaculis arcu. Pellentesque purus augue, fringilla tempus augue eget, ullamcorper condimentum leo.</p>
</div>
<div class="clear"></div>
</div>
Here:
#intro2{
background-color: #b0e0e6;
width: 50%;
left:50%;
font-size: 1.5em;
position:absolute;
margin-left:-25%;
}
That way your container is centered on the page.
I'm not sure I would go with the absaloute positioning method you've gone for on this occasion. I think perhaps a display:table on the wrapper and display:table-cell on the children would give you more control over your style.
#intro2{
background-color: #b0e0e6;
width: 50%;
margin: 0 auto;
font-size: 1.5em;
}
#intro2 .image{
background-color: #aaaae6;
display: table-cell;
vertical-align: top;
}
#intro2 .text{
background-color: #cccccc;
display: table-cell;
vertical-align: top;
}
Here's an example: http://jsfiddle.net/Lfyacy25/2/
http://jsfiddle.net/Lfyacy25/3/
#intro2{
background-color: #b0e0e6;
width: 50%;
margin: 0 auto;
font-size: 1.5em;
}
#intro2 .image{
float: left;
width: 50%;
background-color: #aaaae6;
}
#intro2 .text{
float: left;
width: 50%;
background-color: #cccccc;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
.intro{
background-color: #b0e0e6;
width: 100%;
margin: 0 auto;
font-size: 1.5em;
padding: 5px;
}
.intro:before,.intro:after {
content: " ";
display: table;
}
.intro:after {
clear: both;
}
.image{
width: 50%;
background-color: #aaaae6;
float: left;
}
img{
margin: 0 auto;
display: block;
}
.text{
width: 50%;
background-color: #cccccc;
float: left;
}
Updated fiddle
try the following:
<div class="outter">
<div class="innerleft">image goes here</div>
<div class="innerright">text goes here</div>
</div>
.outter {width:100%; min-height:120px; background-color:red; padding:1% }
.innerleft {float:left; width:49%;background-color: green;min-height:120px; }
.innerright {float:right; width:49%;background-color: blue;min-height:120px; }

How do I make CSS row boxes?

I'm trying to make a few rows like in a table, but with divs.
Each one has an image on the left, a block of text, and "read more"..
I've tried using display:table, but it doesn't seem to be working.. The text is and images are not aligned properly..
http://jsfiddle.net/76a4j/1/
.entry{
width=100%;
display:table;
}
entry-row {
border: 2px #000000 solid;
margin-top:5px;
margin-bottom:5px;
display: table-row;
}
.imgrL {
border: 1px solid #c7c5c8;
padding: 5px;
float:left;
clear:left;
}
Thanks for the answers everyone, I see what I did wrong and have fixed it now :)
You have two problems:
CSS does not use =. Change
width=100%;
to
width: 100%;
You need to use . on all class selectors. Change
entry-row {
to
.entry-row {
With these changes, it looks more like your image.
JSFiddle
Here is the solution you want:
HTML
<div class="entry">
<a href="#">
<img src="#" />
</a>
<div class="text">
<h3 class="title">Article 1</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Curabitur scelerisque arcu at accumsan feugiat. Fusce at interdum sapien.
Phasellus nec odio varius ante imperdiet facilisis. Etiam iaculis dui vitae nibh scelerisque fermentum.
Nam iaculis quis purus ac congue. Maecenas sed elit tortor.
Sed gravida velit nulla, sit amet dapibus elit mollis vitae.
In libero libero, mattis et ipsum eu, euismod aliquet diam.
Nulla eu neque interdum, suscipit libero nec, facilisis sapien. Donec consequat porttitor interdum.
Nullam non blandit massa.Read more
</p>
</div>
</div>
CSS
.entry > a {
float: left;
}
.entry img {
width: 130px;
height: 130px;
}
.entry .text {
float: right;
width: 700px;
}
.entry:after {
clear: both;
content: '';
display: block;
}
.entry .title {
color: #FF7A00;
font-family: arial;
font-size: 15px;
}
.entry .text {
margin: 0px 0px 0px 20px;
}
.entry .text * {
margin: 0px;
}
.entry .read-more {
float: right;
}
display: inline-block;
Could be done for you
add this css
div
{
display: inline-block;
}
Please change css code
entry-row {
border: 2px #000000 solid;
margin-top:5px;
margin-bottom:5px;
display: table-row;
}
To
.entry-row {
float:left;
border: 2px #000000 solid;
margin-top:5px;
margin-bottom:5px;
}
You have to add overflow:hidden property to each row.
.entry-row {
overflow:hidden;
margin:0 0 20px;
}
Hope it will help.

css: zooming-out inside the browser moves rightmost floated div below other divs

I am seeing something strange in both firefox and chrome when I increase
the zoom level inside these browsers, although I see nothing wrong with
my CSS.
Here is the whole story:
I have a right-floated top-level div containing three right-floated right.
The three inner divs have all box-model measurements in pixels which add
up to the width of the enclosing container. Everything looks fine when
the browser size is 100%, but when I start making the browser smaller
with CTRL+scrollwheel or CTRL+minus the rightmost margin shrinks
down too fast and eventually becomes zero, forcing my rightmost
floated inner div to fall down below the other two!
I can't make sense out of this, almost seems like some integer division
is being performed incorrectly in the browser code, but alas firefox and
chrome both display the same result.
Here is the example (just zoom out with CTRL-minus to see what I mean):
Click Here to View What I Mean on Example Site
Just to narrow things down a bit, the tags of interest are the following:
div#mainContent
div#contentLeft
div#contentCenter
div#contentRight
I've searched stackoverflow for an answer and found the following
posts which seem related to my question but was not able to apply
them to the problem I am experiencing:
http://
stackoverflow.com/questions/6955313/div-moves-incorrectly-on-browser-resize
http://
stackoverflow.com/questions/18246882/divs-move-when-resizing-page
http://
stackoverflow.com/questions/17637231/moving-an-image-when-browser-resizes
http://
stackoverflow.com/questions/5316380/how-to-stop-divs-moving-when-the-browser-is-resized
I've duplicated the html and css code below for your convenience:
Here is the HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pinco</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<header>
<div class="logo">
<a href="http://pinco.com">
<img class="logo" src="images/PincoLogo5.png" alt="Pinco" />
</a>
</div>
<div class="titolo">
<h1>Benvenuti!</h1>
<h2>Siete arrivati al sito pinco.</h2>
</div>
<nav>
<ul class="menu">
<li>Menù Qui</li>
<li>Menù Quo</li>
<li>Menù Qua</li>
</ul>
</nav>
</header>
<div id="mainContent">
<div id="contentLeft">
<section>
<article>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempor turpis est, nec varius est pharetra scelerisque. Sed eu pellentesque purus, at cursus nisi. In bibendum tristique nunc eu mattis. Nulla pretium tincidunt ipsum, non imperdiet metus tincidunt ac. In et lobortis elit, nec lobortis purus. Cras ac viverra risus. Proin dapibus tortor justo, a vulputate ipsum lacinia sed. In hac habitasse platea dictumst. Phasellus sit amet malesuada velit. Fusce diam neque, cursus id dui ac, blandit vehicula tortor.
Phasellus interdum ipsum eu leo condimentum, in dignissim erat tincidunt. Ut fermentum consectetur tellus, dignissim volutpat orci suscipit ac. Praesent scelerisque urna metus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis pulvinar, sem a sodales eleifend, odio elit blandit risus, a dapibus ligula orci non augue. Nullam vitae cursus tortor, eget malesuada lectus. Nulla facilisi. Cras pharetra nisi sit amet orci dignissim, a eleifend odio hendrerit.
</p>
</article>
</section>
</div>
<div id="contentCenter">
<section>
<article>
<p>
Maecenas vitae purus at orci euismod pretium. Nam gravida gravida bibendum. Donec nec dolor vel magna consequat laoreet in a urna. Phasellus cursus ultrices lorem ut sagittis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vivamus purus felis, ornare quis ante vel, commodo scelerisque tortor. Integer vel facilisis mauris.
</p>
<img src="images/auto1.jpg" width="272" height="272" />
<p>
In urna purus, fringilla a urna a, ultrices convallis orci. Duis mattis sit amet leo sed luctus. Donec nec sem non nunc mattis semper quis vitae enim. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Suspendisse dictum porta quam, vel lobortis enim bibendum et. Donec iaculis tortor id metus interdum, hendrerit tincidunt orci tempor. Sed dignissim cursus mattis.
</p>
</article>
</section>
</div>
<div id="contentRight">
<section>
<article>
<img src="images/auto2.jpg" width="272" height="272" />
<img src="images/auto3.jpg" width="272" height="272" />
<p>
Cras eu quam lobortis, sodales felis ultricies, rhoncus neque. Aenean nisi eros, blandit ac lacus sit amet, vulputate sodales mi. Nunc eget purus ultricies, aliquam quam sit amet, porttitor velit. In imperdiet justo in quam tristique, eget semper nisi pellentesque. Cras fringilla eros enim, in euismod nisl imperdiet ac.
Fusce tempor justo vitae faucibus luctus.
</p>
</article>
</section>
</div>
</div>
<footer>
<div class="footerText">
<p>
Copyright © Pinco
<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<br />Fusce ornare turpis orci, nec egestas leo feugiat ac.
<br />Morbi eget sem facilisis, laoreet erat ut, tristique odio. Proin sollicitudin quis nisi id consequat.
</p>
</div>
<div class="footerLogo">
<img class="footerLogo" src="images/auto4.jpg" width="80" height="80" />
</div>
</footer>
</div>
</body>
</html>
and here is the CSS:
/* CSS Document */
* { margin: 0; border: 0; padding: 0; }
body { background: #8B0000; /* darkred */; }
body { margin: 0; border: 0; padding: 0; }
div#wrapper { margin: 0 auto; width: 960px; height: 100%; background: #FFC0CB /* pink */; }
header { position: relative; background: #005b97; height: 140px; }
header div.logo { float: left; width: 360px; height: 140px; }
header div.logo img.logo { width: 360px; height: 140px; }
header div.titolo { float: left; padding: 12px 0 0 35px; color: black; }
header div.titolo h1 { font-size: 36px; font-weight: bold; }
header div.titolo h2 { font-size: 24px; font-style: italic; font-weight: bold; color: white;}
header nav { position: absolute; right: 0; bottom: 0; }
header ul.menu { background: black; }
header ul.menu li { display: inline-block; padding: 3px 15px; font-weight: bold; }
div#mainContent { float: left; width: 100%; /* width: 960px; *//* height: 860px; */ padding: 30px 0; text-align: justify; }
div#mainContent img { margin: 12px 0; }
div#contentLeft { height: 900px; float: left; margin-left: 12px; border: 1px solid black; padding: 15px; width: 272px; background: #ccc; }
div#contentCenter { height: 900px; float: left; margin-left: 12px; border: 1px solid transparent; padding: 15px; width: 272px; background: #E00; }
div#contentRight { height: 900px; float: left; margin-left: 12px; border: 1px solid black; padding: 15px; width: 272px; background: #ccc; }
footer { clear: both; padding: 12px; background: #306; color: white; height: 80px; font-style: italic; font-weight: bold; }
footer div.footerText { float: left; }
footer div.footerLogo { float: right; }
a { color: white; text-decoration: none; }
EDIT 1:
I've checked all measurements again and carefully plugged in numbers until they
satisfied the following equation for the three uniform columns in the main area
with uniform collapsed margin areas on all sides:
TEXT_AREA * 3 + MARGIN * 4 + BORDER * 6 = 960px (the width of the
wrapper)
TEXT_AREA = WIDTH + 2 * PADDING
BORDER = 1
subject to the margin and padding set to reasonable values of course,
and here are some numbers which seemed OK which solve these constraints:
TEXT_AREA = 290px
MARGIN = 15px
BORDER = 1px
PADDING = 15px
WIDTH = 268px
which translates to the following:
div#mainContent { float: left; width: 960px; padding: 15px 0; text-align: justify; }
div#contentLeft { height: 900px; float: left; margin: 0 0 0 15px; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
div#contentCenter { height: 900px; float: left; margin: 0 0 0 15px; border: 1px solid transparent; padding: 15px; width: 268px; background: #E00; }
div#contentRight { height: 900px; float: left; margin: 0 15px 0 15px; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
However even now that everything is uniform, I still get the problem that when I zoom
out the rightmost column falls down below the others. One solution is to do the following:
div#contentRight { height: 900px; float: left; margin: 0 0 /* 15px */ 0 15px; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
so that now the right column has no right margin, but the visual result is the same.
Now, when I zoom out, the rightmost column does not fall down, but its right margin
is so small compared to the others, so really, there is still a small problem.
Edit 2:
OK, I've done some more searching and found an even better solution. The solution
consists in having the margins in between the div column elements the same and having
the left and right margin adjust automatically. In order to achieve this, I had to
do away with floats, and use "display: inline-block" which IMHO is much more suitable
than floats and was designed for the purpose at hand:
div#mainContent { padding: 15px 0; width: 960px; text-align: center; }
div#contentLeft { display: inline-block; vertical-align: top; height: 900px; margin: 0 0 0 0/*15px*/; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
div#contentCenter { display: inline-block; vertical-align: top; height: 900px; margin: 0 0 0 15px; border: 1px solid transparent; padding: 15px; width: 268px; background: #E00; }
div#contentRight { display: inline-block; vertical-align: top; height: 900px; margin: 0 0/* 15px */ 0 15px; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; }
div#mainContent section { text-align: justify; }
Now, at a normal zoom level all left margins will be 15px plus the last element's right
margin which will also be 15px. On the other hand, if I zoom out, there is some pixel
rounding going on, but the rounding is applied more or less equally on both sides,
which is somewhat better. This works in Firefox.
Edit 3:
Alas, I've tried reducing the in-between margins a bit, which makes the problem
go away with Chrome, but one of the div elements still drops down in IE10.
div#mainContent { padding: 15px 0; text-align: center; }
div#contentLeft { display: inline-block; vertical-align: top; height: 900px; margin: 0 0 0 0/* 20px increased from 15px */; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; overflow: hidden; }
div#contentCenter { display: inline-block; vertical-align: top; height: 900px; margin: 0 0 0 10px/* reduced from 15px */; border: 1px solid transparent; padding: 15px; width: 268px; background: #E00; overflow: hidden; }
div#contentRight { display: inline-block; vertical-align: top; height: 900px; margin: 0 0/* 20px increased from 15px */ 0 10px/* reduced from 15px */; border: 1px solid black; padding: 15px; width: 268px; background: #ccc; overflow: hidden; }
div#mainContent section { text-align: justify; }
Edit 4:
I've come up with a solution which works in Firefox, Chrome, and IE10.
Basically, I've created three div wrappers around the three columns
and taken measurements again ensuring all measurements are symmetric.
Here is the source code:
HTML File:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pinco</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<header>
<div class="logo">
<a href="http://pinco.com">
<img class="logo" src="images/PincoLogo5.png" alt="Pinco" />
</a>
</div>
<div class="titolo">
<h1>Benvenuti!</h1>
<h2>Siete arrivati al sito pinco.</h2>
</div>
<nav>
<ul class="menu">
<li>Menù Qui</li>
<li>Menù Quo</li>
<li>Menù Qua</li>
</ul>
</nav>
</header>
<div id="mainContent">
<div id="wrapperLeft">
<div id="contentLeft">
<section>
<article>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempor turpis est, nec varius est pharetra scelerisque. Sed eu pellentesque purus, at cursus nisi. In bibendum tristique nunc eu mattis. Nulla pretium tincidunt ipsum, non imperdiet metus tincidunt ac. In et lobortis elit, nec lobortis purus. Cras ac viverra risus. Proin dapibus tortor justo, a vulputate ipsum lacinia sed. In hac habitasse platea dictumst. Phasellus sit amet malesuada velit. Fusce diam neque, cursus id dui ac, blandit vehicula tortor.
Phasellus interdum ipsum eu leo condimentum, in dignissim erat tincidunt. Ut fermentum consectetur tellus, dignissim volutpat orci suscipit ac. Praesent scelerisque urna metus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Duis pulvinar, sem a sodales eleifend, odio elit blandit risus, a dapibus ligula orci non augue. Nullam vitae cursus tortor, eget malesuada lectus. Nulla facilisi. Cras pharetra nisi sit amet orci dignissim, a eleifend odio hendrerit.
</p>
</article>
</section>
</div>
</div>
<div id="wrapperCenter">
<div id="contentCenter">
<section>
<article>
<p>
Maecenas vitae purus at orci euismod pretium. Nam gravida gravida bibendum. Donec nec dolor vel magna consequat laoreet in a urna. Phasellus cursus ultrices lorem ut sagittis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Vivamus purus felis, ornare quis ante vel, commodo scelerisque tortor. Integer vel facilisis mauris.
</p>
<img src="images/auto1.jpg" alt="Auto 1" width="268" height="268" />
<p>
In urna purus, fringilla a urna a, ultrices convallis orci. Duis mattis sit amet leo sed luctus. Donec nec sem non nunc mattis semper quis vitae enim. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
</p>
</article>
</section>
</div>
</div>
<div id="wrapperRight">
<div id="contentRight">
<section>
<article>
<img src="images/auto2.jpg" alt="Auto 2" width="268" height="268" style="margin-top: 0" />
<img src="images/auto3.jpg" alt="Auto 3" width="268" height="268" style="margin-top: 0" />
<p>
Cras eu quam lobortis, sodales felis ultricies, rhoncus neque. Aenean nisi eros, blandit ac lacus sit amet, vulputate sodales mi. Nunc eget purus ultricies, aliquam quam sit amet, porttitor velit. In imperdiet justo in quam tristique, eget semper nisi pellentesque. Cras fringilla eros enim, in euismod nisl imperdiet ac.
Fusce tempor justo vitae faucibus luctus.
</p>
</article>
</section>
</div>
</div>
</div>
<footer>
<img class="footerLogo" src="images/auto4.jpg" alt="Auto 4" width="80" height="80" />
<p class="footerText">
Copyright © Pinco Inc.
<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<br />Fusce ornare turpis orci, nec egestas leo feugiat ac.
<br />Morbi eget sem facilisis, laoreet erat ut, tristique odio. Proin sollicitudin quis nisi id consequat.
</p>
</footer>
</div>
</body>
</html>
CSS File:
/* CSS Document */
*, body, article, secton, p { margin: 0; border: 0; padding: 0; }
body { background: #8B0000; /* darkred */; }
body { margin: 0; border: 0; padding: 0; }
div#wrapper { margin: 0 auto; width: 960px; height: 100%; background: #FFC0CB /* pink */; }
header { position: relative; background: #005b97; height: 140px; }
header div.logo { float: left; width: 360px; height: 140px; }
header div.logo img.logo { width: 360px; height: 140px; }
header div.titolo { float: left; padding: 12px 0 0 35px; color: black; }
header div.titolo h1 { font-size: 36px; font-weight: bold; }
header div.titolo h2 { font-size: 24px; font-style: italic; font-weight: bold; color: white;}
header nav { position: absolute; right: 0; bottom: 0; }
header ul.menu { background: black; }
header ul.menu li { display: inline-block; padding: 3px 15px; font-weight: bold; }
div#mainContent { float: left; padding: 15px 0; height: 900px; }
#wrapperLeft { float: left; margin-left: 15px; width: 305px; }
#wrapperCenter { float: left; margin: 0 15px 0 15px; width: 290px; }
#wrapperRight { float: left; margin-right: 15px; width: 305px; }
div#contentLeft { border: 1px solid black; padding: 15px; width: 273px; height: 868px; background: #ccc; overflow: hidden; }
div#contentCenter { border: 1px solid transparent; padding: 15px; width: 258px; height: 868px; background: #E00; overflow: hidden; }
div#contentRight { border: 1px solid black; padding: 15px; width: 273px; height: 868px; background: #ccc; overflow: hidden; }
div#mainContent section { text-align: justify; }
div#mainContent img { margin: 12px 0; }
footer { clear: both; padding: 12px; background: #306; color: white; height: 80px; font-size: 12px; font-style: italic; font-weight: bold; overflow: hidden; }
footer img.footerLogo { float: right; }
a { color: white; text-decoration: none; }
This is probably caused by sub-pixel rounding.
As you zoom, your browser may calculate pixel values with fractions of pixels. As a result of rounding these values up or down, pixel-perfect layouts can break. (Different browsers handle this in different ways.)
I had decent luck converting your pixel values to percentage values.
Here are the values that worked for me:
div#contentLeft,
div#contentCenter,
div#contentRight {
margin-left: 1.1%;
padding: 1.56%;
width: 28.3%;
}
Edit:
Here's another method, which essentially centers the three boxes in div#mainContent rather than spacing them so tightly with margins. It allows them a little more room to flex when zoomed.
I removed the margin-left from div#contentLeft and added the following CSS to center the three boxes:
div#wrapper {
overflow:hidden; /* ADDED THIS TO AVOID HORIZONTAL SCROLL */
}
div#mainContent {
position: relative; /* ADDED THIS */
left: 50%; /* ADDED THIS */
float: left;
padding: 30px 0px;
text-align: justify;
}
div#contentLeft {
position: relative; /* ADDED THIS */
left: -50%; /* ADDED THIS */
background: none repeat scroll 0% 0% #CCCCCC;
border: 1px solid black;
float: left;
height: 900px;
padding: 15px;
width: 272px;
/* margin-left:12px; REMOVED THIS */
}
div#contentCenter {
position: relative; /* ADDED THIS */
left: -50%; /* ADDED THIS */
background: none repeat scroll 0% 0% #EE0000;
border: 1px solid transparent;
float: left;
height: 900px;
margin-left: 12px;
padding: 15px;
width: 272px;
}
div#contentRight {
position: relative; /* ADDED THIS */
left: -50%; /* ADDED THIS */
background: none repeat scroll 0% 0% #CCCCCC;
border: 1px solid black;
float: left;
height: 900px;
margin-left: 12px;
padding: 15px;
width: 272px;
}
The boxes remain floated on one row even when Firefox is zoomed all the way out.

How come my red border is not wrapping around my text div and my side bar div

How come my red border is not wrapping around my text div and my side bar div. Here's my code:
CSS:
body{
background-color: #d7d7d7;
color: #666666;
font-family: arial, sans-serif;
font-size: x-small;
}
div#header {
background-color: #323232;
height: 140px;
width: 950px;
}
div#maincontainer {
background-color: #d7d7d7;
width: 950px;
height: auto;
margin-top: 5px;
border: 1px solid red;
}
div#maintextcontainer{
//background-color: #333333;
width: 640px;
//margin-right: 10px;
margin: 1px;
float: left;
color: black;
}
div#maintextcontainer h2{
color: #4f4f4f;
}
div#sidebarcontainer {
//background-color: #333333;
width: 300px;
float: left;
color: black;
margin: 1px;
}
div#footer{
background-color: #323232;
width: 950px;
margin-top: 5px;
clear: left;
}
div#global{
width: 950px;
margin: auto;
}
HTML:
<div id="global">
<div id="header"> This is the header div</div>
<div id="maincontainer">
<div id="maintextcontainer">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi aliquam neque eu turpis euismod eget suscipit nulla ultrices. Donec sagittis mi non sem vestibulum elementum dapibus risus auctor. Praesent tristique laoreet dapibus. Integer vel ligula lorem, et pharetra lorem.
</div>
<div id="sidebarcontainer">Nam at lectus vitae est tempor lacinia sed et ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent interdum mi id nisi aliquet pulvinar.
</div>
</div>
<div id="footer">This is Footer Text</div>
</div>
You need to add overflow:auto; to div#maincontainer. Floated elements will flow outside of their containing element, unless this attribute is set.
Also, a double slash (//) is not a valid commenting symbol in CSS.