Html table like structure without table - html

I am trying to create 2 column table like structure without using <table> , Here in 2nd column , When the text overflows I want it to stay on the right side.Here is my code so far - https://jsfiddle.net/a49vuup1/
<div class="mainbox">
<span class="leftbox"> STATE </span> : <span class="rightbox">TAMILNADU TAMILNADU TAMILNADU TAMILNADU</span>
<div class="myhr"></div>
<span class="leftbox"> Phone </span> : <span class="rightbox">Landline</span>
</div>
and my css
.mainbox {
max-width: 300px;
margin: auto;
border: 1px solid #454242;
margin-top: 30px;
}
hr {
border-top: 3px solid rgba(44, 44, 44, 0.69);
}
.leftbox {
border-right: 1px solid #303925;
font-size: 20px;
padding: 5px;
min-width: 150px;
display: inline-block;
}
.myhr {
border-bottom: 1px solid #293A42;
}
.rightbox {
font-size: 16px;
min-width: 150px;
}

You could use display: table for this
example:
<div class="table">
<div class="table-row">
<div class="cell">
text 1
</div>
<div class="cell">
text 2
</div>
</div>
<div class="table-row">
<div class="cell">
text 3
</div>
<div class="cell">
text 4
</div>
</div>
</div>
css:
.table {
display: table;
table-layout: fixed;
border-collapse: collapse;
}
.table-row {
display: table-row;
}
.cell {
display: table-cell;
border: 1px solid black;
}
https://jsfiddle.net/41vpjpuy/

I wasn't sure what the <hr> and .myhr was for so I guessed that it was to span both columns. I used display: table-cell for .leftbox and .rightbox and made the .mainbox display: table of course and added table-layout: fixed so your lengths can make more sense.
Reference
Fiddle
Snippet
.mainbox {
max-width: 300px;
margin: auto;
border: 1px solid #454242;
margin-top: 30px;
display: table;
table-layout: fixed;
border-spacing: 3px;
border-collapse: separate;
}
hr {
border-top: 3px solid rgba(44, 44, 44, 1);
width: 200%;
}
.leftbox {
border-right: 1px solid #303925;
font-size: 20px;
padding: 5px;
min-width: 150px;
display: table-cell;
}
.myhr {
border-bottom: 2px solid #000;
display: table-row;
width: 200%;
min-height: 30px;
padding: 5px;
}
.rightbox {
font-size: 16px;
min-width: 150px;
display: table-cell;
}
<div class="mainbox">
<span class="leftbox"> STATE </span> : <span class="rightbox">TAMILNADU TAMILNADU TAMILNADU TAMILNADU</span>
<div class="myhr">
<hr/>
</div>
<span class="leftbox"> Phone </span> : <span class="rightbox">Landline</span>
</div>

Additionally, try this also. I eddited your css and html
<div class="mainbox">
<div class="row">
<span class="leftbox">State</span>: <span class="rightbox">TAMILNADU TAMILNADUTAMILNADU TAMILNADU</span>
</div>
<div class="row">
<span class="leftbox">Phone</span>: <span class="rightbox">landline</span>
</div>
</div>
CSS:
.mainbox {
max-width: 300px;
margin: auto;
border: 1px solid #454242;
margin-top: 30px;
display: table;
}
.row {
display:table-row;
}
{
border-top: 3px solid rgba(44, 44, 44, 0.69);
}
.leftbox {
border-right: 1px solid #303925;
font-size: 20px;
padding: 5px;
min-width: 150px;
word-wrap: break-word;
display: table-cell;
width:25%;
}
.myhr
{
border-bottom: 1px solid #293A42;
}
.rightbox {
/* word-wrap: break-word; */
font-size: 16px;
min-width: 150px;
display:table-cell;
}

Related

Put two divs one near the other

I have the following html code:
<div class="demand page">
<div id="crumby-title">
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
<div class="page-title">
Demand
</div>
</div>
<div id="chart" class="demand-chart">
</div>
</div>
and the css/less:
.rtm {
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart{
padding-top: 50px;
}
#crumby-title {
display: block;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
position: absolute;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
float: left;
font-size: 20px;
font-weight: 5px 10px 10px 75px;
height: 55px;
}
}
I tried to do like this in order to show the page-icon and page-title one near the other but how it is done now they are one over the other (the icon is on top of the title)
How can I solve this? Thanks
When you say "near each other" I am assuming you mean "beside each other".
You can add flexbox properties to #crumby-title. Then remove position and float properties from .page-icon and page-title. You can also remove height from .page-title
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart {
padding-top: 50px;
}
#crumby-title {
display: flex;
align-items: center;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
font-size: 20px;
font-weight: 5px 10px 10px 75px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="demand page">
<div id="crumby-title">
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
<div class="page-title">
Demand
</div>
</div>
<div id="chart" class="demand-chart">
</div>
</div>
Give float:left to .page-icon instead of position:absolute and add <div class="clear"></div> after page-title.
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart{
padding-top: 50px;
}
#crumby-title {
display: block;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
float: left;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
float: left;
font-size: 20px;
font-weight: 5px 10px 10px 75px;
height: 55px;
}
.clear{
clear:both;
}
<div class="demand page">
<div id="crumby-title">
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
<div class="page-title">
Demand
</div>
<div class="clear"></div>
</div>
<div id="chart" class="demand-chart">
</div>
</div>
I want to show u another version of ankita pantel's put them in a table and add padding-top to Demand
.app__header {
background-color: #ffffff;
box-shadow: 1px 2px 2px rgba(1, 1, 1, 0.15);
}
.app__inner-content {
background-color: #ffffff;
}
.demand-chart{
padding-top: 50px;
}
#crumby-title {
display: block;
border-bottom: 1px solid #eee;
}
.page-icon {
font-size: 20px;
padding: 14px 18px;
background: #e7e7e7;
}
.page-title {
padding-top: 30px;
float: left;
font-size: 20px;
font-weight: 5px 10px 10px 75px;
height: 55px;
}
<div class="demand page">
<div id="crumby-title">
<table>
<tr>
<td>
<div class="page-icon">
<i class="fa fa-line-chart"></i>
</div>
</td>
<td>
<div class="page-title">
Demand
</div>
</td>
</tr>
</table>
</div>
<div id="chart" class="demand-chart">
</div>
</div>
All the cool kids are using flex box.
display:flex; flex-direction:row; makes the child items stack in a row. (flex-direction:row is default so you can skip that)
#crumby-title {
...
display: flex;
flex-direction:row;
}
then you can (if you want) center the text with
.page-title {
....
display: flex;
align-items: center;
}
Fiddle

div table cell width totally ignored

As per title, cell width is totally ignored - tried so many things and none work. Tried inspecting to see if there is any inheritance that i do not know about but nothing showed up. The cells just split into equal chunks and cell width property is ignored.
.CalculateBtn {
background-color: #96c11f;
width: 200px;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Raleway, Arial;
font-size: 21px;
font-weight: normal;
padding: 10px 10px;
text-decoration: none;
text-align: center;
}
.CalculateBtn:hover {
background-color: #7f0050;
color: #ffffff;
}
.divTable {
display: table;
width: 100%;
table-layout: fixed;
/*vertical-align: top;*/
}
.divTableRow {
display: table-row;
background-color: #0d56c2;
}
.divTableButtonRow {
display: table-row;
}
.divTableHead-left {
background-color: #7F0050;
display: table-cell;
padding: 3px 10px;
width: 30%;
}
.divTableHead-center {
color: #ffffff;
text-align: center;
font-family: raleway, arial, helvetica, sans-serif;
background-color: #7F0050;
display: table-cell;
padding: 3px 10px;
width: 40%;
}
.divTableHead-right {
background-color: #7F0050;
display: table-cell;
padding: 3px 10px;
width: 30%;
}
/* Table Cells */
.divTableCell-left,
.divTableHead {
border-right: 1px solid #ffffff;
border-top: 1px solid #ffffff;
display: table-cell;
padding: 3px 10px;
width: 20%;
}
.divTableCell-center,
.divTableHead {
border-right: 1px solid #ffffff;
border-top: 1px solid #ffffff;
display: table-cell;
padding: 3px 10px;
width: 30%;
color: #ffffff;
}
.divTableCell-right,
.divTableHead {
border-right: 1px solid #ffffff;
border-top: 1px solid #ffffff;
display: table-cell;
padding: 3px 10px;
width: 50%;
color: #ffffff;
}
/* Button Cell properties */
.divTableCellButton-left,
.divTableHead {
display: table-cell;
padding: 3px 10px;
width: 30%;
}
.divTableCellButton-center,
.divTableHead {
display: table-cell;
padding: 3px 10px;
width: 40%;
}
.divTableCellButton-right,
.divTableHead {
display: table-cell;
padding: 3px 10px;
width: 30%;
}
/* End Button Cell properties */
/* INFO cell properties*/
.divTableCellInfo-left {
color: #ffffff;
display: table-cell;
padding: 3px 10px;
max-width: 20%;
}
.divTableCellInfo-right {
color: #ffffff;
display: table-cell;
padding: 3px 10px;
max-width: 80%;
}
/* End info cell properties*/
.divTableFoot {
background-color: #EEE;
display: table-footer-group;
font-weight: bold;
}
.divTableBody {
display: table-row-group;
}
<div class="divTable" style="border: 1px solid #ffffff;">
<div class="divTableBody">
<div class="divTableHead-left"> </div>
<div class="divTableHead-center">
<font size="4">Staffing Calculator K=2</font>
</div>
<div class="divTableHead-right"> </div>
<div class="divTableRow">
<div class="divTableCell-left">
<font color="#ffffff">Calls:</font>
</div>
<div class="divTableCell-center"><input type="text" name="calls" id="calls" style="width: 80px;" value="151"></div>
<div class="divTableCell-right">
<font color="#ffffff">in a period of</font>
<input name="period" value="5" />
<select name="callUnit">
<option value="hour" selected>hours</option>
<option value="minute" >minutes</option>
</select>
</div>
</div>
<div class="divTableRow">
<div class="divTableCell-left">
<font color="#ffffff">Average Handle Time: </font>
</div>
<div class="divTableCell-center"><input type="text" name="aht" value="300"></div>
<div class="divTableCell-right">
<select name="ahtUnit">
<option value="minute" >minutes</option>
<option value="second" selected>seconds</option>
</select> <i>include time spent on phone and time working after call. Usually between 3 and 5 minutes.</i>
</div>
</div>
</div>
I use colgroup for this. I see you are using div's in your markup and table related CSS to style your table, so my suggestion would require that you change your markup to table markup (not sure if doable).
table {
width: 100%;
table-layout: fixed;
}
th {
background: #0095ff;
color: white;
}
td {
border: 1px solid #ccc;
}
<table>
<colgroup>
<col style="width:30%" />
<col style="width:40%" />
<col style="width:30%" />
</colgroup>
<thead>
<tr>
<th colspan="3">This is the table header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
</tr>
</tbody>
</table>

Footer elements vertical align

I'm trying to make this footer, where every element is vertically aligned. But for some reason, copyright for example isn't vertically aligned.
Can anyone help me finding out what is wrong? Or what I am missing?
Footer HTML:
<div id="footerSocial">
<div id="socialNetwork">
Connect with us
<img src="/www/assets/newImages/footer/facebook.png">
<img src="/www/assets/newImages/footer/twitter.png">
<img src="/www/assets/newImages/footer/google plus.png">
<img src="/www/assets/newImages/footer/pinterest.png">
<img src="/www/assets/newImages/footer/tumblr.png">
</div>
<div id="footerNewsletter">
Subscribe to Newsletter
<input id="subscribeNewsletter" name="email" type="text">
<input id="subscribe_ok" type="image" src="/www/assets/newImages/footer/Ok.png" onclick="saveNewsletter(this);">
</div>
<div id="copyright">
Copyright 2013 - Dreaming Different
</div>
</div>
Footer CSS:
#footerSocial {
display: inline-block;
text-align: center;
width: 100%;
margin-top: -25px;
}
#socialNetwork {
display: inline-block;
float: left;
font-size: 10px;
color: #747474;
}
#footerNewsletter {
display: inline-block;
margin: 0 auto;
font-size: 10px;
color: #747474;
}
#footerNewsletter #subscribe_ok {
margin-bottom: -5px;
}
#copyright {
display: inline-block;
float: right;
font-size: 10px;
color: #747474;
}
#footerSocial {
border: 1px solid black;
}
#socialNetwork {
border: 1px solid green;
}
#footerNewsletter {
border: 1px solid red;
}
#copyright {
border: 1px solid blue;
}
Fiddle Demo
You can use a table layout to achieve what you want :
#footerSocial { display: table; text-align: center; width: 100%; font-size: 10px;color: #747474;}
#footerSocial > div {display: table-cell; }
#footerNewsletter #subscribe_ok { margin-bottom: -5px; }
#footerSocial { border: 1px solid black; }
#socialNetwork { border: 1px solid green; }
#footerNewsletter { border: 1px solid red; }
#copyright { border: 1px solid blue; }
Example

Unknown additional space on <div> top

I am creating a table madde with several divs, and I am having an extra space between the first row (styled as head) and the rest of them, only the fist two columns (divs). Here you can see very clear:
There is no style atribute causing this space, at least I am not able to find the reason of it.
I have reproduced it on jsfiddle and you can see that it also sets the extra space: DEMO
Here I bring HTML & Syle related code:
HTML:
<div class="tableWrap">
<div class="tableHeader">
<div class="contentColumn60">
<span class="tableHeaderText">Turno</span>
</div>
<div class="contentColumn20">
<span class="tableHeaderText">Tipo</span>
</div>
<div class="contentColumn10">
<span class="tableHeaderText">Editar</span>
</div>
<div class="contentColumn10">
<span class="tableHeaderText">Reactivar</span>
</div>
</div>
<div class="tableContent">
<div class="contentColumn60">
<span class="tableContentText">Mañana(17:00 - 21:00)</span>
</div>
<div class="contentColumn20">
<span class="tableContentText">Mañanas</span>
</div>
<div class="contentColumn10">
<div class="editIcon"></div>
</div>
<div class="contentColumn10">
<div class="discontinueIcon"></div>
</div>
</div>
<div class="tableContent">
<div class="contentColumn60">
<span class="tableContentText">Mañana(17:00 - 21:00)</span>
</div>
<div class="contentColumn20">
<span class="tableContentText">Mañanas</span>
</div>
<div class="contentColumn10">
<div class="editIcon"></div>
</div>
<div class="contentColumn10">
<div class="discontinueIcon"></div>
</div>
</div>
<div class="tableContent">
<div class="contentColumn60">
<span class="tableContentText">Mañana(17:00 - 21:00)</span>
</div>
<div class="contentColumn20">
<span class="tableContentText">Mañanas</span>
</div>
<div class="contentColumn10">
<div class="editIcon"></div>
</div>
<div class="contentColumn10">
<div class="discontinueIcon"></div>
</div>
</div>
STYLE:
.tableWrap{
width: 100%;
height:380px;
border:#ccc 1px solid;
border-radius:3px;
box-shadow: 0 1px 2px #d1d1d1;
margin: 10px;
background: -webkit-gradient(linear, left top, left bottom, from(#fbfbfb), to(#fafafa));
background: -moz-linear-gradient(top, #fbfbfb, #fafafa);
font-size:12px;
color:#666;}
.tableHeader{
height: 40px;
width: 100%;
background: -moz-linear-gradient(center top , #EDEDED, #EBEBEB) repeat scroll 0 0 rgba(0, 0, 0, 0);
border-bottom: 1px solid #E0E0E0;
border-left: 1px solid #E0E0E0;
border-top: 1px solid #FAFAFA;
display: inline-block;
font-weight: 600;
}
.tableHeaderText{
line-height: 40px;
padding: 0 10px;
}
.tableContent{
height: 40px;
width: 100%;
}
.tableContentText{
line-height: 40px;
padding: 0 0 0 20px;
}
.contentColumn60{
height: 40px;
width: 58%;
border-top:1px solid #fafafa;
border-bottom:1px solid #e0e0e0;
border-left:1px solid #e0e0e0;
display: inline-block;
}
.contentColumn20{
height: 40px;
width: 20%;
border-top:1px solid #fafafa;
border-bottom:1px solid #e0e0e0;
border-left:1px solid #e0e0e0;
display: inline-block;
}
.contentColumn10{
height: 40px;
width: 10%;
border-top:1px solid #fafafa;
border-bottom:1px solid #e0e0e0;
border-left:1px solid #e0e0e0;
display: inline-block;
}
.discontinueIcon{
width: 23px;
height: 23px;
background-size: 98%;
background-image: url(images/error.png);
background-repeat:no-repeat;
margin: 0 auto;
}
.editIcon{
width: 23px;
height: 23px;
background-size: 98%;
background-image: url(images/edit.png);
background-repeat:no-repeat;
margin: 0 auto;
}
Since the elements are inline-block, you could use vertical-align:top to align them as desired. It's worth noting that the default property value is baseline; this explains why they were behaving as they were. UPDATED EXAMPLE HERE
.contentColumn60 {
height: 40px;
width: 58%;
border-top: 1px solid #fafafa;
border-bottom: 1px solid #e0e0e0;
border-left: 1px solid #e0e0e0;
display: inline-block;
vertical-align: top;
}
.contentColumn20 {
height: 40px;
width: 20%;
border-top: 1px solid #fafafa;
border-bottom: 1px solid #e0e0e0;
border-left: 1px solid #e0e0e0;
display: inline-block;
vertical-align: top;
}
use overflow:hidden; for content column60,20,10 it works perfect
add a clearfix or use vertical-align:top and overflow:hidden
.contentColumn60:after {
content: "";
display: table;
clear: both;
}

Table grid using Div in HTML and CSS

I want to create a table grid using DIV (HTML & CSS only). I almost got into and still got some issues. I attached the sample image. I want the grid should be the same like this sample image. I attached the fiddle of what I created so far. Could you help somebody that what am doing and how can I improve to finish the table as same as the image?
HTML:
<div class="containerDiv">
<div class="rowDivHeader">
<div class="cellDivHeader">Recommendation</div>
<div class="cellDivHeader">Typical savings</div>
<div class="cellDivHeader">Improved SAP</div>
<div class="cellDivHeader">Improved EI</div>
<div class="cellDivHeader">Indicative cost</div>
<div class="cellDivHeader">Include</div>
<div class="cellDivHeader lastCell">Removal Reason</div>
</div>
<div class="rowDiv">
<div class="cellDiv">Room-in-roof-insulation</div>
<div class="cellDiv">93.0</div>
<div class="cellDiv">F : 29</div>
<div class="cellDiv">B : 89</div>
<div class="cellDiv">£1,500 - £2,700</div>
<div class="cellDiv">Checkbox</div>
<div class="cellDiv lastCell">Textbox</div>
</div>
</div>
CSS:
.containerDiv {
border: 1px solid #3697f6;
width: 100%;
}
.rowDivHeader {
border: 1px solid #668db6;
background-color: #336799;
color: white;
font-weight: bold;
}
.rowDiv {
border: 1px solid #668db6;
background-color: #cee6fe;
}
.cellDivHeader {
border-right: 1px solid white;
display: table-cell;
width:12%;
padding: 1px;
text-align: center;
}
.cellDiv {
border-right: 2px solid white;
display: table-cell;
width:10%;
padding-right: 4px;
text-align: center;
border-bottom: none;
}
.lastCell {
border-right: none;
}
sample image
Add display:table-row to the row div i.e .rowDivHeader & .rowDiv
& display:table to the main div .containerDiv
.containerDiv {
border: 1px solid #3697f6;
width: 100%; display:table
}
.rowDivHeader {
border: 1px solid #668db6;
background-color: #336799;
color: white;
font-weight: bold; display:table-row
}
.rowDiv {
border: 1px solid #668db6;
background-color: #cee6fe;
display:table-row
}
DEMO