I don't understand why the table headers are shifting when there is vertical scroll bar attached to table.
Here is my html code:
<div >
<ul class="nav nav-tabs" id="tab123" style="margin-top: 26px;">
<li><a href="#div1" data-toggle="tab" >Tab1</a></li>
<li><a href="#div2" data-toggle="tab" >Tab2</a></li>
</ul>
<div class="tab-content" style="overflow: hidden; margin-left: 20px; height: 504px;">
<div id="div1" class="tab-pane">
<div style="overflow: hidden;margin-top: 10px;" >
<table style="width: 100%" border = "1">
<thead><tr>
<th style="padding: 0px;width: 0px;visibility: hidden"></th>
<th style="padding: 0px;width: 130px;text-align: left">Text1</th>
<th style="padding: 0px;width: 181px;text-align: left">Text2 </th>
<th style="padding: 0px;width: 85px;text-align: left">Text3 </th>
<th style="padding: 0px;width:0.5px "></th>
<th style="padding: 0px;text-align: center;width: 70px">Text5</th>
</tr>
</thead>
</table>
</div>
<div style="overflow: auto;height: 50px;" class="tab-pane">
<table id ="tblSysDetails" style="width: 100%;float: left" border ="1">
<tbody >
<tr >
<td style="padding: 0px;width: 0px;visibility: hidden" ></td>
<td style="padding: 0px;width: 130px;text-align: left" >BBB</td>
<td style="padding: 0px;width: 181px;text-align: left" >CCC</td>
<td style="padding: 0px;width: 85px;text-align: left" >DDD</td>
<td style="padding: 0px;width: 0.5px"></td>
<td style="padding: 0px;text-align: center;width: 70px" >XXX</td></tr>
</tbody>
</table>
</div>
</div>
<table style="width: 95%" id="tblCountSysTableChanges">
<tr><td style="font-weight: bold;text-align: right">456 </td></tr>
</table>
<div id="div2" class="tab-pane">
<table>
<tr>
<td>AAAAAAAAA</td>
</tr>
</table>
</div>
</div>
</div>
Here are my fiddles
.1 This one is without vertical scroll bar
2. This is with vertical scroll bar . This second fiddle is shifting columns.
Can someone tell why and how to avoid it?
The why is because there is not enough room within the parent for the scrollbar to fit, thus it shrinks the other elements a little to make room
The only way I know to avoid it without changing the scrollbar would be to hide the scrollbar unless the tbody is hovered, like this. This uses overflow:hidden on the tbody unless it is hovered, then it changes to overflow-y:scroll (which doesn't affect positioning or width of the elements when toggled like this)
Following is my added CSS (mostly just the inline stuff moved into an external CSS file), you can look at the jsFiddle for the updated HTML
th, td {
padding:0px;
margin:0px;
text-align:left;
}
th:nth-child(1), td:nth-child(1) {
width:0px;
visibility:hidden;
}
th:nth-child(2), td:nth-child(2) {
width: 130px;
}
th:nth-child(3), td:nth-child(3) {
width:181px;
}
th:nth-child(4), td:nth-child(4) {
width:85px;
}
th:nth-child(5), td:nth-child(5) {
width:.5px;
}
th:nth-child(6), td:nth-child(6) {
width:70px;
text-align:center;
}
tbody {
overflow:hidden;
}
tbody:hover {
overflow-y: scroll;
}
thead > tr, tbody{
display:block;
}
The approach was found in this SO post, another option would be to create a custom scrollbar but that requires a bit of javascript to do as the top answer on that question says
I am not quite sure why you used two tables... Probably to keep the head in place... But I put them both together and used the approach described here (found by a simple Google search) to fix it
With that being said, there are some other CSS basics that you really need to pick up. Following is a list of some and reasons why
Use classes and other generic selectors It saves time, is better structured, and is easier to follow than inline CSS
Tidy up your code! When I first looked at your jsFiddle the spacing was off a lot which makes it hard to follow and read. jsFiddle even has a "TidyUp" Button; Use it!
Know what something does when you put it in your code If you use padding, know what padding does. If you use IDs, know the reason why. The same goes for javascript or any other language you are using. It allows you to find the root of the problems you're having, avoid errors in the first place, and use things the way that they are supposed to be used
If you think there could be a better way to do something, look for it If you're tired of writing the same 5 styles for a block of elements, there probably is something that allows you to apply the 5 styles in only 1 line (a class). This is just an example, but the principle applies to anything. If you've thought of it, most likely someone else has too
Avoid inline CSS as much as possible It makes finding and fixing problems difficult, especially when you have lots of elements styled the same way. It also overrides non-inline CSS which can cause a whole lot of problems if you're not careful
DON'T REPEAT IDS It took me around 10 minutes to fix a formatting error because I didn't realize you repeated the ID tblCountSysTableChanges twice. It causes all sorts of errors and is illegal markup
I hope you learned some things and keep them in mind! Cheers! (:
Related
I'm populating a large amount of text within td. I am trying to wrap the text with td if the text content takes up enough space, but the text keeps breaking out of the table.
td.noBorder {
border: none;
}
.alignTable {
border-collapse: collapse;
background: #f4f4f4;
padding-left: 10px;
text-align: center;
font: normal 13px Calibri;
color: #5a5a5a;
}
table tr td {
height: 30px;
border: solid 1px #cbd0d2;
}
<div style="margin:0 auto;">
<div style="width:730px; margin:0 auto;">
<h1 style="height:20px;font:normal 18px Calibri;color:#010101;font-weight:600;border-collapse: collapse; margin-left:20px"> Related Links </h1>
<div style="width:730px; margin:0 auto;">
<h2 style="padding-left:23px;"> Header </h2>
<table border="1" width="100%" cellpadding="0" cellspacing="0" class="alignTable" >
<tr>
<td class="noBorder" style="text-align: left;padding-left: 23px;"><!-- #06999c -->
<img src="images/arrow.png" width="5" height="10" alt="" /> <a style="padding-left: 8px;" href="{$hyperlink}" target="_blank"> LARGE TEXT </a></td>
<td class="noBorder"/>
<td class="noBorder"/>
</tr>
</table>
</xsl:for-each>
</div>
</div>
</div>
Solution 1: Make It Scrollable
You can make the td automatically scrollable if the content exceeds its regular size by setting its overflow property to auto. If you expect that the td will usually overflow its boundaries, you could also pass overflow: scroll so that it always renders with a scrollbar. Check out the MDN article if you decide to go that route.
Solution 2: Flexbox
Within the td, you could add a div and give it display: flex. Doing this would allow you to apply styles solely to that div without breaking outside of the table. This goes against the cascading principle of CSS, but should be a convenient workaround if that's all you need.
If you're unfamiliar with flexbox styles, Chris Coyier does a good job of explaining them. Flexbox is supported by nearly all modern browsers, and can be coaxed to work with IE9 and 10 if you apply vendor prefixes.
Suggestion: Refactor Your Markup
Just so you're aware, using a table-based layout is no longer a recommended way to structure most websites. If it's at all possible to refactor this into div's, doing so will keep your stylesheets organized and manageable.
You have several possibilities, one to add vertical scroll if text exceeds the margin, one to adjust the font size to fit the text inside, you should see what fits best in your page. If you create a snippet here I can help you more precise!
O have a polyfill for IE7 that transforms display:table into actual tables and I'm using IE7.js (IE9.js file).
Both are working wonderfully and both are doing a great job allowing us devs to think less on IE7.
This is what I have (join of main sheet and IE7 specific sheet):
/*IE7*/
.sideBySide{
display:table;
}
.sideBySide > *{
display:table-cell;
}
/*MAIN*/
.A{
margin-left: 20px;
}
<li>
<div class="sideBySide">
<img class="img" src="img">
<div class="sideBySide">
<div class="A">Info A</div>
<div class="A">Info B</div>
</div>
<div>OK</div>
</div>
</li>
This is what the polyfills generate:
<style>
........ .A{
/* CSS that overrides and invalidates what was set for A */
}
.newClassA{
margin-left: 20px;
}
.newClassA > /*etc*/{
/* All properties relative to class A */
}
</style>
<li>
<div class="sideBySide">
<img class="img" src="img">
<table>
<tbody>
<tr>
<td class="newClassA">Info A</td>
<td class="newClassA">Info B</td>
</tr>
</tbody>
</table>
<div>OK</div>
</div>
</li>
The <style> tag is placed as the last one in the <head>.
In order to deal with this, I made this:
.sideBySide > * > * > td{
padding-left: expression(this.currentStyle['marginLeft']);
}
Unfortunately, it didn't work. Although the CSS clearly gives that it should have a marginLeft of 20px, instead, it is returning auto... So padding-left becomes auto.
Is there a way to seamlessly polyfill this? No one here minds if it requires a substantial amount of computation as long as the browser doesn't hang because of it.
One main thing I want this to follow that this is supposed to be reusable parts. If I set the CSS either in the stylesheet or inline for the other browsers, IE7 must follow it too.
NOTE:
I can tell that those two are working exactly as specified here and it is not a bug on any of them. My issue is that working as specified doesn't help for this specific use-case.
No matter how much I want to ditch IE7... And even IE8, the contractor wants us to support it for some more years.
Would this help?
css
.sideBySide table {
border-collapse:separate;
}
html
<div class="sideBySide">
<img class="img" src="img">
<table>
<tbody>
<tr>
<td class="newClassA">Info A</td>
<td class="newClassA">Info B</td>
</tr>
</tbody>
</table>
<div>OK</div>
</div>
I recently applied a hover feature to a set of buttons. When applied to a different website the coding was fine. When applied to this site the link/hotspot goes to the next button. For example: I have buttons home/about/gallery/blog/prints/contact and you would think with the dimensions set in CSS style sheet that the link would only apply to those dimensions. Not with this one. The link/hotspot shows linked to index.shtml from the edge of the table to the other side of the home button. There are spaces between buttons but the link/hotspot goes 50%across the space until it hits the next buttons link/hotspot. And the final button "contact" spans across to the opposite edge of the table. Any clues as to what I am doing wrong?
CSS:
div.nav-home {
margin-top: 10px;
margin-bottom: 0px;
margin-left: 130px;
Margin-right: -60px;
background-position: right top;
background-repeat: no-repeat;
width: 75px;
height: 64px;
}
#home {
background-image: url('img/home.png');
}
#home:hover {
background-image: url('img/home_hover.png');
}
Index.shtml:
<table width="1213" height="64" align="center" background="img/tablebg2.png">
<!--#include file="menubuttons.html" -->
menubuttons.html:
<tr>
<td align="center" width="75">
</div>
</td>
<td align="center" width="86">
</div>
</td>
<td align="center" width="94">
<a href="/gallery.shtml" title="GALLERY" ><div id="gallery" class="nav-gallery">
</div></a>
</td>
<td align="center" width="63">
</div>
</td>
<td align="center" width="85">
<a href="/prints.shtml" title="PRINTS" ><div id="prints" class="nav-prints">
</div></a>
</td>
<td align="center" width="103">
<a href="/contact.shtml" title="CONTACT" ><div id="contact" class="nav-contact">
</div></a>
</td>
</tr>
FIXED: (maybe not properly?)
I have only been coding for 2 months and have a pretty good idea on how to write it out, but I don't know what everything means such as the DIV tag. I know I was searching on here last night and I assumed I was to put the div inside a TD.
I was able to fix everything by simply adding a few spacer.png's before the first button in between each set of buttons and after the last button. This also fixed my spacing issues on the sides.
Thanks for the help. I simply am trying to find an easy way to make my buttons change on hover. This method was the first I found last night on here and am now trying to perfect it.. well in my head at least. I need to research on the unordered list a little because I have heard that that makes things more simple...
Here is the link(based off the back end of a site I recently finished) www.blackmarkettattoos.com/amysesco/index.shtml
I think the problem is the fact that you are using DIV, which is a container tag inside table's cell, and for both you apply style (to the DIV as class and to the TD as inline).
Generally, it is better to create menus with lists, but if you must use the code you provided, then try to remove width: 75px; from the div.nav-home.
Check these two links for how to create CSS menus with lists:
css.maxdesign.com.au
Dynamic Drive CSS Library
I can't get over what appears to be a simple CSS formatting problem in Chrome: I want to put a table towards the right, and a label and some buttons toward the left, inside the same paragraph. This works easy enough in other browsers (Firefox, IE7 & 8), but in Chrome the table stretches over the entire page, under the label.
HTML:
<div class="formrow">
<label> </label>
<div style="display: inline; width: 208px; ">
<table id="tbl_Index" class="grid" style="display: inline; width: 208px; table-layout: fixed;">
<thead>
<tr class="">
<th style="width: 50px;"></th>
<th style="width: 150px;" class=""></th>
</tr>
</thead>
<tbody>
<tr id="1" class="">
<td style="width: 50px;"></td>
<td style="width: 150px;"></td>
</tr>
<!-- etc... -->
</tbody>
</table>
</div>
</div>
Thing is, I've tried just about any trick I found to get the table limited at 200px:
I tried assigning table-layout: fixed, which, in conjunction with width, should have limited my table to 208px;
I tried wrapping the table in a div and setting the div inline, to limit the table this way
I tried styling the grid with display: inline; and then setting max-width: 208px; (you might know that max-width only applies to inline or block, and table is neither of those.)
What's really annoying for me is that if I go in the console and try to get width for the table, it does tell me 208; but when I look in the compiled properties for the table, it displays 0px;
Add to the table's style: float:right; and you want to use inline-block and not inline this should do the trick
You can try to use this css above:
div.formrow { clear:left; }
div.formrow label { float:left; }
div.formrow tabel { width:208px; border-collapse:collapse; display:inline-block; }
I use Drupal 6 with theme summertime. Also I use FCKeditor. In order to align content I wanted to create a table with invisible borders. First I tried FCKEditor table properties and I gave 0 to border size in order to make borders invisible. But it did not work. I looked up the source and non working code was like below (Why giving border="0" did not work?) :
<table width="468" cellspacing="0" cellpadding="0" border="0" style="width: 468px; height: 201px;">
<tbody>
<tr>
<td>
<h2 class="rtecenter"><strong>Content </strong></h2>
</td>
<td><img src="/sites/mydomain.com/files/sample.jpg" alt="" /></td>
</tr>
</tbody>
</table>
Then I tried:
<table width="468" cellspacing="0" cellpadding="0" style="border: medium hidden ; width: 468px; height: 201px;">
Table borders are now invisible but cell borders are still visible. How can I make it totally invisible. Thanks.
The border attribute should be specified on the cell level, eg <td style="border: 0;">. Of course, this should be made in CSS using:
table td { border: 0; }
But I see that in your case that might be difficult.
It should be done like this:
<table width="468" cellspacing="0" cellpadding="0" border="0" style="width: 468px; height: 201px;">
<tbody>
<tr>
<td style="border: 0">
<h2 class="rtecenter"><strong>Content </strong></h2>
</td>
<td style="border: 0"><img src="/sites/mydomain.com/files/sample.jpg" alt="" /></td>
</tr>
</tbody>
There are probably borders set in the CSS. Drupal core's system.css sets some borders on table headers and body that can be a pain to override.
You can add a custom CSS file to the theme so you avoid editing its CSS directly. Simply add the path to your added .css file in the theme's .info file.
Then try adding:
tbody,
thead,
thead th,
tr.even,
tr.odd {
border: 0;
}
Don't forget to turn off CSS aggregation and clear your cache.
I just happened upon this while searching for something else. This is old, but thought I'd comment anyway. Someone else might find it helpful.
Rather than do a few of the things mentioned above, it would be simpler to just add a specific ID or CLASS name to the table itself, then you could specify settings just for that table in the CSS.
HTML:
<table .... id="exampleclass">
CSS:
#exampleclass tbody,
#exampleclass thead,
#exampleclass th {
border: 0;
}