Solved

Table Center To Browser

Posted on 2012-03-15
8
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
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 …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

688 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