I needed some help with table alignment. I haven't coded for a while, and can't figure out what I am doing wrong here. I have these divs setup, and a table in one, but for some reason the table does not align to the middle. It just aligns with the left side of the table, and the rest leads off to the right. Here is my code:
<div id="SlideShow_Wrapper" align="center">
<div id="SlideShow_Background" align="center">
<div align="center" id="SlideShow">
<table border="1" align="center" >
<tr align="center">
<td style="padding-right:15px;"><img src="LeftArrow.png" /></td>
<td><img id="SlideShow_Picture" src="Ore_Background.png" /></td>
<td style="padding-left:15px;"><img src="RightArrow.png" /></td>
</tr>
</table>
</div>
</div>
</div>
And here is my css:
#SlideShow {
margin:0px auto;
}
#SlideShow_Background {
background-image:url(Stone.png);
border-radius:10px;
width:820px;
height:420px;
}
#SlideShow_Wrapper {
padding-top:50px;
}
I tried some things out, and when I remove the SlideShow_Background, the table aligns as normally, but when I add it back in, the table just aligns to the right. Any help would be nice
EDIT:
I want the table to be centered, not off to the right. This jsFiddle shows it, but without the content, but you can see what I mean.
And this next link is how I want it to be, jsfiddle.net/fuECu see how it's centered, But I cant find a way to do that without taking off the SlideShowbackground div.
Your table is centered already. The SlideShow_Background division just create a horizontal scroll bar on small screens. But still if you scroll the bar to the middle, you will see that table is on the center.
Still if you want the table to be centered, you don't have to remove the SlideShow_Background. Just remove the height and width attribute of the div. And it will be set to auto.
#SlideShow_Background{
background-image:url(Stone.png);
border-radius:10px;
}
Fiddle
Related
I'm using a three-column Skeleton layout for my website. All works how I want it apart from one thing. I have an image aligned and above a table. See below:
http://www.cosworth-europe.co.uk/catalogue/pistonringsets.html
If I add max-width:100%; to the image it slightly shrinks and moves it out of line with my table before I've even resized by browser. See here:
http://www.cosworth-europe.co.uk/catalogue/pistonringsets2.html
Is there a way I can keep the max-width, but so it doesn't resize at all until the screen size changes?
HTML
<div class="six columns">
<img src="../images/catalogue/pistonringslarge.jpg">
<p style="padding-top:10px;"></p>
<table style="font-size:11px; width:380px; margin-left:20px;">
<tbody>
<tr>
<td style="padding-right:5px; width:70px;">Product Code</td>
<td style="background-color:#133D8D; color:white; padding-left:5px;">Description</td>
</tr>
CSS
.container .six.columns {
width: 340px;
}
as Mr Listed pointed out... my image was fine, it was in fact the table that had overgrown the div due to adding a 20px margin. I removed the margin and added max-width:100% to my table. all works great now.
I have div, which has all content aligned to center:
<div align="center">
<table><tr><td>.....
But align is not more valid attribute. So, i have changed to class or style:
<div style="text-align:center;">
But it is not the same as before. Table is now aligned to left and not to center. Obvious text-align is not equivalent to old center attribute. How should i write style to achieve the same functionality as before with center attribute?
Just use margin: 0 auto on your table to center it.
See HERE
To align the table to center of the parent element of the table, just use:
table {
margin: 0 auto;
}
Also to align the table to center in respect of height of the parent element of table, you can give line-height same as height of the parent element.
As mentioned above in the comment you need to align the table
Add this to your CSS:
table.center {
margin-left:auto;
margin-right:auto;
}
And then add this to your table:
<table class="center">
...
</table>
Perhaps take a look here?
I've used that several times to vertically center content.
Then take a look at bootstrap. They have mix-ins that take care of the horizontal alignment (here).
Edit:
#mattytommo has a good answer for the horizontal alignment.
If you want to align table to center, use the following
<table align="center">
This will align your table to centre of div.
You can try this:-
div{
width:90%;
margin:0 auto;
text-align:center;
}
or
<div style="width:90%;margin:0 auto;text-align:center">
<table>
<thead>
<tr>
<th>header</th>
</tr>
</thead>
<tbody>
<tr>
<td>data</td>
</tr>
</tbody>
</table>
</div
I'm trying to create an e-mail newsletter in HTML. The layout has a fixed-width (600px) center. If the viewport is larger than 600px in width, there should be some decoration images on the left and the right. These images should be 'glued' to the viewport's edges:
As you can see, when the viewport scales, the fixed-width (blue) content stays centered, but the (red) images on the left and on the right are moving with the viewport's edges.
If the viewport gets too narrow, the (red) images should become fixed such that they don't overlap the (blue) center content.
To accomplish this, I'm using <div>s with auto margins for the (red) images, for example: margin:0 auto 0 0.
This works well, except that on small devices like the iPhone, I want the e-mail client to just show the (blue) centered content:
But the <div>s with the (red) images on the side influence the content width, so the e-mail clients show them too.
How can I achieve this? Using Javascript and/or CSS media queries is not an option, since most e-mail clients strip CSS and JS from the e-mail HTML.
You should use tables.
You'll need 3 tables for that.
First, the good old centering table:
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
Then, another centering table of 3 columns in percents:
<table width="100%" align="center" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="15%" align="left" valign="middle">YOUR LEFT CONTENT HERE</td>
<td width="70%" align="center"> YOUR MAIN CONTENT TABLE HERE </td>
<td width="15%" align="right" valign="middle">YOUR RIGHT CONTENT HERE</td>
And, in the middle TD of the previous center, you can put your 600px wide main content table.
This might need some styling tweaks with floats and block elements aligns, but the basic structure is there.
*Table 2 is nested in table 1's main TD cell.
For mobile mail clients, just put a class on the two LEFT and RIGHT tds, then have them display:none; in your media query. Since the content will be nested inside those, it will inherit the display none and your 3 columns table will effectively become a single column one.
This is not possible without media queries. There is no way to get the left and right columns to pop or hide on resize. Even if you used a float/align technique, it would just pop the right side only (then center with the left above).
I would suggest a fluid table with a max width div to keep your main content at 600px.
<style>
#media only screen and (min-device-width: 600px) { /* don't over stretch */
.main {
width:600px !important;
}
}
</style>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
<tr>
<td width="15%" align="left">left
</td>
<td width="70%" align="center">
<div class="main" style="max-width:600px !important;">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td>
center
</td>
</tr>
</table>
</div>
</td>
<td width="15%" align="right">right
</td>
</tr>
</table>
What about a table where the middle cell has a fixed width and the other two cells have a) either a background image aligned to either side, or b) have an image with overflow:hidden on the cells?
Here's a more minimal solution to what you want to achieve.
For the red elements, you can continue to set their positions with margin: 0 auto 0 0... etc, but include this CSS:
width: 0;
overflow: visible;
z-index: 1;
This way, the red elements won't "clash" with the blue <div> when they "meet".
For the blue <div>, declare a higher z-index:
z-index: 2;
Because the z-index of the blue is higher than the red, the red elements will hide underneath the blue element when they "overlap".
Note: gmail does not yet support z-index (source), but you could look into creating the same effect through default stacking.
Side notes:
It REALLY does not have to get as complex as using tables. Read: Why not use tables for layout in HTML?
In both IE8 and Firefox I am experiencing the following:
I have a panel that is 30px in height, within this panel I have a single row table with 30px in height. When it displays on the browser window the table does not fill the height of the panel (there is a small amount of the panel showing on the top and bottom. How do I correct this so that the table takes up the entire height of the table?
HEADERPANELTABLE CSS:
table.masterHeader
{
background-color:transparent;
border-collapse:collapse;
height:30px;
margin-left:auto;
margin-right:auto;
margin-top:0;
margin-bottom:0;
padding:0;
display:block;
width:820px;
}
HEADERPANEL CSS:
.HeaderPanel
{
background-color:#0079d0;
height:30px;
margin-left:auto;
margin-right:auto;
margin-bottom:0px;
margin-top:0px;
padding:0;
width:820px;
}
SPACER CSS:
div.Spacer
{
background-color:transparent;
height:30px;
}
MAINPANEL CSS:
.MainPanel
{
background-color:#6699cc;
height:700px;
margin-left:auto;
margin-right:auto;
width:820px;
}
HTML CODE:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div class="Page">
<asp:Panel ID="HeaderPanel" CssClass="HeaderPanel" runat="server">
<table class="masterHeader" cellspacing="0" cellpadding="0">
<tr>
<td class="Account"></td>
<td class="Name"></td>
<td class="Spacer"></td>
<td class="CompanyName"></td>
<td class="Logout"></td>
</tr>
</table>
</asp:Panel>
<asp:RoundedCornersExtender ID="HeaderPanelRounded" TargetControlID="HeaderPanel" runat="server" Radius="3" Corners="Bottom"></asp:RoundedCornersExtender>
<div class="Spacer"> </div>
<asp:Panel ID="MainPanel" runat="server" CssClass="MainPanel">
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
</asp:Panel>
</div>
<asp:RoundedCornersExtender ID="rceMainPanel" runat="server" TargetControlID="MainPanel" Radius="3">
</asp:RoundedCornersExtender>
Have you looked at the page in something like Firebug, where you can look at each DOM element, see the attributes (like margin, padding, and so on). That way you might be able to see exactly where that extra spacing is coming from, and what styling attributes are being applied to each element.
set the cellspacing to 0
<table cellspacing="0">
<tr>
<td></td>
</tr>
</table>
You haven't posted code (HTML or CSS) or stated what browsers you are seeing this in, so difficult to know for sure. Some suggestions:
make sure your table has zero margins
make sure the panel doesn't have any padding
make sure cell spacing is zero
make sure some other element isn't blocking the table
make sure your css styling is not being over-ridden somewhere
If you don't have it already, you should install the Firebug addin https://addons.mozilla.org/en-US/firefox/addon/1843/ for Firefox. This makes it extremely easy to inspect the DOM and CSS styling applied.
Because an ASP:Panel breaks up the panel into div tags and with rounded corners it add anothe 1px border to the panel which is placed after the table has been placed. In order to fix this the table had to be placed within a div tag and float the div above the panel.
I notice that you aren't doing anything about your table borders. Could this be the gap you are seeing? If your borders have any width for any reason then they could be showing which might be giving you the effect in question.
I made a quick jsfiddle proof of concept based on what I assume your outputted HTML will look like in its simplest form. I'm not familiar with the RoundedCornersExtender control though and I suspect that is modifying the HTML of the main div.
http://jsfiddle.net/tAgp3/1/
You can see that this simplified form works but I assume that the rounded corners is trying to do some nasty tricks with embedding extra DIVs with background to do rounded corners. These could be what is causing your additional padding.
Again I ask if you can post the actual html outputted to the browser so we can see if this is the case or not.
I'd like to make a (non-numbered or bulleted) list of items, where each item has some text that is adjacent to an image. It's important that the text be vertically aligned to the center of the image, and that there will enough top and bottom padding so that each pair of text and image do not vertically overlap. I tried using something like this:
img.floatRight { float: right; margin-bottom: 2px; border: 0px; vertical-align: text-middle}
.myitem { font-size: 12pt; margin-bottom: 50px; margin-top: 130px; vertical-align: middle}
in body of HTML page:
<!-- item 1 -->
<img src="item1.jpg" class="floatRight"><p class="myitem">Description of item 1</p>
<!-- item 2 -->
<img src="item2.jpg" class="floatRight"><p class="myitem">Description of item 2</p>
the problem is that the items overlap -- so the images are not vertically aligned which each other, which i'd like them to be. the margin-top and margin-bottom don't seem to add the right level of padding to achieve this. also, the vertical-align parameter does not seem to vertically align the text to the center of the image.
finally, I'm not sure if I should use p class="" or div class="" here... again, it's important not to have overlap between each items'
any ideas on how to fix this? thanks very much.
I would start with putting the images inside the p.myitem block and giving it a:
p.myitem {
overflow: hidden;
}
That should take care of the overlap.
About the vertical align of the images and the text, that can be tricky using css. If the vertical-align solution does not work and you know the height of the images and it is only one line of text, the easiest solution is giving the paragraph a line-height equal to the images.
Vertical aligning things without using tables is a pain in the butt! You're better off using a table for this. Are your images all using the same width? If not, you can remove the fixed width in td.item_photo{} and td.item_photo img{}. Also you can change table.items width from auto to 100% or a px amount (eg: 400px) if you want.
I hope this helps solve your problem.
table{margin:0;padding:0;border-collapse:collapse}
table.items{width:auto}
td.item_photo{vertical-align:middle;text-align:left;width:200px;padding:0 0 15px 15px}
td.item_text{vertical-align:middle;text-align:left;padding:0 0 15px 0;font-size:12px;line-height:16px}
td.item_photo img{display:block;width:200px}
<table class="items">
<tr>
<td class="item_text">Item 1 Description</td>
<td class="item_photo"><img src="/images/item1.jpg" /></td>
</tr>
<tr>
<td class="item_text">Item 2 Description</td>
<td class="item_photo"><img src="/images/item2.jpg" /></td>
</tr>
</table>