Horizontally centering and spacing with css - css

I want to produce an image gallery style page for a responsive web site.
Depending on device and orientation the page displays between 1 and 4 images horizontally.
How can I achieve this and ensure that:
The space between the images remains equal
Each row is centered on the page regardless of device,
orientation and the number of images.
I would appreciate any pointers, as I am new to this I may have overlooked the correct terminology while attempting to find the answer using the search feature.
Thanks for your time and consideration.
#verwrapper {
text-align:left;
width:100%;
margin-left: auto;
margin-right: auto;
padding-top:20px;
overflow: hidden;
background: none repeat scroll 0 0 #FFFFFF;
text-align:center; /* for IE */
}
.ver{
position:relative;
border-bottom:2px solid #686868;
width:200px;
height:310px;
background-color:#fff;
margin-bottom:20px;
margin:0 auto;
padding:0 0.5em;
overflow:hidden;
float:left;
}
.verbild{
position:relative;
height:200px;
width:200px;
float:left;
outline:2px solid #C0C0C0;
outline-offset: -2px;
}
<div id="verwrapper">
<div class="ver">
<div class="verbild"><img src="image1.jpg" width="200" height="200" /></div>
</div>
<div class="ver">
<div class="verbild"><img src="image2.jpg" width="200" height="200" /></div>
</div>
<div class="ver">
<div class="verbild"><img src="image3.jpg" width="200" height="200" /></div>
</div>
</div>
Nick

Use same padding for right & left side(em or %), use margin:0 auto. like that -
.test1{
margin:0 auto;
padding:0 0.5em;
}

Try this. Just change sizes as you need.
<div class="row">
<div class="image">
<img src="http://placehold.it/350x150"/>
</div>
<div class="image">
<img src="http://placehold.it/350x150"/>
</div>
<div class="image">
<img src="http://placehold.it/350x150"/>
</div>
<div class="image">
<img src="http://placehold.it/350x150"/>
</div>
</div>
<style>
.row {width: 500px; margin: 0 auto;}
.image {width: 25%; float: left;box-sizing: border-box; padding: 0 5px;}
.image img { width: 100%;}
</style>

Related

2 floating divs on top of 2 centered divs

I'm trying to create something that will allow me to put something on top of images in this case, small images.
basically, it goes like this and both main divs are centered:
http://jsmith.elementfx.com/images/questions.png
tia.
Sorry, here is
HTML
<div id="container">
<div id="left"><img src="" width="130" height="130" style="border:2px solid #72d6fe" /></div>
<div id="leftimage"><h2>963</h2></div>
<div id="right"><img src="" width="130" height="130" style="border:2px solid #72d6fe" /></div>
<div id="rightimage"><h2>434</h2></div>
</div>
CSS
#container{
margin:0px auto;
width:320px;
text-align:center;
margin-bottom:20px;
}
#left {
float:left;
margin-left:15px;
margin-right:20px;
position:relative;
}
#leftimage{
position:absolute;
padding-top:2px;
margin-left:5px;
width:65px;
}
#right {
margin-right:15px;
}
#rightimage{
position:absolute;
padding-top:2px;
width:65px;
}
you have to use z-index and position to acheive it,
DEMO
HTML
<div id="container">
<div id="left"><img src="" width="130" height="130" style="border:2px solid #72d6fe" /></div>
<div id="leftimage"><h2>963</h2></div>
<div id="right"><div id="rightimage"><h2>434</h2></div><img src="" width="130" height="130" style="border:2px solid #72d6fe" /></div>
</div>
CSS
#container{
margin:0px auto;
width:320px;
text-align:center;
margin-bottom:20px;
}
#left {
float:left;
margin-left:15px;
margin-right:20px;
position:relative;
}
#leftimage{
position:absolute;
padding-top:2px;
margin-left:5px;
width:65px;
z-index:1;
}
#right {
position:relative;
margin-right:15px;
}
#rightimage{
margin-left:175px;
position:absolute;
z-index:1000;
}
use this code, the calculation of the width and height of images would be according to your images:
HTML
<div class="container">
<div class="img1">
<img src="https://cdn1.iconfinder.com/data/icons/windows-8-metro-style/128/test_tube.png" width="32" height="32" />
</div>
<div class="img2">
<img src="https://cdn1.iconfinder.com/data/icons/windows-8-metro-style/128/test_tube.png" width="32" height="32" />
</div>
</div>
CSS
.container{
width:270px;
margin:0 auto;
overflow:hidden;
}
.img1,.img2{
width:128px;
height:128px;
background:url(https://cdn1.iconfinder.com/data/icons/windows-8-metro-style/128/test_tube.png);
float:left;
margin-right:10px;
border:1px solid #000;
}
.img2{margin:0;}
DEMO jsfiddle for this
Demo Fiddle - Quad view with 3 layered images
<div class="container start">
<img src="http://www.placehold.it/300/555555"></img>
<div id="base1" class="base">
<img src="http://www.placehold.it/200/654321"></img>
<div id="overlay1" class="overlay">
<img src="http://www.placehold.it/100/123456"></img>
</div>
</div>
</div>
.base {
width: 200px;
height: 200px;
position: relative;
top: -290px;
left: 10px;
}
.overlay {
width:100px;
height:100px;
position: relative;
left: 10px;
top: -190px;
}
.container {
left:100px;
width: 300px;
height: 300px;
margin: 10px;
float: left;
}
.start {
clear: left;
}

How to layout divs as specified?

Please help me to create layout as specified on image below.
I have tried to achieve it but my knowledge of CSS is not enough and layout has to be done ASAP... I tried to play with CSS attributes like float, overflow, position:absolute, relative, etc but results were disappointing - divs overflow with each other, don't position properly and so on. Each div contains a lot of content - other divs, images, lists, etc.
Desired result:
<div style="float: left; width: 100px; height: 200px; background: #f00;">content...</div>
<div style="float: right; width: 200px; height: 300px; background: #0f0;">content...</div>
<div style="clear: both;"></div>
<div style="float: right; width: 100px; height: 300px; background: #00f;">content...</div>
<div style="clear: both;"></div>
<div style="float: right; width: 500px; height: 200px; background: #ff0;">content...</div>
<div style="clear: both;"></div>
<div style="width: 100%; height: 100px; background: #000;">content...</div>
<body>
<div class="box">
<div class="red">
</div>
<div class="green">
</div>
</div>
<!-- -->
<div class="box">
<div class="blue">
</div>
</div>
<!-- -->
<div class="box">
<div class="yellow">
</div>
</div>
<!-- -->
<div class="box">
<div class="black">
</div>
</div>
</body>
.box{
width:400px;
clear:both;
height:400px;
margin-top:10px;
}
.yellow{
background:yellow;
width:40%;
height:100%;
float:right;
}
.black{
background:black;
width:80%;
height:20%;
float:right;
}
.blue{
background:blue;
width:20%;
height:100%;
float:right;
}
.red{
background:red;
width:30%;
height:60%;
float:left;
}
.green{
background:green;
width:60%;
height:90%;
float:left;
margin-left:10%;
}

Html disappearing divs below image

I have a problem. I'm making a website, and it has part which is transparent (png image). But if it covers other div, that said div part that is covered disappears. I've tried some things, and nothing helped. So...
Index.html
<div id="TopLine">
<div id="Logo">
<img src="images/logo.png" width="420" height="248"/>
<div id="Menu">
</div>
</div>
</div>
<div id="Main">
<div id="Content">
</div>
<div id="Twitter">
</div>
<div style="clear:both"></div>
</div>
base.css
#Main {width:70%; padding: 10px 0 0 0; margin:0 15% 0 15%; text-decoration:none; background:#663333; border-radius: 15px;}
#Twitter {width:auto; height:auto; max-height:450px; margin: 0 10% 0 60%; background:#00FF00; float:right;}
#Content {width:auto; height:40%; background:#00FF00; float:left;}
#TopLine {width:auto; height:auto;}
#Logo {width: 100px; height:100px; margin: 10% 0 0 15%;}
image:
The background is not disappearing, it doesn't have a background. Your "TopLine" element and its children should be inside of main, from there you may position your element as you please (probably using position: relative)

center fixed width divs in a variable parent div

I have a problem I can't solve.
i'm trying to auto center multiple 150x150px divs in a parent div that is 80% width (but it could also be 90% or 100%).
I have an isotope JQuery attached that works fine but when I enlarge my navigator window, the child divs do not move and furthermore, they do not center "live" (the menu above works fine).
Here is the html code :
<div class="portfolioContainer">
<div id="marque" class="interieur">
<p class="categorie"><a href="http://www.arper.it" target="_blank">
<img src="images/logo_arper_140_Noir.jpg" width="100" height="33"></a><br>
<span class="txt">ARPER</span><br>
MOBILIER</p>
</div>
<div id="marque" class="interieur exterieur">
<p class="categorie"><a href="http://www.b-line.it" target="_blank">
<img src="images/logo_bline_140_Noir.jpg" width="140"></a><br>
<span class="txt">B-LINE</span><br>
MOBILIER</p>
</div>
<div id="marque" class="audio ipod">
<p class="categorie"><a href="http://www.bowers-wilkins.fr" target="_blank">
<img src="images/logo_BW_140_Noir.jpg" width="80" height="33"></a><br>
<span class="txt">BOWERS & WILKINS</span><br>
AUDIO</p>
</div>
<div id="marque" class="audio">
<p class="categorie"><a href="http://www.clearaudio.de" target="_blank">
<img src="images/logo_clearaudio_140_Noir.jpg" width="80" height="74"></a><br>
<span class="txt">CLEARAUDIO</span><br>
PLATINES VINYLE</p>
</div>
</div>
and the CSS:
#container {
width:80%;
padding-top:50px;
position:relative;
margin: auto;
text-align:center;
}
p {
width:150px;
margin:0;
padding:0;
position:absolute;
bottom:20px;
text-align:center; /* centrage horizontal */
}
img {
padding-top:5px;
padding-bottom:10px;
}
#marque {
position:relative;
width: 150px;
height: 150px;
margin:2px;
float:left;
border: solid 1px #333;
text-align:center;
}
The page can be found at this address to see the whole html/CSS code:
www.pixsix.fr/marques.html
replace float: left to display: inline-block
test it :
#marque {
position:relative;
width: 150px;
height: 150px;
margin:2px;
display: inline-block;
border: solid 1px #333;
text-align:center;
}

Sticky footer containing multiple divs not working

I'm really struggling with my footer. I've followed the instructions at http://www.cssstickyfooter.com/ to make my footer stick to the bottom of the page. It works fine until I add divs into the footer div - the purple background and image disappears. I would do it as a single div but I can't work out how to do the zigzag edge without creating a separate box.
Any help would be greatly appreciated! I've been trying for days to get this to work.
Here is my HTML:
<body>
<div id="wrapper">
<!-- Begin Header -->
<div id="header">
<img src="images/logo.png" width="435px" height="112px" alt="Lauren Womack Logo" />
<div id="menu">
<img src="images/menu/home.png" width="142" height="160" alt="Home" />
<img src="images/menu/about.png" width="131" height="157" alt="About" />
<img src="images/menu/contact.png" width="128" height="160" alt="Contact" />
</div>
</div>
<!-- End Header -->
<!-- Begin Content -->
<div id="content">
<div id="rightholder">
<div class="outerleft">
<div class="inner"><h2>Animation and Interactive</h2>
</div>
</div>
<div class="outerright">
<div class="inner">
<h2>Web Design</h2>
</div>
</div>
<div class="outerleft">
<div class="inner">
<h2>Print Design</h2>
</div></div>
<div class="outerright">
<div class="inner">
<h2>Illustration</h2>
</div>
</div></div> <!-- End Content -->
</div>
</div><!-- Begin Footer -->
<div id="footer">
<div class="footeredge"> </div>
<div class="footerinner"> <p>© Lauren Womack 2012</p>
</div> </div> </div>
<!-- End Footer --></body></html>
And here's my css:
body {font-size: 13px; background: url(images/background.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; height: 100%;}
html {height: 100%;}
#wrapper{ min-height:100%; min-width:992px; margin-left:0px; margin-right:0px;}
#header {height: 170px; padding-top:36px; border: none;}
#menu {float:right;}
#content { position: relative; min-width: 1141px; border:none;background: none; overflow:auto; padding-right:32px; padding-left:32px; padding-bottom: 86px;}
#rightholder { float: right; clear: left;min-width: 639px;width: 60%;padding-top: 90px;}
.outerright {background-image:url(images/threadborder.jpg);min-width: 257px;width: 45%; height: 98px; margin-top: 22px; margin-bottom: 22px; margin-left: 20px;float: right;clear: right;}
.outerleft {background-image:url(images/threadborder.jpg);
min-width: 257px; width: 45%; height: 98px; margin-top: 22px;margin-bottom: 22px;margin-right: 20px; float: left;clear: left;}
.inner {padding: 5px; height: 87px;}
#footer {position: relative; margin-top:-86px; margin-left:0px; margin-right:0px; padding-left:0px; padding-right:0px; height:86px; clear:both; padding-right: 32px; margin-left:0px; margin-right:0px; border: none;
/*Opera Fix*/
body:before {
content:"";
height:100%;
float:left;
width:0;
margin-top:-32767px;/
}
.footeredge {
background-color: none;
background-image:url(images/footer/zigzag.png);
background-repeat:repeat-x;
height: 20px;
}
.footerinner {
background-color:#663366;
height: 66px;
}
How I want it to look: http://tinypic.com/r/242swuc/6 The purple box at the bottom and the zigzag isn't showing though, just the text.
There's no closing curly brace for #footer, which in turn break's your style declarations after this point.

Resources