CSS Horizontal space div table - html

I'm working on a div table in CSS. What I'm trying to do is to set the same space between margins and table cells and between table cells.
This is what I want to achieve:
But this is what it currently looks like:
I'm using this code for the class:
.tfoto{width:600px;
display:table;
margin-left:200px;
border-top-style:dotted;
border-bottom-style:dotted;
border-left-style:dotted;
border-right-style:dotted;
text-align:center;
background-color:transparent;
border-spacing:1px;
collapse:separate;}
.tcaption {display:table-caption;
font:"Traditional Arabic";}
.trow {display:table-row;
width:200px;
cell-spacing:5px;
padding:5px;}
.tdcell {display:table-cell;
width:200px;
padding:5px;}

Set Class
.imgs{
width:100%;
height:200px;
}
Checkout This :
.tfoto{width:600px;
display:table;
margin-left:200px;
border-top-style:dotted;
border-bottom-style:dotted;
border-left-style:dotted;
border-right-style:dotted;
text-align:center;
background-color:transparent;
border-spacing:1px;
collapse:separate;}
.tcaption {display:table-caption;
font:"Traditional Arabic";}
.trow {display:table-row;
width:200px;
cell-spacing:5px;
padding:5px;}
.tdcell {display:table-cell;
width:200px;
padding:5px;}
.imgs {width:100%;
height:200px;}
<div class="tfoto">
<div class="tcaption">
<p><em>Sample text.</em></p>
</div>
<div class="trow">
<div class="tdcell">
<img class="imgs" src="foto1.jpg">
</div>
<div class="tdcell">
<img class="imgs" src="foto2.jpg">
</div>
</div>
<div class="trow">
<div class="tdcell">
<img class="imgs" src="foto3.jpg">
</div>
<div class="tdcell">
<img class="imgs" src="foto4.jpg">
</div>
</div>
</div>

UPDATE
It looks like you were very close, but you had 2 crucial syntax errors, see Snippet 2:
collapse:separate;
AND
cell-spacing:5px;
Should be:
border-collapse:separate;
AND
border-spacing:5px
Now it looks exactly as you wanted it.
Use border-spacing
SNIPPET 1
table {
table-layout: fixed;
border-spacing: 5px;
outline: 5px solid #fff;
width: 200px;
height: 200px;
margin: 20px auto;
}
td {
outline: 5px solid #fff;
background: #000;
}
<table>
<tbody>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
SNIPPET 2
.tfoto {
width: 600px;
display: table;
margin-left: 200px;
border-top-style: dotted;
border-bottom-style: dotted;
border-left-style: dotted;
border-right-style: dotted;
text-align: center;
background-color: transparent;
border-spacing: 1px;
border-collapse: separate;
}
.tcaption {
display: table-caption;
font: "Traditional Arabic";
}
.trow {
display: table-row;
width: 200px;
border-spacing: 5px;
padding: 5px;
}
.tdcell {
display: table-cell;
width: 200px;
padding: 5px;
}
.imgs {
width: 100%;
height: 200px;
}
<div class="tfoto">
<div class="tcaption">
<p><em>Sample text.</em>
</p>
</div>
<div class="trow">
<div class="tdcell">
<img class="imgs" src="foto1.jpg">
</div>
<div class="tdcell">
<img class="imgs" src="foto2.jpg">
</div>
</div>
<div class="trow">
<div class="tdcell">
<img class="imgs" src="foto3.jpg">
</div>
<div class="tdcell">
<img class="imgs" src="foto4.jpg">
</div>
</div>
</div>

Related

how to wrap div elements boxes with responsive

How to wrap div boxes into main div along with images with responsive.?
Am trying to achieve below layout.
When i use float:left the boxes are aligned perfect where as without it if i use display inline block the boxes are not aligned as shown below.
My jfiddle
.mywrapper {
margin: 0 auto;
min-width: 320px;
max-width: 905px;
background: yellow;
}
.firstblock {
margin-top: 60px;
margin-bottom: 60px;
background: red;
//background: #2b2b2b;
padding:30px;
width:auto;
height:auto;
}
.mainimage{
width: 190px;
height: 125px;
margin-left:2%;
float:left;
padding-right:30px;
}
.smallbox{
float: left;
width: 190px;
height: 110px;
background-color: green;
margin-right:10px;
}
.secondblock {
margin-bottom: 30px;
height: 215px;
background: aqua;
padding:30px;
}
<div class="mywrapper" id="myid">
Hello
<div class="firstblock">
<div >
<img class="mainimage" src="mainimg.JPG" border="0" />
</div>
<div>
<h2 class="title"><span>MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT</span></h2>
<div class="smallbox"><img class="pcspecimg" src="box1.JPG" alt="box1.JPG" border="0" /><span>box1</span><div>MY TEXT</div></div>
<div class="smallbox"><img class="pcspecimg" src="box2.JPG" alt="box2.JPG" border="0" /><span>box2</span><div>MY TEXT MY TEXT</div></div>
<div class="smallbox"><img class="pcspecimg" src="box3.JPG" alt="box3.JPG" border="0" /><span>box3</span><div>MY TEXT MY TEXT</div></div>
</div>
</div>
<div class="secondblock">
secondblock
</div>
</div>
I think you would like this
.mywrapper {
margin: 0 auto;
min-width: 320px;
max-width: 905px;
background: yellow;
}
.firstblock {
margin-top: 60px;
margin-bottom: 60px;
background: red;
//background: #2b2b2b;
padding:30px;
width:auto;
height:auto;
}
.left-div{
float:left;
width: 27%;
height: 125px;
margin-right:2%;
border: 1px solid;
}
.right-div{
float:right;
width:70%;
}
h2{
margin-top:0;
}
.clear{
clear:both;
}
img{
height:auto;
width:auto;
max-width:100%;
max-height:100%;
}
.pcspecimg {
border: 1px solid #fff;
float: left;
height: 40px;
margin-right: 3%;
width: 27%;
}
.small-wrap {
margin-bottom: 5px;
}
.smallbox {
background-color: green;
float: left;
height: 110px;
margin-right: 1.5%;
width: 32.3%;
padding:5px;
box-sizing: border-box;
}
.smallbox:last-child{
margin-right:0;
}
.secondblock {
margin-bottom: 30px;
height: 215px;
background: aqua;
padding:30px;
}
<div class="mywrapper" id="myid">
Hello
<div class="firstblock">
<div class="left-div">
<img class="mainimage" src="mainimg.JPG" border="0" />
</div>
<div class="right-div">
<h2 class="title">
<span>MY TEXT MY TEXT</span>
</h2>
<div class="smallbox">
<div class="small-wrap">
<div class="pcspecimg">
<img src="box1.JPG" alt="box1" border="0" />
</div>
<span>box1</span>
<div class="clear"></div>
</div>
<div>MY TEXT</div>
</div>
<div class="smallbox">
<div class="small-wrap">
<div class="pcspecimg">
<img src="box1.JPG" alt="box1" border="0" />
</div>
<span>box1</span>
<div class="clear"></div>
</div>
<div>MY TEXT</div>
</div>
<div class="smallbox">
<div class="small-wrap">
<div class="pcspecimg">
<img src="box1.JPG" alt="box1" border="0" />
</div>
<span>box1</span>
<div class="clear"></div>
</div>
<div>MY TEXT</div>
</div>
</div>
<div class="clear"></div>
</div>
<div class="secondblock">
secondblock
</div>
</div>
.mywrapper {
margin: 0 auto;
min-width: 320px;
max-width: 905px;
background: yellow;
}
.firstblock {
display: flex;
flex-direction: row;
margin-top: 60px;
margin-bottom: 60px;
background: red;
//background: #2b2b2b;
padding:30px;
width:auto;
height:auto;
}
.mainimage{
width: 190px;
height: 125px;
margin-left:2%;
float:left;
padding-right:30px;
}
.smallbox{
float: left;
width: 190px;
height: 110px;
background-color: green;
margin-right:10px;
}
.secondblock {
margin-bottom: 30px;
height: 215px;
background: aqua;
padding:30px;
}
<div class="mywrapper" id="myid">
Hello
<div class="firstblock">
<div>
<img class="mainimage" src="mainimg.JPG" border="0" />
</div>
<div>
<h2 class="title"><span>MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT MY TEXT</span></h2>
<div class="smallbox"><img class="pcspecimg" src="box1.JPG" alt="box1.JPG" border="0" /> <span>box1</span><div>MY TEXT</div>
</div>
<div class="smallbox"><img class="pcspecimg" src="box2.JPG" alt="box2.JPG" border="0" /> <span>box2</span><div>MY TEXT MY TEXT</div>
</div>
<div class="smallbox"><img class="pcspecimg" src="box3.JPG" alt="box3.JPG" border="0" /> <span>box3</span><div>MY TEXT MY TEXT</div>
</div>
</div>
</div>
<div class="secondblock">
secondblock
</div>
</div>
Is it you want?
Can You explain detail?

stretch a div to match it to the sum of width of 2 divs below it

I'm trying to make 3 divs align in such a way that the top div stretches to make the sum of the width of the bottom 2 divs.
Attached Image of the expected div positioning
I tried using display : table-row for the divs.
<div id="main_div" style="display: table-row">
<div id='col1' style="width: 300px; display: table-cell;">
<div style="display: table-row">
<div style="width: 300px; display: table-cell;text-align :right;border-style: groove;">
<h1>This is heading 1</h1>
</div>
</div>
<div style="display: table-row">
<div style="width: 150px; display: table-cell;white-space: nowrap;border-style: groove; border-color: green;">
abc: <input type="text" name="def">
</div>
<div style="width: 150px; display: table-cell;white-space: nowrap;border-style: groove; border-color: red">
def: <input type="text" name="ghi">
</div>
</div>
</div>
</div>
Thanks
Updated
You can also achieve this by div elements by using the float: left and display: inline-block property of css.
.row:before,.row:after{
content:"";
display:table;
}
.row:after{
clear:both;
}
.row{
border: 1px solid #000;
text-align:center;
}
.full{
width:100%;
float:left;
display:inline-block;
padding: 20px;
box-sizing:border-box;
}
.half{
width:50%;
float:left;
display:inline-block;
padding: 20px;
box-sizing:border-box;
border-top:1px solid #000;
border-right: 1px solid #000;
}
.half:last-of-type{
border-right:0;
}
<div class="row">
<div class="full">
DIV 1
</div>
<div class="half">
DIV2
</div>
<div class="half">
DIV3
</div>
</div>
The best way to achieve this layout is to use table. Please check the code below:
table{
border-spacing: 0;
border-collapse: collapse;
text-align: center;
}
td{
border: 1px solid #000;
padding:30px;
}
<table>
<tbody>
<tr>
<td colspan="2">DIV 1</td>
</tr>
<tr>
<td>DIV 2</td>
<td>DIV 3</td>
</tr>
</tbody>
</table>
Using flex from css3:
<div style="width: 300px;">
<div style="width: 100%; border: 1px solid black;">Hello</div>
<div style="width: 302px; display: flex;">
<div style="width: 50%; border: 1px solid black;">1</div>
<div style="width: 50%; border: 1px solid black;">2</div>
</div>
</div>
The 302px width is the left and right 1px borders

Fixing column alignment

I want column 1 (comment 1) and column 2 (comment 2) to be next to each other and to be floated to the left side. Column 3 (comment 3) should be floated to the right side.
jsfiddle
I've tried a lot but can't make it work with %.
HTML:
<div class="comment_one">
<div class="reitings">
<div class="rate pluss"><img class="plus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC"> 83</div>
</div>
</div>
<div class="comment_two">
<div class="reitings">
<div class="rate minuss"><img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC"> 9</div>
</div>
</div>
<div class="comment_three">
<div class="reitings">
<div class="rate minuss"><img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">Report</div>
</div>
</div>
CSS:
.comment_one {
width:25%;
float:left;
}
.comment_two {
width:25%;
float:left;
}
.comment_three {
float:right;
width:40%;
}
.reitings {
display:table;
width:50%;
border:1px solid #e9e9e9;
-webkit-border-radius:4px;
-moz-border-radius:4px;
border-radius:4px;
}
.rate {
display:table-cell;
text-align:center;
vertical-align:middle;
line-height:1.5em;
padding:10%;
}
.rate img {
vertical-align:middle
}
.pluss {
background:#f5f5f5;
color:#4d761a
}
.minuss {
background:#f5f5f5;
color:#a8404b;
border-left:1px solid #e9e9e9;
text-align:center
}
Structure the HTML:
<div id="comments">
<div class="c1 rate-plus"></div>
<div class="c2 rate-plus"></div>
<div class="c3 rate-minus"></div>
</div>
Access all divs in #comments with #comments div. Think about what the divs have in common. Write it in the CSS. For Example:
#comments div {
background: #f5f5f5;
border-left: 1px solid #e9e9e9;
padding: 12px;
margin: 5px;
text-align: center;
}
Float c1 and c2 with left and c3 with right.
Complete CSS
#comments div {
background: #f5f5f5;
border-left: 1px solid #e9e9e9;
padding: 12px;
margin: 5px;
text-align: center;
}
.rate-plus {
color: #4d761a
}
.rate-minus {
color: #a8404b;
}
.c1, .c2 {
width: 25%;
float: left;
}
.c3 {
width: 37%;
float: right;
}
Complete HTML
<div id="comments">
<div class="c1 rate-plus">
<img class="plus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">83
</div>
<div class="c2 rate-minus">
<img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">9
</div>
<div class="c3 rate-minus">
<img class="minus" alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAIAQMAAAD3KoyyAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAAtJREFUeNpjYMAOAAAYAAFG27MLAAAAAElFTkSuQmCC">Report
</div>
</div>
I've modified it a little bit.
Demo

Alignment issues inside table

I have two divs which I put inside a table in order to get horizontally alignment.
<table>
<tr>
<td>
<div>
data
</div>
<div>
data
</div>
</td>
</tr>
</table>
Which looks like the following:
I now want to align these 2 in the centre, as opposed to the left.
I have tried <td style="margin-left:auto; margin-right:auto;">
but no joy.
Any idea?`
Apply the margins to the <table/>:
table {
margin: 0 auto;
}
Here is a demo fiddle.
Created a fiddle example
use align="center" for td and for div use display: inline-block;
<table style="border: 1px solid green; width: 100%; ">
<tbody><tr>
<td align="center">
<div style="border: 1px solid red;width: 30px;display: inline-block;">
data
</div>
<div style="border: 1px solid red;width: 30px;display: inline-block;">
data
</div>
</td>
<div id="containerdiv">
<div id="coveringdiv">
<div id="firstdiv">
<div id="yourdata">
Your Data Here
</div>
<div id="yourvalue">
Value
</div>
</div>
<div id="seconddiv">
<div id="yourdata">
Your Data Second
</div>
<div id="yourvalue">
values2
</div>
</div>
</div>
</div>
and CSS:
body
{
background-color: #123456;
}
#coveringdiv
{
border: solid 1px #FFFFFF;
height: 200px;
margin: 0 auto;
width: 100%;
text-align: center;
}
#firstdiv
{
display: inline-block;
}
#yourdata
{
color: #FFFFFF;
font-size: 10px;
}
#yourvalue
{
color: #FFFFFF;
font-size: 24px;
}
#seconddiv
{
display: inline-block;
}

How can I CSS for List/grid in div with border?

I want to create a list table in DIV with border. When more content of width of a column then line break and border increase but other column border not increase. see the example:
Div based CSS Table
.list_container{
float:left;
width: 550px;
margin-bottom:10px;
font-family: vardana;
}
.list_row{
float:left;
width: 548px;
border-bottom:1px #9F9F9F solid;
}
.list_row:hover{
background-color:#CCCCCC;
}
.list_rowHeader{
float:left;
width: 548px;
border-bottom:1px #9F9F9F solid;
border-top:1px #9F9F9F solid;
font-weight: bold;
background-color: #FF0000;
color: #FFFFFF;
}
.list_column{
float:left;
padding: 3px;
border-left: 1px #9F9F9F solid;
}
.list_columnLast{
float:left;
padding: 3px;
border-left: 1px #9F9F9F solid;
border-right: 1px #9F9F9F solid;
}
.even{ background-color:#E0E0E0!important;}
.odd{ background-color:#FFFFFF!important;}
</style>
</head>
<body>
<div class="list_container" >
<div class="list_rowHeader" >
<div class="list_column" style="width: 250px;">Name</div>
<div class="list_column" style="width: 96px;"> Bid Amount</div>
<div class="list_columnLast" style="width: 180px;"> Email </div>
</div>
<div class="list_row even" >
<div class="list_column" style="width: 250px;">Saidul Haque</div>
<div class="list_column" style="width: 96px;"> 2131231</div>
<div class="list_columnLast" style="width: 180px;"> saiduleye#gmail.com</div>
</div>
<div class="list_row odd" >
<div class="list_column" style="width: 250px;">Saidul Haque, Sonargaon, Bangladesh Dhaka, </div>
<div class="list_column" style="width: 96px;"> 2131231</div>
<div class="list_columnLast" style="width: 180px;"> saiduleye#gmail.com</div>
</div>
<div class="list_row even" >
<div class="list_column" style="width: 250px;">Saidul Haque</div>
<div class="list_column" style="width: 96px;"> 2131231</div>
<div class="list_columnLast" style="width: 180px;"> saiduleye#gmail.com</div>
</div>
</div>
</body>
Anybody solve this problem?
Ok, so I got it to work - you need to set a specific height on the .list_column class:
(I added a DOCTYPE and your CSS/INLINE styles are slightly better formed).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.list_container{
float:left;
width: 548px;
margin-bottom:10px;
font-family: vardana;
border: 1px #9F9F9F solid;
}
.list_row{
float:left;
width: 548px;
border-bottom:1px #9F9F9F solid;
}
.list_row:hover{
background-color:#CCCCCC;
}
.list_rowHeader{
float:left;
width: 548px;
font-weight: bold;
background-color: #FF0000;
color: #FFFFFF;
}
.list_column{
float:left;
width: 250px;
/* height: 50px; /* Need a height - UNCOMMENT */
/* min-height: 50px; /* Need a height - UNCOMMENT */
padding-left: 3px;
padding-right: 3px;
border-right: 1px #9F9F9F solid;
}
.list_columnLast{
float:left;
padding: 3px;
width: 180px;
}
.even{ background-color:#E0E0E0!important;}
.odd{ background-color:#FFFFFF!important; }
</style>
</head>
<body>
<div class="list_container">
<div class="list_rowHeader">
<div class="list_column">Name</div>
<div class="list_column" style="width: 96px;"> Bid Amount</div>
<div class="list_columnLast"> Email </div>
</div>
<div class="list_row even">
<div class="list_column">Saidul Haque</div>
<div class="list_column" style="width: 96px;"> 2131231</div>
<div class="list_columnLast"> saiduleye#gmail.com</div>
</div>
<div class="list_row odd">
<div class="list_column">Saidul Haque, Sonargaon, Bangladesh Dhaka,</div>
<div class="list_column" style="width: 96px;"> 2131231</div>
<div class="list_columnLast"> saiduleye#gmail.com</div>
</div>
<div class="list_row even">
<div class="list_column">Saidul Haque</div>
<div class="list_column" style="width: 96px;"> 2131231</div>
<div class="list_columnLast"> saiduleye#gmail.com</div>
</div>
</div>
</body>
I hope that helps! ^_^ <(Enjoi)