Div alignment is not working - html

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

Related

CSS not working properly when trying to align text with rowspan

What i am trying to do is to make HTML similar to this image.
I tried Below HTML with table and with div as well. but text is not aligning proper. Not sure what is the best way to do it. As i am using bootstrap.
Here is my HTML that i tried.
h1{
font-size:45px;
}
<table>
<tr>
<td rowspan="2"><h1>1</h1></td>
<td>Shopping Cart</td>
</tr>
<tr>
<td>small content</td>
</tr>
</table>
You can try with elements to get the result you want.
<div class="item">
<span class="count">1</span>
<div class="txt">
<h2>Shopping Cart</h2>
<p>Manage Your Item list</p>
</div>
<div class="clear"></div>
</div>
<style type="text/css">
.clear {
clear: both;
}
.count {
float: left;
font-size: 45px;
width: 30px;
}
.txt {
margin-left: 40px;
}
.txt h2,
.txt p {
margin: 0;
}
</style>
try this
<style>
.sc-col-4{
width: 33.33%;
background: #ddd;
height: 150px;
}
.left-box{
background:#007bff;
padding: 1.5rem; color: white;
padding-right: 3rem;
padding-left: 3rem;
margin-right:1.3rem;
float:left;
font-size: 50px;
}
.right-box{
float: left;
}
</style>
<div class="sc-col-4">
<div class="left-box">1</div>
<div class="right-box">
<div style="padding-top: 1rem; font-weight:600; font-size: 1.25rem; color: #007bff;">$1.999,50</div>
<div style="color: #868e96; font-weight: 700; font-weight: bold">INCOME</div>
</div>
</div>
h1{
font-size:45px;
}
#bottom{
vertical-align:bottom;
}
#top{
vertical-align:top;
}
td{
padding:0;
margin:0;
line-height:1;
}
<table>
<tr>
<td rowspan="2"><h1>1</h1></td>
<td id='bottom'>Shopping Cart</td>
</tr>
<tr>
<td id='top'>small content</td>
</tr>
</table>
Your code is actually working but the output comes like that due to the size of each cell in table try this :-
<table >
<tr>
<td rowspan="2"><h1>1</h1></td>
<td style="vertical-align:bottom">Shopping Cart</td>
</tr>
<tr>
<td style="vertical-align:top">small content</td>
</tr>
</table>
A solution using styles as mentioned above would probably be cleanest. But if you're looking for something purely within the table element, you could add a nested table as follows.
Hope this helps!
h1 {
font-size: 45px;
}
<table>
<tr>
<td rowspan="2">
<h1>1</h1>
</td>
<td>
<table cellspacing="0">
<tr>
<td>Shopping Cart</td>
</tr>
<tr>
<td>small content</td>
</tr>
</table>
</td>
</tr>
</table>

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>

Adding an image to right pushes the table below to right

I have some HTML code. I have added two images: one alinged to the left and one to the right. Then it has two headings and an HTML table after that.
The problem is that I have use the following code to add the images to the document.
<img src="http://Path_To_Foler/Logo1.jpg" align="left" />
<img src="http://Path_To_Foler/Logo2.jpg" align="right" />
<p class="h1"><b>Private and Confidential</b> </p>
<p class="h1"><b>REPORT FOR Mr Person A BLA BLA</b> </p>
<table class="table" >
<tr>
<td class="CellHeader">Date </td>
<td class="CellHeader">Time</td>
</tr>
<tr>
<td class="cell"><AssessmentDateFrmMSPAPARR /></td>
<td class="cell"><CurrentRcFrmMSPAPARR /></td>
</tr>
</table>
CSS
<style>
.CellHeader{
width:50%;
text-align:left;
font-family: 'calibri';
font-size: 11pt;
color:#FFFFFF;
background-color:#151515;
border:1px solid black;
border-collapse:collapse;
}
.cell{
width:50%;
text-align:left;
font-family: 'calibri';
font-size: 11pt;
border:1px solid black;
border-collapse:collapse;
}
.table{
width:100%;
border:1px solid black;
border-collapse:collapse;
}
.h1{
page-break-before: always;
text-align: center;
font-family: 'calibri';
font-size: 12pt;
}
<style>
Issue
Everything was working fine as expected. The problem started when I added the second image. Adding second image causes the table to be aligned right as well.
And when I take out the align:"right" atribute from the image element, the table is where it is supposed to be but the second image is pushed to the right which is kind of understandable.
How can I fix this?
Try replacing align="left" by style="float:left" and align="right" by style="float:right"
Then, add clear: both in .table{} in your CSS.

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