Stripy HTML tables and rowspan - html

Original table (http://highspeedbroadband.com.my/home-package/comparison-chart-for-home-package/)
I want to modify the original as highlighted in image below. I can do this by adding rowspan and colspan attribute to td elements but when I use row span in stripy tables the order of alternative color breaks and gives me ugly result.
someone help me please.

Try wrapping those three texts with another table in which every FREE xmins will be a new table cell (<td>) like this:
(...)
<td colspan="3">
<table>
<tr>
<td>FREE 50 mins</td>
<td>FREE 100 mins</td>
<td>FREE 200 mins</td>
</tr>
</table>
</td>
(...)

You could make 3 spans inside the cell.
HTML:
<td>
<span>1</span>
<span>2</span>
<span>3</span>
</td>
CSS:
table td span {
display: inline-block;
width: 30%;
background: lightblue;
}
DEMO.

<td colspan="3" id="TD_97"> <div class="xyz">
<div class="abc"> FREE 50mins </div>
<div class="abc"> FREE 100mins </div>
<div class="abc"> FREE 200mins </div>
<div class="aa"> *RM0.15/min (local fixed and mobile call)</div> </div>
</td>
CSS
.xyz{
height: 168px;
line-height: 21px;
outline: rgb(81, 94, 108) none 0px;
padding: 8px;
text-align: center;
vertical-align: middle;
float:right;
width: 250px;
}
.abc {
float:left;
width:77px;
height:100px;
padding-top:50px;
border:double 3px black;
}
.aa {
border-top:none;
border:double 3px black;
padding:0;
margin:0;
clear:both;
}
DEMO

Related

How to remove the collapse in a table using css

I'm trying to code a status cars for a character using Css and Html and I ant to remove those black collapse from the inside of the table so that it ill look like it's 40% Red and 60% Green.
Like the photo here:
enter image description here
I tried this:
.border table{
border-collapse: collapse;
width: 235px;
margin: 2px;
}
.border td{
padding:3px; /* the height */
border:2px solid black;
}
.percent20{
background-color:#ff000d;
}
.percent60{
background-color:rgba(18, 148, 18, 0.7);
}
But it didn't work and that's the further point I've reached:
enter image description here
The HTML code:
<div class="border">
<table>
<tr>
<td class="percent60"></td>
<td class="percent20"></td>
<td class="percent60"></td>
<td class="percent60"></td>
<td class="percent60"></td>
<tr>
</table>
</div>
I tried using just divs without using any tables but I cant make the percentages and all I got is small squares.
You can try using colspan for this particular scenario as it will combine multiple columns into one and you will be left with two columns which you can turn red or green as per your requirement.
table{
border-collapse: collapse; /* Remove cell spacing */
width: 235px;
margin: 2px;
}
table, th, td{
padding:3px; /* the height */
border:2px solid black;
}
table th, table td{
padding: 10px; /* Apply cell padding */
}
.percent20{
background-color:#ff000d;
}
.percent60{
background-color:rgba(18, 148, 18, 0.7);
}
<div class="border">
<table>
<tr>
<td class="percent60"></td>
<td class="percent20"></td>
<td class="percent60"></td>
<td class="percent60"></td>
<td class="percent60"></td>
<tr>
</table>
</div>
I solved the problem myself, Making the table with Html is just pain so I created it with only Divs.
The Css code:
/* Making table with only divs */
.divTable{
display: table;
width: 100%;
column-count: 5;
}
.divTableBody {
display: table-row-group;
}
.divTableRow {
display: table-row;
}
.class1, .class2{
border: 1px solid #000000;
display: table-cell;
padding: 3px 10px;
column-span: 2;
}
.class1 {
columns: 2;
background-color:#ff000d;
}
.class2 {
columns: 3;
background-color: rgba(18, 148, 18, 0.7);
}
The Html code:
<div class="border">
<div class="divTable" style="border: 1px solid #000;">
<div class="divTableBody">
<div class="divTableRow">
<div class="class1"></div>
<div class="class2"></div>
</div>
</div>
</div>
</div>

Highlight entire div when it's inside table

I'm trying to highlight a div section which is inside of a table, but it seems it's limited to the width of the table. The part after the scroll is not highlighted.
I can add styles in the div, e.g: "width:400px !important", but I don't know in advance what the width will be.
Is there any simple solution for this?
.area1{
border:1px solid;
height:200px;
overflow:scroll;
float: left;
font-size: 16px;
}
.area1Content{
height:500px;
font-size: 16px;
white-space:nowrap;
}
<div id="area1Id" class="area1">
<table>
<tr>
<td style="min-width:300px; max-width:300px"><div id="area1ContentId" class="area1Content">
<div style="BACKGROUND-COLOR:cyan;">Test long text sentence that will exceed the box width. I want that all the sentence will be highlighed</div>
</div>
</td>
</tr>
</table>
</div>
You can achieve what you're trying to do by adding inline-block to .area1Content:
.area1{
border:1px solid;
height:200px;
overflow:scroll;
float: left;
font-size: 16px;
}
.area1Content{
height:500px;
font-size: 16px;
white-space:nowrap;
display: inline-block;
}
<div id="area1Id" class="area1">
<table>
<tr>
<td style="min-width:300px; max-width:300px"><div id="area1ContentId" class="area1Content">
<div style="BACKGROUND-COLOR:cyan;">Test long text sentence that will exceed the box width. I want that all the sentence will be highlighed</div>
</div>
</td>
</tr>
</table>
</div>
I see 3 solutions :
Either use a <span> instead of a <div> to contain your text.
Either use display:inline-block on the same div
Cleaner variation of the second solution : add display:inline-block to your area1ContentIdclass in the css.
.area1{
border:1px solid;
height:200px;
overflow:scroll;
float: left;
font-size: 16px;
}
.area1Content{
height:500px;
font-size: 16px;
white-space:nowrap;
}
<div id="area1Id" class="area1">
<table>
<tr>
<td style="min-width:300px; max-width:300px"><div id="area1ContentId" class="area1Content">
<div style="BACKGROUND-COLOR:cyan; display:inline-block">Test long text sentence that will exceed the box width. I want that all the sentence will be highlighed</div>
</div>
</td>
</tr>
</table>
</div>
Note also that instead of using the styleattribute I'd rather define a class in the CSS

How to align two columns in HTML

I am trying to format a personal info list in HTML.
Something like:
.myself p{
font-size: 130%;
margin-left: auto;
margin-right: auto;
text-align: center;
}
<div class="myself">
<p>Name: First Last<br /><br />Age: 21<br /><br />Movie: xxxxx<br /><br /></p>
</div>
but when you run this code, it will look like
Name: First Last
Age: 21
Movie: xxxxx
which basically is centered every line. What I really want to achieve is like this:
Name: First Last
Age: 21
Movie: xxxxx
which align all the ":" colons.
My idea is to make a table, then align each column separately, but I doubt that is the best way to do make this. Hope you guys can give me some better solutions. Thank you.
Try this piece of code.
This is called a grid layout, which is currently one of the most used types of layouts ones. The main idea about it is just splitting your page into boxes and stacking them together.
.myself .property{
width:30%;
display:inline-block;
box-sizing:border-box;
text-align:right;
}
.myself .value{
text-align:left;
padding-left:10px;
width:70%;
display:inline-block;
box-sizing:border-box;
}
<div class="myself">
<div class="property">Name:</div><div class="value"> First Last</div>
<div class="property">Age:</div><div class="value"> 21</div>
<div class="property">Movie:</div><div class="value"> xxxxxx Last</div>
</div>
Another option instead of using a table is to use the <dl> element. Here's a basic example of how it would look:
dl>dt {
float: left;
width: 150px;
overflow: hidden;
clear: left;
text-align: right;
text-overflow: ellipsis;
white-space: nowrap;
font-weight: bold;
}
dl>dd {
margin-left: 160px;
}
<dl>
<dt>Name:</dt>
<dd>First Last</dd>
<dt>Age:</dt>
<dd>21</dd>
<dt>Movie:</dt>
<dd>xxxxx</dd>
</dl>
The benefit is less HTML code than what a table would require, and less convoluted. However, if column headers are required, then you should definitely use a <table> element.
In my opinion there is no problem using a table for simple stuff like these.
<table>
<tr>
<td class="titles"> My name :</td>
<td>John</td>
</tr>
</table>
styles
.titles { text-align : right; }
This is my solution with tables. Not pixel perfect but it should get you started...
#mytable {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 200px;
}
#mytable td {
border: 1px solid #ddd;
padding: 8px;
}
#mytable .centered{
text-align:center;
}
#mytable .age{
padding-left:54px;
}
#mytable .movie{
padding-left:40px;
}
#mytable tr:nth-child(even){background-color: #f2f2f2;}
#mytable tr:hover {background-color: #ddd;}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table id="mytable">
<tr>
<td class="centered">Name: First Last</td>
</tr>
<tr>
<td class="age">Age: 21</td>
</tr>
<tr>
<td class="movie">Movie: xxxxx</td>
</tr>
</table>

Equal width spacing with div table

I am trying to figure out why I keep having first column in my div table have more space than the rest of the columns. I don't understand what is so special about it considering I apply the same CSS to all columns equally. I am trying to keep the same equal width for all columns. But look what I have:
My goal is to have the same equal space between Value1, Value 2, Value3 and Value 4. Here is my CSS and its HTML:
.Table2
{
display: table;
background:white;
}
.Row2
{
display: table-row;
}
.Cell3
{
display: table-cell;
white-space:nowrap;
padding-left: 5px;
padding-right: 5px;
}
.Cell4
{
display: table-cell;
white-space:nowrap;
padding-left: 5px;
padding-right: 5px;
border-top:1px solid;
}
.Cell5
{
display: table-cell;
white-space:nowrap;
padding-left: 5px;
padding-right: 5px;
border-bottom:1px solid;
}
I did the research and this is how div tables are made. According to examples I've seen, they all had the same equal spacing, but why am I having one column with greater space than the rest? I don't understand what is so special about Value 1 column in my CSS This is my HTML:
<div class="Table2">
<div class="Row2">
<div class="Cell3">
<p><font class="textlargedarkblue"> Info: </font> <font class="textTotalPrice1"> $1.00</font></p>
</div>
</div>
<div class="Row2">
<div class="Cell4">
<p><font class="textsmalldarkblue"> Value1 </font></p>
</div>
<div class="Cell4">
<p><font class="textsmall"> Value2 </font></p>
</div>
<div class="Cell4">
<p><font class="textsmall"> Value3 </font></p>
</div>
<div class="Cell4">
<p><font class="textlittle">Value4 </font></p>
</div>
</div>
</div>
Could somebody explain to me how I can keep all Value columns have the same space width?
P.S. The CSS for Value1 is not having any spacing of its own, it's simply defining font and color:
.textlargedarkblue{font-family: Verdana, Geneva, sans-serif;font-size:16px; color:darkblue; font-weight: bold}
Same for Value2..Value4 So that shouldn't be the problem.
That column is stretching to fit your Info: $1.00 line. You should put that in a div or something separate, since it isn't part of the table. Or make that row a different class and remove the display: table-row; for it.
My honest opinion is that you should use table's for this matter... they're created to display tabular content.
<table>
<tr>
<th colspan="4">Info: <span>$1.00</span></th>
</tr>
<tr>
<td>Value 1</td>
<td>Value 2</td>
<td>Value 3</td>
<td>Value 4</td>
</tr>
</table>
CSS:
table {
border: 0;
border-collapse: collapse;
}
table th {
padding: 0 5px;
text-align: left;
}
table td {
border-top: 1px solid black;
}
DEMO.

Div alignment is not working

I am having a main div PricingBar inside that i have 3 sub div's . while keeping PricingBar height: auto; sub div's are displaying out of the PricingBar
Here Green color border is PricingBar
Option A, Option B, Option C are sub div's
html code:
<div id="PriceBar">
<div id="OptionA">
<h2>Option A</h2>
<table class="optiontable">
<tr><td class="column1">Setup Fee: </td><td><span>$250.00</span> (includes 10 customized apparel pieces)</td></tr>
<tr><td class="column1">Monthly Fee:</td><td><span>$25.00</span></td></tr>
</table>
</div>
<div id="OptionB">
<h2>Option B</h2>
<table class="optiontable">
<tr><td class="column1">Setup Fee:</td><td><span>$99.00</span> (includes 10 customized apparel pieces)</td></tr>
<tr><td class="column1">Monthly Fee:</td><td><span>$40.00</span></td></tr>
</table>
</div>
<div id="OptionC">
<h2>Option C</h2>
<table class="optiontable">
<tr><td class="column1">Setup Fee:</td><td>Refund</td></tr>
<tr><td class="column1">Monthly Fee:</td><td>Refunded</td></tr>
</table>
</div>
</div>
css code:
#PriceBar{
width: 1004px;
position: relative;
height:auto;
padding:10px;
border: 2px solid green;
background:#930;
float: inherit;
}
#OptionA, #OptionB, #OptionC{
margin: 10px 20px;
padding: 5px;
float: left;
width: 283px;
height: auto;
background-color: #FFF;
-webkit-border-radius:15px;
-mox-border-radius:15px;
border-radius:15px;
}
#OptionA h2, #OptionB h2, #OptionC h2{
text-align: center;
font-size: 18px;
font-weight: bold;
color: #006A8E;
}
table.optiontable tr td{
padding: 10px 5px;
color: #B9B196;
}
td.column1{
width:100px;
vertical-align: top;
font-size: 12px;
font-weight: bold;
font-family: Verdana, Geneva, sans-serif;
color: #252525 !important;
}
table.optiontable tr td span{
font-weight: bold;
}
Since all your div elements float, the "red bar" basically "forgets" that it is the container for them. Simply add an overflow:auto; to make it remember. I also tend to add zoom:1 for IE.
because of float of sub div's
add overflow:hidden to PricingBar
#PriceBar{
width: 1004px;
position: relative;
height:auto;
padding:10px;
border: 2px solid green;
background:#930;
float: inherit;
overflow:hidden;/*!!!*/
}
Add overflow:hidden to your #PriceBar style should do the trick.
Demo
http://jsfiddle.net/8aduV/1/
You don't need the height:auto;
Just make it a table, as it would be crossbrowser:
<table id="PriceBar">
<tr>
<td id="OptionA">
<h2>Option A</h2>
<table class="optiontable">
<tr><td class="column1">Setup Fee: </td><td><span>$250.00</span> (includes 10 customized apparel pieces)</td></tr>
<tr><td class="column1">Monthly Fee:</td><td><span>$25.00</span></td></tr>
</table>
</td>
<td id="OptionB">
<h2>Option B</h2>
<table class="optiontable">
<tr><td class="column1">Setup Fee:</td><td><span>$99.00</span> (includes 10 customized apparel pieces)</td></tr>
<tr><td class="column1">Monthly Fee:</td><td><span>$40.00</span></td></tr>
</table>
</td>
<td id="OptionC">
<h2>Option C</h2>
<table class="optiontable">
<tr><td class="column1">Setup Fee:</td><td>Refund</td></tr>
<tr><td class="column1">Monthly Fee:</td><td>Refunded</td></tr>
</table>
</td>
</tr>
</table>
​
It's Normal, If you have an height in auto; in your two first block your block is in two lines, in the third, text it's just in one block, try whith "min-height" in every "tr"
tr{
min-height:40px;
}
Or, other solution is to create a global table, for all your code. your three colums was link, and you don't have this problem :p
For debuging, Use Firebug it's more easy for testing your html code and CSS.
I hope I help you ;-P