Equal width spacing with div table - html

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.

Related

how to reduce line height of a table row

I wanna reduce the line height between table rows. I used the following code, But it didn't work for me. Please look at my picture. I wanna reduce the line height between "Mon-Sat 09:00 AM - 7:00 PM" and
"We closed Sunday & Holidays". see the photo
I used following code, But I didn't do anything
.tb tr {
height: 0px;
}
table {
margin: 0 15.0% 0 0;
float: right;
}
p {
font-weight: bold;
float: right;
}
span {
font-weight: bold;
color: red;
}
<table class="tb">
<tr>
<td>
<p>Business Hours:</p>
</td>
<td><span>Mon - Sat 09:00AM - 7:00PM</span></td>
</tr>
<tr>
<td></td>
<td><span>We closed Sunday & Holidays</span> </td>
</tr>
</table>
Please tell me how to do it.. default table height is very high.
The p tag has margin at top and bottom from the browser css. Please just add the below condition and adjust the margins to your desired height!
.tb tr {
height: 0px;
}
p.bottom-no-space {
margin: 0px;
}
<table class="tb" style="margin:0 15.0% 0 0; float: right;">
<tr>
<td>
<p style="font-weight: bold; float: right;" class="bottom-no-space">Business Hours:</p>
</td>
<td><span style="font-weight: bold; color: red; ">Mon - Sat 09:00AM - 7:00PM</span></td>
</tr>
<tr>
<td></td>
<td><span style="font-weight: bold;color: red; ">We closed Sunday & Holidays</span> </td>
</tr>
</table>
You can easily manipulate HTML tables with css using the ff.
/*if you want your table to have borders*/
table, td, th {
border: 1px solid black;
}
/*If you want your borders to be merged to other borders*/
table {
border-collapse: collapse;
width: 100%;
}
/*Finally the height, this will give your th, td and tr an equal height of 0px
just try to play with this to get your desired height, you can also use padding*/
th, td, tr {
height: 0px;
}
https://www.w3schools.com/css/css_table_size.asp
Don't use a table. You can lay this out with much more flexibility with out. There are many ways to do this. Just one example is below. A definition list would also be a good candidate here.
.businessHours * {font-size:16px;}
.businessHours h1 {margin: 0; padding-right:1em;}
.businessHours {display:flex; align-itmes:flex-start;}
.businessHours > div {color:red; font-weight:bold;}
<section class="businessHours">
<h1>Business Hours</h1>
<div>
<div>Mon - Sun 0:900AM - 7:00PM</div>
<div>We are closed Sundsays & Holidays</div>
</div>
</section>

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

Two Tables, Overlapping Borders

Alright, so I have two tables set up, one outside the other. In order to make it display properly, I had to put the inner table within tags. Problem is, I want the inner table to completely overlap the outer table's borders on the top, left, and right. Here, look at this JSFiddle:
http://jsfiddle.net/26Fnm/15/
html:
<body>
<table class="main-body round">
<tr><td class="nopad">
<table class="header round">
<tr>
<td class="header">Test Text 1</td>
</tr>
<tr>
<td class="header2">This is a longer test text two.</td>
</tr>
</table>
</td></tr>
<tr>
<td>Line 1</td>
</tr>
<tr>
<td>Line 2</td>
</tr>
<tr>
<td>Line 3</td>
</tr>
<tr>
<td>Line 4</td>
</tr>
</table>
</body>
CSS:
body table.round
{
border:2px solid;
border-radius:25px;
}
.main-body td.header
{
text-align:left;
padding-left:50px;
color:white;
font-size:50px;
}
.main-body td.header2
{
text-align:right;
padding-right:30px;
color:white;
font-size:30px;
}
.nopad
{
border-spacing: 0px;
padding: 0px;
}
table.header
{
background-color:#151515;
width:100%;
}
.main-body
{
border-spacing: 0px;
border-collapse: separate;
color: #202020;
margin-left: auto;
margin-right: auto;
width: 600px;
background-color: #d2ffdc;
box-shadow: 10px 10px 10px #101010;
}
#navi
{
}
You can see, in the upper left and right corners, a bit of the green coming out between the two tables' borders. Not only do I want that to be gone, I want those two borders, on the top, left, and right, to essentially be one border, they are so overlapped. Like if I were to copy paste those two tables on top of each other, and they were exactly the same width. I've tried border-spacing, I've tried no padding, no margin, changing the size of the borders. Nothing has brought me close to where I want to be.
Is this even possible? Or do I have to settle for the appearance of overlapping with the inner table not having a border?
On a side note, why the heck does a JSFiddle link need code accompanying it? The code is there on the JSF page!
Something like this?
Fiddle
table, tr, td{
border-collapse: collapse;
}
table.header2
{
background-color:#151515;
width:100%;
border-radius:20px;
padding: 0;
margin: 0;
}
.nopad {
border-spacing: 0;
display: table-cell;
padding: 2px;
}

Stripy HTML tables and rowspan

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

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