Solved

Table Center To Browser

Posted on 2012-03-15
8
236 Views
Last Modified: 2012-06-21
Hi Experts!

Thanks for reading this.

Trying to build a page with a header, footer, and a table.

Need help centering table to the browser, but the contents in the table shouldn't be centered. If you could can show the table's border and add the buttons that would be gravy.

Should look like this:

screenshoot
Here's the incomplete code:

<!DOCTYPE html>
<html>
<head>
    <title>MyTitle</title>
</head>

<body>

<div id="Header">Header</div>

    <table>
    <tr>
        <td>button 1 </td>
        <td>button 2 </td>
        <td>button 3 </td>
    </tr>
</table>

<div id="Footer"> Footer</div>

</body>
</html>

Open in new window


TIA!
0
Comment
Question by:allanau20
  • 6
8 Comments
 
LVL 22

Assisted Solution

by:Mrunal
Mrunal earned 250 total points
ID: 37728127
Hi, try this:

<html>
<head>
<style type="text/css">
#Header {background-color:#CCC; border: solid 1px #AAA;}
#Footer {background-color:#CCC; border: solid 1px #AAA;}
.centerTable {background-color:#EEE; height:90%; width:100px; margin: 20px 0px;}
.centerTable td {text-align:center; vertical-align: middle;}
</style>
</head>

<body>

<div id="Header">Header</div>
<center>
    <table class="centerTable" cellspacing="0" cellpadding="0" border="1">
    <tr>
        <td>button 1 </td>
        <td>button 2 </td>
        <td>button 3 </td>
    </tr>
</table>
</center>
<div id="Footer"> Footer</div>

</body>
</html>

Open in new window


Now you can change width of table in CSS.
0
 
LVL 16

Accepted Solution

by:
HagayMandel earned 250 total points
ID: 37728291
Try this:

The CSS
    <style type="text/css">
<!--
#Header {
	background-color: #99CCFF;
	padding-top: 2px;
	padding-bottom: 2px;
	padding-left: 4px;
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 14px;
	border: 1px solid #000000;
}
#Footer {
	background-color: #99CCFF;
	padding-top: 2px;
	padding-bottom: 2px;
	padding-left: 4px;
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 14px;
	border: 1px solid #000000;
}
#table_div {
	border: thin solid #999999;
	padding-top: 25px;
	padding-bottom: 25px;
	margin-top: 30px;
	margin-bottom: 30px;
	text-align: center;
	margin-right: auto;
	margin-left: auto;
	width: 90%;
}
#table_div #myTable {
	margin-right: auto;
	margin-left: auto;
	width: 100%;
	margin-top: 20px;
	margin-bottom: 20px;
}
#myTable .td_button {
	border: thin solid #999999;
	padding-top: 5px;
	padding-bottom: 5px;
	background-color: #CCFF00;
	margin-top: 12px;
	margin-bottom: 12px;
	float: left;
	width: 25%;
	margin-left: 6.25%;
}
-->
    </style>

Open in new window


The HTML

<div id="Header">Header</div>
<div id="table_div">
    <table id="myTable">
    <tr>
        <td class="td_button">button 1 </td>
        <td class="td_button">button 2 </td>
        <td class="td_button">button 3 </td>
    </tr>
</table> </div>
<div id="Footer"> Footer</div>

Open in new window

0
 
LVL 5

Author Comment

by:allanau20
ID: 37730856
thanks; I will try it now.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 5

Author Comment

by:allanau20
ID: 37730888
Thanks; you both are cool.

BTW, how do you show the border of the table?

I will split points. Thanks again.
0
 
LVL 5

Author Comment

by:allanau20
ID: 37730895
0
 
LVL 5

Author Comment

by:allanau20
ID: 37730906
nvm; HagayMandel had the table borderlined. Thanks!
0
 
LVL 5

Author Comment

by:allanau20
ID: 37731647
Hi HagayMandel,

a quick question; how do you change the Table width?
Tried several adjusting the 'width' in with the different selector in CSS and doesn't work.

Thanks!
0
 
LVL 5

Author Comment

by:allanau20
ID: 37731706
nvm; thanks; figured it out.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Session on Html 8 41
CSS question 4 24
ASP Error Handler 5 20
calculate days away 11 27
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question