remove unwanted spaces between 2divs with css - html

Hi i has created this simple design:
body{
background: url("../imgs/bg_pattern.gif") scroll 0 0% repeat, url("../imgs/1.jpg") no-repeat scroll 0 0% / 100% 100%;
margin: auto;
}
#panel{
height: 100%;
width: 300px;
background-color: #232325;
float: right;
}
#audio{
width: 100%;
height: 11%;
background-color: red;
}
#term{
width: 100%;
height: 11%;
background-color: blue;
}
#content{
width: 100%;
height: 67%;
background-color: green;
}
#footer{
width: 100%;
height: 11%;
background-color: pink;
}
.term{
background-color: black;
height: 100%;
width: 25%;
display: inline-block;
border-right: solid red;
}
.term:first-child{
margin-left: 0;
}
.term:last-child{
border-right: none;
}
<div id="panel">
<div id="header">
<div id="audio"></div>
<div id="term">
<div class="term"></div>
<div class="term"></div>
<div class="term"></div>
<div class="term"></div>
</div>
</div>
<div id="content"></div>
<div id="footer"></div>
</div>
But when I see the result, the divs which are in the term div have some space between each other. Setting the padding and margin to zero doesn't remove the space.
What should I do to remove the space to set the divs exactly near to each other?

One solution is to use in term container display: flex:
body {
background: url("../imgs/bg_pattern.gif") scroll 0 0% repeat, url("../imgs/1.jpg") no-repeat scroll 0 0% / 100% 100%;
margin: auto;
}
#panel {
height: 100%;
width: 300px;
background-color: #232325;
float: right;
}
#audio {
width: 100%;
height: 11%;
background-color: red;
}
#term {
width: 100%;
height: 11%;
background-color: blue;
display: flex;/*Add display flex*/
}
#content {
width: 100%;
height: 67%;
background-color: green;
}
#footer {
width: 100%;
height: 11%;
background-color: pink;
}
.term {
background-color: black;
height: 100%;
width: 25%;
display: inline-block;
border-right: solid red;
}
.term:first-child {
margin-left: 0;
}
.term:last-child {
border-right: none;
}
<div id="panel">
<div id="header">
<div id="audio"></div>
<div id="term">
<div class="term">asd</div>
<div class="term">asd</div>
<div class="term">asd</div>
<div class="term">asd</div>
</div>
</div>
<div id="content"></div>
<div id="footer"></div>
</div>
Reference
flex

the problem is that Inline-block have some default spaces ,
use Float to left better than Inline-block and use a clearfix class :
#term{
width: 100%;
height: 11%;
background-color: blue;
**overflow: hidden;**
}
.term{
background-color: black;
height: 100%;
width: 25%;
**float : left ;**
border-right: solid red;
}
http://jsfiddle.net/n0zxmgoy/

As stated earlier, any white space between inline blocks is retained in the layout, so one way
of getting rid of it is to make sure that the inline block elements have no intervening space
in the HTML mark-up.
Also, you need to set a reference height so that the height percentage values work as expected.
I did this by adding height: 100% to the html and body tags.
Also, make sure to add a height value to the #header element, which makes the arithmetic
a bit easier to deal with.
A subtle point involves the right border on the .term elements. You can either use the
CSS calc value or box-sizing: border-box, you can try either.
html, body {
height: 100%; /* this may be needed... */
}
body{
background: url("../imgs/bg_pattern.gif") scroll 0 0% repeat, url("../imgs/1.jpg") no-repeat scroll 0 0% / 100% 100%;
margin: auto;
}
#panel{
height: 100%;
width: 300px;
background-color: #232325;
float: right;
}
#header {
width: 100%;
height: 22%;
}
#audio{
width: 100%;
height: 11%;
background-color: red;
}
#term{
width: 100%;
height: 50%;
background-color: blue;
}
#content{
width: 100%;
height: 67%;
background-color: green;
}
#footer{
width: 100%;
height: 11%;
background-color: pink;
}
.term{
background-color: black;
height: 100%;
width: calc(25% - 2px);
/* box-sizing: border-box; optional alternative */
display: inline-block;
border-right: 2px solid red;
}
.term:first-child{
margin-left: 0;
}
.term:last-child{
border-right: none;
width: 25%; /* you need to consider this... */
}
<div id="panel">
<div id="header">
<div id="audio"></div>
<div id="term">
<div class="term"></div><div class="term"></div><div class="term"></div><div class="term"></div>
</div>
</div>
<div id="content"></div>
<div id="footer"></div>
</div>

Related

how to make a <div> column that stretches to height of two <div>s beside it?

Goal: In the content area of a site, I need to make a decorative-only column that spans the height of two divs (containing images) beside it.
Problem: the column either has no height, regardless which attributes I give it, or only has the height of the first sibling div and no fill. I have tried height: 100%, min-height: 100%. Also tried making parent position: absolute and setting top: 0 and bottom: 0.
the code:
.row {
position: relative;
overflow: hidden;
border: #000 3px dashed;
}
#colLeft {
float: left;
width: 15%;
height: 100%;
background-color: red;
}
#B1 {
float: left;
width: 84%;
height: 100px; /* this will actually be the height of the img */
background-color: green;
}
#B2 {
width: 84%;
height: 100px; /* this will actually be the height of the img */
float: left;
background-color: #ff0;
}
<div class="row">
<div id="colLeft"></div>
<div id="B1">
<img src="foo">
</div>
<div id="B2">
<img src="bar">
</div>
</div>
Thanks in advance for your help.
what I want: http://i.stack.imgur.com/sgr5g.png
What I get: http://i.stack.imgur.com/lS63m.png
You should change the left column to position: absolute.
.row {
position: relative;
overflow: hidden;
border: #000 3px dashed;
}
#colLeft {
float: left;
width: 20%;
position: absolute;
height: 100%;
background-color: red;
}
#B1 {
float: right;
width: 80%;
height: 100px;
background-color: green;
}
#B2 {
width: 80%;
height: 100px;
float: right;
background-color: #ff0;
}
<div class="row">
<div id="colLeft"></div>
<div id="B1">
<img src="foo">
</div>
<div id="B2">
<img src="bar">
</div>
</div>
In your code you have height: 100px; /* this will actually be the height of the img */ for both img in your .row
You can do it like this also, fiddle http://jsfiddle.net/DIRTY_SMITH/QwZuf/260/
in this example I set the height of 200px to the row and height of 100% to the column
.row {
position: relative;
overflow: hidden;
border: #000 3px dashed;
height: 200px;
}
#colLeft {
float: left;
width: 15%;
height: 100%;
background-color: red;
}
Here's an alternate solution I found that works very well, too.
.row {
display: table-row;
}
#colLeft {
display: table-cell;
width: 15%;
background-color: red;
}
#B1 {
display: table-cell;
width: 84%;
height: auto;
background-color: green;
}
#B2 {
display: table-cell;
width: 84%;
height: auto;
background-color: #ff0;
}

have 3 divs to each other with spacers in between

I have 3 divs that I want next to each other on my page. If the container is 700px in width, they all connect well. But I want to have a max width of 800px on my container. And in that case, I want all my divs to space out (1st div to the left, 2nd div in the center and 3rd div on the right). I need to connect those divs with 2 spacers that I've got (1 to connect div 1 and 2. The other to connect 2 and 3).
Once I have achieved that, I want a second div (content) to float above the first div (background). But I have already achieved that.
I have tried a few things, but I can't find a solution, if anyone could help me, I would appreciate it!
Here are my code snippet:
* {
margin: 0;
padding: 0;
}
.container {
width: 800px;
margin: 0 auto;
background: #efefef;
height: 800px;
}
.content {
position: relative;
z-index: 100;
top: 0;
}
.background {
position: absolute;
z-index: 0;
top: 0;
width: inherit;
}
.bg-left {
height: 190px;
width: 268px;
background: url(images/left-1.png);
float: left;
}
.bg-left-spacer {
height: 190px;
width: 1px;
background: url(images/left-spacer.png);
float: left;
}
.bg-connector {
height: 190px;
width: 133px;
background: url(images/connector.png);
float: left;
margin: 0 auto;
}
.bg-right-spacer {
height: 190px;
min-width: 1px;
background: url(images/right-spacer.png);
float: left;
background-repeat: repeat-x;
}
.bg-right {
height: 190px;
width: 297px;
background: url(images/right-1.png);
float: left;
}
<div class='container'>
<div class='content'>
<h1>testheader</h1>
<p>testtext</p>
</div>
<div class='background'>
<div class='bg-left'></div>
<div class='bg-left-spacer'></div>
<div class='bg-connector'></div>
<div class='bg-right-spacer'></div>
<div class='bg-right'></div>
</div>
</div>
You could achieve it like this:
JSFiddle - DEMO
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
position: relative;
min-width: 700px;
max-width: 800px;
margin: 0 auto;
background: #efefef;
height: 800px;
}
.content {
position: relative;
z-index: 100;
top: 0;
}
.background {
position: absolute;
width: 100%;
z-index: 0;
top: 0;
display: table;
table-layout: fixed;
}
.bg-left {
height: 190px;
width: 268px;
background: url(images/left-1.png);
border: 1px solid #000;
display: table-cell;
}
.bg-connector {
height: 190px;
width: 133px;
background: url(images/connector.png);
border: 1px solid #000;
display: table-cell;
}
.bg-right {
height: 190px;
width: 297px;
background: url(images/right-1.png);
border: 1px solid #000;
display: table-cell;
}
.space {
display: table-cell;
width: 100%;
height: 190px;
background: #F00;
}
<div class='container'>
<div class='content'>
<h1>testheader</h1>
<p>testtext</p>
</div>
<div class='background'>
<div class='bg-left'></div>
<div class="space"></div>
<div class='bg-connector'></div>
<div class="space"></div>
<div class='bg-right'></div>
</div>
</div>
You should use percantages to achieve that:
.bg-left {
height: 190px;
width: calc( 100% / 3 - 1px );
background: url(images/left-1.png);
}
This way .bg-left is 33.3% in width -1px for the spacer.
DEMO: http://jsfiddle.net/6aor5u4m/

fill remaining space with div width auto

hey guys thanks for the upcoming support how do I set the blue to fill up the remaining width of the whole maininfo div? I tried setting the width:auto
<div class="maininfo">
<div class="large">2</div>
<div class="smallblock">
<div class="smalltop">3</div>
<div class="small">4</div>
</div>
<div class="smallblock">
<div class="smalltop">5</div>
<div class="small">6</div>
</div>
</div>
.maininfo {
width: 600px;
}
.large {
float: left;
height: 95px;
background-color: blue;
width:auto;
}
.smallblock {
float: right;
height: 90px;
margin: 0 0 0 5px;
width: 20%;
}
.small {
background-color: red;
height: 50%;
width: 100%;
}
.smalltop {
background-color: red;
height: 50%;
width: 100%;
margin-bottom:5px;
}
UPDATED MY JFIDDLE BUT NOW IT MAKES 2 LINES: http://jsfiddle.net/4ykf5frk/11/
If just .maininfo, merely add a 'background: blue;' property to your style declaration:
.maininfo {
background-color: blue;
width: 600px;
}
Otherwise, just add a 'background: blue;' property for the 'body' element:
body {
background-color: blue;
}

How do I define a content 100% while having a sidebar?

I have this structure for my website as below. How do I define red area as 100%, while it has a sidebar with 260px width and the sidebar is fixed.
If you can use CSS3 you can use calc:
#wrapper {
width: calc(100% - 260px);
}
#sidebar {
width: 260px;
}
#sidebar {
position: fixed;
width: 260px;
}
#wrapper {
width: 100%;
box-sizing: border-box;
padding-left: 260px;
}
Please see if this will work for you:
Demo: http://jsfiddle.net/dDULw/2/
HTML
<div id="outer">
<div id="sidebar">
sidebar
</div>
<div id="wrapper">
wrapper
</div>
</div>
CSS
#outer {
overflow: hidden;
border: 3px solid #000;
width: 600px;
height: 300px;
}
#sidebar {
float: left;
border: 5px solid blue;
width: 130px;
height: 250px;
}
#wrapper {
overflow: hidden;
border: 5px solid red;
height: 250px;
}

Two column layout: Problems with column

I created a simple two column layout based on this:
How to control overflow of table cell in Firefox?.
The left columns should be scrollable (top-down) and the right one should be fix.
HTML:
<div id="col1">
<div id="list">
<div class="row">Test 1</div>
<div class="row">Test 2</div>
<div class="row">Test 3</div>
<div class="row">... more rows</div>
</div>
</div><div id="col2"></div>
CSS:
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background-color: #0c0;
}
#col1 {
width: 25%;
height: 100%;
display:inline-block;
background-color: #c00;
}
#col1>#list {
width: 100%;
overflow: auto;
}
#col1>#list>.row {
padding: 5px;
border-bottom: 1px solid #ccc;
}
#col2 {
width: 75%;
height: 100%;
display:inline-block;
background-color: #00c;
}
Please see this demo:
http://jsfiddle.net/bitas/qRtjN/
Firefox 18.0.2 shows it nearly as expected. In other browsers the left column doesn't start at the top of the page but in the lower left corner.
It works as expected if I remove the "div#list". What's wrong with this div? How I can I fix it?
I have modified your CSS a bit and it does work. Here it is:
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background-color: #0c0;
}
#col1 {
width: 25%;
height: 1000px;
display:inline-block;
background-color: #c00;
}
#col1>#list {
width: 100%;
height: 100%;
overflow: auto;
}
#col1>#list>.row {
padding: 5px;
border-bottom: 1px solid #ccc;
}
#col2 {
width: 75%;
height: 100px;
display:inline-block;
background-color: #00c;
position:fixed;
top:0;
right:0;
}
Adding this CSS will correct the alignment of your columns:
#col1, #col2 {
vertical-align: text-top;
}
http://jsfiddle.net/qRtjN/13/