How To Have Multiple Divs On One Line With Even Spacing - html

Trying to get multiple divs on the same line with even spacing. So they nicely fit the whole container.
Here is what i have got so far. Tried to set margin right and left equal to the same on all the boxes, but it is still tricky to make it even and sometimes the final box will go on a new line.
HTML
<div id="serviceBox">
<div class="serviceBox1">
<h2> Heading 1</h2>
<p>Information</p>
</div>
<div class="serviceBox2">
<h2>Heading 2</h2>
<p> Information</p>
</div>
<div class="serviceBox3">
<h2>Heading 3</h2>
<p>Information</p>
</div>
<div class="serviceBox4">
<h2>Heading 4</h2>
<p>Information</p>
</div>
</div>
CSS
#serviceBox
{
width:100%;
margin: 0 auto;
margin-top:75px;
height:250px;
border:1px solid black;
}
.serviceBox1, .serviceBox2, .serviceBox3, .serviceBox4 {
float:left;
width:20%;
height: 250px;
background-color: white;
border: 1px solid #bdbdbd;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0 0 10px #bdbdbd;
-webkit-box-shadow: 0 0 10px #bdbdbd;
box-shadow: 0 0 10px #bdbdbd;
}
https://jsfiddle.net/ruJ2R/3/

I would suggest adding a new element inside each serviceBox, in this example the div with class box
CSS:
#serviceBox
{
width:100%;
margin: 0 auto;
margin-top:75px;
height:250px;
border:1px solid black;
}
.serviceBox1, .serviceBox2, .serviceBox3, .serviceBox4 {
float:left;
width:25%;
}
.box{
height: 250px;
background-color: white;
border:1px solid #bdbdbd;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0 0 10px #bdbdbd;
-webkit-box-shadow: 0 0 10px #bdbdbd;
box-shadow: 0 0 10px #bdbdbd;
}
HTML
<div id="serviceBox">
<div class="serviceBox1">
<div class="box">
<h2> Heading 1</h2>
<p>Information</p>
</div>
</div>
<div class="serviceBox2">
<div class="box">
<h2>Heading 2</h2>
<p> Information</p>
</div>
</div>
<div class="serviceBox3">
<div class="box">
<h2>Heading 3</h2>
<p>Information</p>
</div>
</div>
<div class="serviceBox4">
<div class="box">
<h2>Heading 4</h2>
<p>Information</p>
</div>
</div>
</div>
This way the service boxes are nicely a quarter of the container and inside service box you can add the border and shading to the new box element

UPDATE: because of the borders , either apply box-sizing:border-box to your style, or put your div with borders inside one more div.
There are at least 4 different ways of doing it.
using float layout
using display:table-cell
using display:inline-block
using absolute positioning
.serviceBox {
box-sizing:border-box;
margin-right:4%;
float:left;
width:20%;
height: 250px;
background-color: white;
border: 1px solid #bdbdbd;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0 0 10px #bdbdbd;
-webkit-box-shadow: 0 0 10px #bdbdbd;
box-shadow: 0 0 10px #bdbdbd;
}
.serviceBox:first { margin-left:4%; }
see updated fiddle

Your problem is that the boxes have a border, so giving them width and margin in percentages that sum to 100% don't work: each box has an extra 2 pixels from the border, pushing the last one off the row. But you can solve this problem by giving them negative margins to compensate for the border:
width:25%;
margins:0 -1px;

try this,
.serviceBox {
margin-left:4%;
float:left;
width:20%;
height: 250px;
background-color: white;
border: 1px solid #bdbdbd;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0 0 10px #bdbdbd;
-webkit-box-shadow: 0 0 10px #bdbdbd;
box-shadow: 0 0 10px #bdbdbd;
}

Related

Can't move elements in css divs

For some reason I have a parent div called banner which contains a number of child divs, however in my css styles sheet I can't seem to move any elements especially the "CRAFT412" logo image to my desired position within the banner. I've tried using left/right/top/bottom to move these elements but nothing seems to budge them. If anyone could help me here I'd appreciative it.
Here is my HTML for a page on my site
<!--TOP BANNER SECTION-->
<div id="banner">
<div id="logo">
<img src="images/CRAFT412 - Logo.png" width="500" height="281" alt="CRAFT412">
</div>
<div id="ip_box"></div>
<div id="ip_text">
<p>SERVER IP<P/>
<p>craft412.serveminecraft.net<P/>
</div>
<div id="teamspeak_box"></div>
<div id="teamspeak_box_2"></div>
<div id="teamspeak_text">
<p>TEAMSPEAK<P/>
</div>
<div id="teamspeak_image">
<a href="ts3server://craft412.serveminecraft.net:9987">
<img src="images/CRAFT412 - Box - Teamspeak.png" alt="TEAMSPEAK">
</a>
</div>
</div>
Also here is my CSS for the same divs
/*CSS FOR ALL PAGES*/
/*BODY/WRAPPER SECTION*/
body {
background:#EEEEEE;
background-repeat: no-repeat;
background-attachment: fixed;
}
#wrapper {
width: 1750px;
margin: 0 auto;
background-color: white;
border-radius: 5px;
box-shadow: 0px 1.5px 2px 0px;
border: 1.5px solid #E0E0E0;
color: #E0E0E0;
}
/*TOP BANNER SECTION*/
#banner { height:100px; }
#logo {}
#ip_box {
width:200px;
height:43px;
background:#212121;
border-radius: 5px;
box-shadow: 1px 1px 5px;}
#ip_text {
color: white;
font-size: 15px;
}
#teamspeak_box {
width:159px;
height:43px;
background:#212121;
border-radius: 5px;
box-shadow: 1px 1px 5px;
}
#teamspeak_box_2 {
width:43px;
height:43px;
background:#313131;
border-radius: 5px 0px 0px 5px;
}
#teamspeak_text { color: white; }
#teamspeak_image {}
Give the parent div a property :
Position:relative;
Also give the property to child div:
Position:absolute;
Now you can change the places of child div inside the "BANNER" div. by using TOP , BOTTOM, RIGHT, LEFT

How to keep a ribbon inside its parent element?

I have a Bootstrap .hero-unit box, and then I have a Fork me on Github ribbon that I am displaying in the top left corner of this box.
Usually a ribbon is placed in a corner of the screen, but in the case it isn't. So how do I hide the part of the ribbon that overflows its parent element?
The HTML:
<div class="hero-unit my-unit">
<a class="ribbon" href="#">Fork me on Github</a>
</div>
</div>
The CSS for the parent element:
.my-unit {
border-radius: 10px;
border: 1px solid #cfcece;
}
The CSS for the ribbon:
.ribbon {
position:absolute;
padding:5px 45px;
width:128px;
background-color:#555451;
color:#e5e5e5;
font-size:13px;
font-family:sans-serif;
text-decoration:none;
font-weight:bold;
-webkit-backface-visibility:hidden;
letter-spacing: .5px;
border:2px dotted #e5e5e5;
box-shadow:0 0 0 3px #383733,0 0 20px -3px rgba(0,0,0,.5);
text-shadow:0 0 0 #e5e5e5,0 0 5px rgba(0,0,0,.3);
margin-top:10px;
margin-left:-80px;
-ms-transform:rotate(330deg);
-moz-transform:rotate(330deg);
-webkit-transform:rotate(330deg);
transform: rotate(330deg);
}
Your HTML should be
<div class="container">
<div class="hero-unit my-unit">
<img class="ribbon"src="https://camo.githubusercontent.com/82b228a3648bf44fc1163ef44c62fcc60081495e/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f7265645f6161303030302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png">
</div>
</div>
Your CSS should be
.ribbon{
top: 0;
left: 0;
border: 0;
}
Demo : http://jsbin.com/piqinore/2/
Did you check the official github page to incorporate this ribbon , check it out at
https://github.com/blog/273-github-ribbons

multiple div having dynamic height and also to keep 2 divs that are side by side

I want to display the div content (having different heights) one after the other, with 2 divs side by side. I have tried to do this but I am getting space between divs having different heights.
Here is the code:
<html>
<div class="itemlist">
<div class="ItemView">
<p>content</p>
</div>
<div class="ItemView">
<p>content</p>
</div>
<div class="ItemView">
<p>content</p>
</div>
<div class="ItemView">
<p>content</p>
</div>
<div class="ItemView">
<p>content</p>
</div>
</div>
.ItemView {
width: 46%;
float:left;
background: #fff;
margin: 10px 10px 0px 10px;
border: solid 1px #aaa;
text-align: left;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
-moz-box-shadow: 2px 2px 2px #ddd;
-webkit-box-shadow: 2px 2px 2px #ddd;
box-shadow: 2px 2px 2px #ddd;
min-height: 90px;
padding: 0;
}
Current output:
You should seperate the 2 columns and put all elements of a column in a floated container.
See this FIDDLE
HTML :
<div class="itemlist">
<div class="col">
<div class="ItemView">
<p>content</p>
</div>
...
</div>
<div class="col">
<div class="ItemView">
<p>content</p>
</div>
...
</div>
</div>
CSS :
.ItemView {
width: 100%;
background: #fff;
margin: 10px 0 0;
border: solid 1px #aaa;
text-align: left;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
-moz-box-shadow: 2px 2px 2px #ddd;
-webkit-box-shadow: 2px 2px 2px #ddd;
box-shadow: 2px 2px 2px #ddd;
min-height: 90px;
padding: 0;
}
.col{
float:left;
width:46%;
margin: 0 10px;
}
.big {
height:200px;
}

Why do I get wrong alignment in this if I use bootstrap?

If I use bootstrap, it messes the alignment up on my page. Member names should be appeared right next to icon, but with Bootstrap, they overlap the icon.
How can I fix this?
Also, when the browser window is made smaller, the square line gets messed up too. I want the data to have a border when the window is small.
So I don't want it to look like this:
But rather, like this:
If possible I want to have these icon, and name in middle not on the top.
DEMO http://jsfiddle.net/sbq7X/
HTML
<div class="store_row">
<div class="store_left">
<div class="store_title">walmart</div>
<div class="store_location">Located in California</div>
</div>
<div class="store_right">
<div class="store_icon">
<img class="img-polaroid" src="http://www.miraiha.net/wpblog/wp-content/uploads/2010/10/designreviver-free-twitter-social-icon-300x266.jpg" />
</div>
<div class="introduction">
<div class="name1">John Tailor</div>
<div class="name2">Mike Smith</div>
<div class="name3">Jessica Swan</div>
</div>
</div>
</div>
<div class="store_row">
<div class="store_left">
<div class="store_title">walmart</div>
<div class="store_location"><span class='text-error'>Located in California</span></div>
</div>
<div class="store_right">
<div class="store_icon">
<img class="img-polaroid" src="http://media-cache-ec1.pinterest.com/avatars/walmarthub-1349815045_600.jpg" />
</div>
<div class="introduction">
<div class="name1">John Tailor</div>
<div class="name2">Mike Smith</div>
<div class="name3">Jessica Swan</div>
</div>
</div>
CSS
div.store_row{
min-width: 300px;
margin-bottom: 20px;
margin-left: 10px;
margin-right: 10px;
border:1px solid;
display:table;
}
div.store_left{
width: 300px;
display:inline-block;
vertical-align:top;
}
div.store_right{
width: 300px;
display:inline-block;
vertical-align:top;
background-color: #FFFFFF;
}
div.store_title{
background-color: #000000;
color: #FFFFFF;
height: 35px;
padding:5px;
}
div.store_location{
height: 35px;
border-right:1px solid;
background-color: #FFFFFF;
padding:5px;
}
div.store_icon{
width: 70px;
height: 70px;
display:inline-block;
}
div.store_icon img{
width:100%;
height:100%;
}
div.introduction{
display:inline-block;
vertical-align:top;
width:200px;
text-align: left;
}
.... and bootstrap
img-polaroid class has 4px padding and it causes the problem:
.img-polaroid {
padding: 4px;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.2);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
See the fiddle where it's removed.
EDIT: The alignment is working fine as well. You have static width for the all elements and they're too wide for fiddle. I've decreased their size so they are inline now.

Element Align Problem - Negative margins, images etc

I'm trying to make a header that goes outside the borders of my sidebar and has a shadow image that makes it look like it is a book-mark.
Something similar to this: http://inelmo.com/images/img2.png
Right now I tried my best, but it is not looking correct. here is my code for sidebar and header That I think should work to make this effect, but it isn't.
HTML
<!-- Sidebar -->
<aside id="sidebar">
<!-- header div -->
<div id="sideProfile">
<!-- Span with image background -->
<span id="sideHshadow"></span>
</div>
</aside>
CSS
#sidebar {
padding: 15px;
width: 400px;
}
/*Span with shadow image to make it look like a bookmark */
#SideHshadow {
height: 6px;
width: 12px;
margin: 0 0 -6px 0;
float: right;
background: url("../images/sidebar_header_shadow.png") no-repeat;
}
#sideProfile {
background:#333333;
border-bottom: 1px solid #2d2d2d;
height: 50px;
width: 400px;
margin: 0 -12px 0 0;
box-shadow: 0 1px 2px #77bee6;
-moz-box-shadow: 0 1px 2px #77bee6;
-webkit-box-shadow: 0 1px 2px #77bee6;
-webkit-border-radius: 7px 7px 0 7px;
-khtml-border-radius: 7px 7px 0 7px;
-moz-border-radius: 7px 7px 0 7px;
border-radius: 7px 7px 0 7px;
}
Anyone knows how to make it look like in example? Thnx
Here is the #sideHshadow background image file: http://inelmo.com/images/sidebar_header_shadow.png
Here's a pure CSS version: http://jsfiddle.net/bcZKh/2/
Code below:
<div id="list">
<div class="item selected">Nationwide Coverage Area</div>
<div class="shadow"></div>
</div>
body {margin:40px}
#list {width:200px;border-radius:8px;min-height:200px;background:#E6E5E0;padding:20px 0;position:relative}
.item {color:#fff;font-size:0.8em;line-height:24px;font-family:sans-serif;text-indent:24px;margin-right:-12px;margin-left:-12px;position:relative;z-index:1}
.item.selected {background:#C74312;border-radius:4px;border-bottom-left-radius:0}
.shadow {border-color:transparent #733411 transparent transparent;border-width:12px;border-style:solid;height:0;width:0;position:absolute;top:32px;left:-24px;z-index:0}