Solved

Table Center To Browser

Posted on 2012-03-15
8
218 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now