I have a table of items that look like this
As you can see, the table does not take up the entire width of the screen(the width of that image is the width of the screen, this app is being designed for mobile devices)
The HTML that is generated to display this looks like this:
<table>
<tbody>
<tr>
<td>
<span style="display: table; min-width: 320px; max-width: 640px; border-top: 1px solid #f6f6f6; width: 100%;">
<div style="display: table-row;">
<div style="display: table-row; float: left;">
<div><b>R8,383.00</b></div>
<div>
<img style="float: left;" src="../resources/img/icon_circle_footer.png" width="20px" height="20px">
Emirates
</div>
</div>
<div style="display: table-row; float: left;">
<div>
<div>
<span><b>13:30</b></span> - 07:00
</div>
<div style="display: table-row;">18h 30m, 1-stop</div>
</div>
<div>
<div>
<span><b>14:25</b></span> - 16:25
</div>
<div style="display: table-row;">25h 0m, 1-stop</div>
</div>
</div>
<div style="display: table-row; float: right;">
<img style="float: right;" src="../resources/img/icon_circle_footer.png" width="20px" height="20px">
</div>
</div>
</span>
</td>
</tr>
</tbody>
</table>
I didn't bother including the styles that colors the fonts. The only reason that the image is even that wide, is because I set a minimum width of 320px, and then made the last image float right.
Setting min-width to 100% does not work. I'm at my wits end here, and I would really appreciate some help if anyone can lend it.
What you want is width='100%' inline style. DEMO
100 % width table:
<table bgcolor='red' width='100%'>
<tr>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
</tr>
<tr>
<td>31</td>
<td>32</td>
<td>33</td>
<td>34</td>
</tr>
</table>
Fiddle DEMO: http://jsfiddle.net/xeemez/WJJBX/
Alternatively you can use CSS instead of inline tags like this:
table{
background:red;
width:100%; }
DEMO
if you have a try give <table width="100%"></table>
OR
you make class table{width:100%;} both of work
HTML
<table width="100%">
<tbody>
<tr>
<td>
<span style="display: table; min-width: 320px; max-width: 640px; border-top: 1px solid #f6f6f6; width: 100%;">
<div style="display: table-row;">
<div style="display: table-row; float: left;">
<div><b>R8,383.00</b></div>
<div>
<img style="float: left;" src="../resources/img/icon_circle_footer.png" width="20px" height="20px">
Emirates
</div>
</div>
<div style="display: table-row; float: left;">
<div>
<div>
<span><b>13:30</b></span> - 07:00
</div>
<div style="display: table-row;">18h 30m, 1-stop</div>
</div>
<div>
<div>
<span><b>14:25</b></span> - 16:25
</div>
<div style="display: table-row;">25h 0m, 1-stop</div>
</div>
</div>
<div style="display: table-row; float: right;">
<img style="float: right;" src="../resources/img/icon_circle_footer.png" width="20px" height="20px">
</div>
</div>
</span>
</td>
</tr>
</tbody>
</table>
DEMO2
CSS
table{
background-color:yellow;
width:100%;
}
If you don't set a specific width for your table it will only take the space necessary to show the content it holds. So use width: 100%.
You should add width="100%" for parent table.
<table width="100%">
Please use div's, not tables :)
DEMO
width:100%;
Have a good day! :D
UPDATE:
Why not use tables for layout in HTML?
Only in <table> you can define width. Td might work, but to make sure it works the same everywhere you have to make it to <table width="_of_your_desire">
the same goes with the height - only this time height can be defined only in <td>.
Luck
Related
I have a table in my jsp inside a div which is resizeable.
When I'm resizing the div, I'm not able to resize the height of table inside where as width of table is getting resized. Following is my snippet. Please check once.
<div id="id" style="height:350px; width250px;" class="control">
<div id="fifth_heading" class="heading_control">
<i class="fa2 fa-fifth"></i>
<p><%=entry1.getDivdescription() %></p>
<div class="button_right_second">
<i class="fa3 fa-second3" id="<%=entry1.getDivid() %>"></i>
</div>
</div>
<div class="fifth_dropdown">
<div class="table_data" id="table_second">
<table id="example3" style="height:auto;"class="display" border="0" cellspacing="0" cellpadding="0">
<!-- the below tr prints the dates -->
<tbody>
<tr id="line1">
<td>
<span id="header_title">Your Current Lead Time</span>
</td>
</tr>
<tr id="line2">
<td>
<span id="value">alignvalue</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
div.table_data{margin-left:2px;margin-right:10px;margin-top:5px;overflow:auto;}
#table_second::-webkit-scrollbar{
width:10px;
background-color:#cccccc;
}
#table_second::-webkit-scrollbar-thumb{
background-color:rgb(78, 82, 93);
border-radius:10px;
}
#table_second::-webkit-scrollbar-thumb:hover{
background-color:rgb(78, 82, 93);
border:1px solid #333333;
}
#table_second::-webkit-scrollbar-thumb:active{
background-color:rgb(78, 82, 93);
border:1px solid #333333;
}
Try setting the height of your table to 100% and explicitly setting the div's height.
Answer as per this post: link
Not sure which <div> you want to resize but you can try one of these...
If you want to resize the <div id="id" ... class="control"> to make your <table> resized, try to add the height property in your div.table_data with % percent unit.
If you like to resize your <div> and <table>, you must set the height your <div> with class control, div.table_data and your <table> to 100% or any value (from 0-100) with % percent unit.
My code snippet after doing that...
CSS
div.table_data
{
margin-left:2px;
margin-right:10px;
margin-top:5px;
overflow:auto;
height:70%;
background-color:#ccffcc;
}
(Excluded the -webkit-scrollbar)
HTML
<div id="id" style="height:100%; width250px;background-color:#ff9999;" class="control">
<div id="fifth_heading" class="heading_control">
<i class="fa2 fa-fifth"></i>
<p>dddddddd</p>
<div class="button_right_second">
<i class="fa3 fa-second3" id="ddd"></i>
</div>
</div>
<div class="fifth_dropdown">
<div class="table_data" id="table_second">
<table id="example3" style="height:100%;" class="display" border="1" cellspacing="0" cellpadding="0">
<!-- the below tr prints the dates -->
<tbody>
<tr id="line1">
<td>
<span id="header_title">Your Current Lead Time</span>
</td>
</tr>
<tr id="line2">
<td>
<span id="value">alignvalue</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
This snippet can make the two <div> and your <table> will be re-sized when the window is re-sized.
If you don't like that your <table> will be too small if the size of your window is too small, you can use the min-height CSS property. For bigger sizes, use max-height.
I can get two divs next to each other using display: inline-block; in the style attribute, but then the div on the right side is aligned on the bottom rather than at the top. So I tried floating the divs and I get another issue...
If I use floats like so:
<div style="width:100%">
<div style="width:25%; float:left;">
<asp:HyperLink ID="hlPic" runat="server" Target="_blank" ToolTip="Click to open this picture.">
<asp:Image ID="imgPic" Width="256px" Height="256px" runat="server" ToolTip="Picture" />
</asp:HyperLink>
</div>
<div style="width:75%; float:right;">
<table style="width:100%">
<tr>
<td>
<h2 style="display:inline;"><asp:HyperLink ID="hlCGValue" runat="server" ToolTip="Go to this corporate group.">[hlCGValue]</asp:HyperLink></h2>
</td>
</tr>
<tr>
<td>
<h3 style="display: inline;">
<asp:Label ID="lblCompanyNameValue" runat="server"></asp:Label></h3>
<asp:Label ID="lblCompanyID" runat="server" Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:HyperLink ID="hlWebsiteValue" runat="server" Target="_blank">[hlWebsiteValue]</asp:HyperLink>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblAssignedToValue" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
</div>
I get the following layout:
Notice the table with text is so far away from the picture...I'd like to move it right next to the picture. I tried doing it using display: inline-block but then the table of data would be next to the picture however it would sit at the bottom of the div rather then at the top (probably due to the size of the pic). If it helps the max size of the picture should only be 256px x 256px.
Can anyone help me with my CSS / HTML to make this look right...
Rendered html
<div style="width:100%">
<div style="width:25%; float:left;">
<a id="MainContent_hlPic" title="Click to open this picture." href="/Attachments/Pictures/56_27_11_2013_23_26_11_2013_Penguins.jpg" target="_blank"><img id="MainContent_imgPic" title="Picture" src="/Attachments/Pictures/56_27_11_2013_23_26_11_2013_Penguins.jpg" style="height:256px;width:256px;" /></a>
</div>
<div style="width:75%; float:right;">
<table style="width:100%">
<tr>
<td>
<h2 style="display:inline;"><a id="MainContent_hlCGValue" title="Go to this corporate group." href="../Corporate/Details.aspx?CorporateGroupID=39">Ford</a></h2>
</td>
</tr>
<tr>
<td>
<h3 style="display: inline;">
<span id="MainContent_lblCompanyNameValue">Ford Global Test Co.</span></h3>
</td>
</tr>
<tr>
<td>
<a id="MainContent_hlWebsiteValue" href="http://www.ford.com" target="_blank">www.ford.com</a>
</td>
</tr>
<tr>
<td>
<span id="MainContent_lblAssignedToValue">Name</span>
</td>
</tr>
</table>
</div>
</div>
You can use display: inline-block. When you want them aligned at the top, you must use vertical-align: top
<div>
<div id="#first">
<!-- image -->
</div>
<div id="second">
<!-- table -->
</div>
</div>
#first, #second {
display: inline-block;
vertical-align: top;
}
JSFiddle
The problem with display: inline-block is that the whitespace between your two div elements is NOT ignored. The result is that the width of your 2 divs + the width of the whitespace is more than 100%. That's why the second div appears under the first one.
One way to fix this is to set font-size: 0 on the parent element, but there are other solutions:
http://davidwalsh.name/remove-whitespace-inline-block
I have a table within a div using the span12 class from twitter bootstrap which is contained within a row class div all surrounded by a footer tag as follows:
<footer class="footer">
<div class="row">
<div class="span12">
<table>
<tr>
<td> <!-- Contact Us -->
<table>
<tr>
<td><b>Contact Us</b></td>
</tr>
<tr>
<td>Tel: 01234 567897</td>
</tr>
<tr>
<td>E-mail: info#email.com</td>
</tr>
</table>
</td>
<td> <!-- Useful Links -->
<table>
<tr>
<td><b>Useful Links</b></td>
</tr>
<tr>
<td>Contact Us</td>
</tr>
<tr>
<td>About Us</td>
</tr>
<tr>
<td>Copyright Information</td>
</tr>
<tr>
<td>Terms & Conditions</td>
</tr>
</table>
</td>
<td> <!-- Social -->
<table>
<tr>
<td><b>Connect With Us</b></td>
</tr>
<tr>
<td>Facebook</td>
</tr>
<tr>
<td>Twitter</td>
</tr>
<tr>
<td>Google Plus</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</footer>
I have the following CSS applied:
/* Table Style */
.footer table {
table-layout:fixed;
margin-right: auto;
margin-left: auto;
width: 100%
}
.footer td b {
vertical-align:top;
color: #ccc2a0;
}
.footer td {
vertical-align:top;
color: #a8a8a8;
}
I have tried to get the space between the left side of the footer and the first table data to be the same as the space between the right side of the footer and the last table data however it always has a bigger gap on the right side.
Can anyone see a problem with the CSS I am using?
Thanks
EDIT:
Here is the code for trying to achieve this using divs:
<footer class="footer">
<div class="row" style="background-color:red;">
<div class="span12" style="background-color:orange;">
<div class="span4" id="leftFooter">
</div>
<div class="span4" id="middleFooter">
</div>
<div class="span4" id="rightFooter">
</div>
</div>
</div>
</footer>
The CSS simply colours the boxes so I can see what is going on and adds some height to the divs.
The grey box is the footer div, the red box is the row and the orange box is the span12. The rest are the 3 content divs of span4. Not sure why they don't stay on the same row.
I changed some of it and stripped all styling out (sorry), but your spacing should be fixed horizontally. You can apply whatever else you want styling wise. Also, I got rid of all the embedded tables because it was so cumbersome...I can adjust the vertical spacing if you want, but I just threw this together to give you an idea for horizontal spacing.
http://jsfiddle.net/YYZwY/1/
HTML:
<footer class="footer">
<table>
<td>
<div id="ContactUS" class="information">Contact Us</div>
<div id="Telephone" class="information">Tel: 01234 567897 </div>
<div id="email" class="information">Email: info#email.com</div>
</td>
<td>
<div class="links">Useful Links</div>
<div class="links">Contact Us</div>
<div class="links">About Us</div>
<div class="links">Copyright Information</div>
<div class="links">Terms & Conditions</div>
</td>
<td>
<div class="connect"><b>Connect With Us</b></div>
<div class="connect">Facebook</div>
<div class="connect">Twitter</div>
<div class="connect">Google Plus</div>
</td>
</footer>
CSS:
.links {
padding-left: 10px;
padding-right: 10px;
position: relative;
}
.connect {
padding-left: 10px;
padding-right: 10px;
position: relative;
}
.information {
padding-right: 10px;
}
CSS:
.span12 {
text-align: center;
}
This solution works if we don't mind the text alignment.
Result [CodePen] : http://codepen.io/loxaxs/pen/kilLG
A different solution:
CSS:
.span12 {
padding-left: 15%;
}
Result [CodePen] : http://codepen.io/loxaxs/pen/izIHq
Whats the best way to split up a table element <td>? I don't really want to use nested tables. I need the internal element to have two elements one that is left justified and the other to be right justified with no border.
For example:
<table>
<tr>
<td>LEFT, RIGHT</td>
</tr>
</table>
any other ways to do this besides the following?
<table>
<tr>
<td>LEFT</td>
<td>RIGHT</td>
</tr>
</table>
I want the internal element to be a <span> or whatever is best for this.
<table>
<tr>
<td>
<div style="float:left">LEFT</div><div style="float:right">RIGHT</div>
</td>
</tr>
</table>
I would do something like:
<td><div class="left>LEFT</div><div class="right">RIGHT</div></td>
then my css would resemble:
td{position: relative;}
td .left{position: absolute; text-align: left; left: 0;}
td .right{position: absolute; text-align: right; right: 0;}
... or something along those lines.
You could do it like this, although spans and divs are much better imo.
<table width="100%">
<tr width="100%">
<td width="100%">
<span style="float:left;">left</span>
<span style="float:right;">right</span>
</td>
</tr>
</table>
The floats didn't seem to look right so I used flexbox:
https://jsfiddle.net/6rc8w709/
.td-content{
display:flex;
}
.child{
flex:1;
}
.right{
text-align:right;
}
HTML:
<table>
<tr>
<td>
<div class="td-content">
<div class="child">
LEFT
</div>
<div class="child right">
RIGHT
</div>
</div>
</td>
</tr>
</table>
Flexbox is the right approach since it is now supported by all major browsers. This is an alternative approach if you need to target an older browsers or you don't like the drawbacks of floats. With this approach you can control the overflow of the left and right segment better and you can easily add a centered segment if you need one.
CSS:
table{
width: 100%;
}
.container{
width: 100%;
display: table;
}
.cell{
display: table-cell;
}
.cell .left{
text-align: left;
}
.cell.right{
text-align: right;
}
HTML:
<table>
<tr>
<td>
<div class="container">
<span class="cell left">LEFT</span>
<span class="cell right">RIGHT</span>
</div>
</td>
</tr>
</table>
I read that each column of a table can be styled using <colgroup> and <col>. I tried the following, but the style speficication is not seeming to work. How can I fix it?
When I do this with width property, it works. Is there anything wrong with text-align property?
<html><body><table>
<colgroup>
<col style="text-align:right" />
<col style="text-align:center" />
<col style="text-align:left" />
</colgroup>
<tr>
<td>aaaaaaaaaaa</td>
<td>bbbbbbbbbbb</td>
<td>ccccccccccc</td>
</tr>
<tr>
<td>aaa</td>
<td>bbb</td>
<td>ccc</td>
</tr>
</table></body></html>
The result is that each colum is left aligned by default, ignoring the specification made in colgroup.
I am using Chrome 17.
While support for colgroup and col seems to be spotty, I don't think one should throw out the baby with the bathwater. I think tables have their place, to display tabular data. Using divs to display tabular data borders on table-phobia in my opinion.
<html><body>
<style>
.left {text-align:left;}
.center {text-align:center;}
.right {text-align:right;}
</style>
<table>
<tr>
<td class="left">aaaaaaaaaaa</td>
<td class="center">bbbbbbbbbbb</td>
<td class="right">ccccccccccc</td>
</tr>
<tr>
<td class="left">aaa</td>
<td class="center">bbb</td>
<td class="right">ccc</td>
</tr>
</table>
</body></html>
If not in need of tables, here´s how I´d do it tableless, just in case:
HTML:
<div id="container">
<div class="left">left aligned text</div>
<div class="center">center aligned text</div>
<div class="right">right aligned text</div>
</div>
CSS:
.container {}
.left {
width:100px;
float:left;
text-align:left;
}
.center {
width:100px;
float:left;
text-align:center;
}
.right {
width:100px;
float:left;
text-align:right;
}
(and you could just unify all the common styles with commas and just separate the text-alignment)
Don't use tables, use divs. Obviously the following should be seperated out into classes and such, but it works.
<html><body>
<div style="display: table">
<div style="display: table-row">
<div style="display: table-cell;">aaaaaaaaaaa</div>
<div style="display: table-cell;">bbbbbbbbbbb</div>
<div style="display: table-cell;">ccccccccccc</div>
</div>
<div style="display: table-row">
<div style="display: table-cell; text-align:right;">aaa</div>
<div style="display: table-cell; text-align:center;">bbb</div>
<div style="display: table-cell; text-align:left;">ccc</div>
</div>
</div>
</body></html>