Solved

Table Center To Browser

Posted on 2012-03-15
8
230 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to combine and minify CSS and JS files 5 16
CREATE DATABASE 3 28
convert Systemjs to Webpack 3 29
message Alert on an empty search 10 20
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

840 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