I am trying to work with CSS and containers without success, I would like if someone helps:
I am trying to do as the specified with the following code, the table is okay is fulfilled the 100% of the 40% of body Container1 DIV, the problem is with the rows and the columns, they don't follow the specification.
<div id="CamadaSuperior" >
<table id="tabela">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</div>
<div id="CamadaDoMeio" >
CamadaDoMeio
</div>
<div id="CamadaInferior" >
<table class="TabelaDaCamadaInferior" border="1">
<tr><td>Esquerda</td><td>Meio</td><td> Direita</td></tr>
</table>
</div>
<div id="CamadaRodape" >
</div>
</body>
My CSS is this:
html, body{
height: 100%;
margin:0;
padding:0;
}
div{
border:1px solid black;
padding:0;
}
#CamadaSuperior
{
height: 40%;
}
#CamadaDoMeio
{
height: 10%;
}
#CamadaInferior
{
height: 40%;
padding:0;
}
#CamadaRodape
{
height: 10%;
padding:0;
}
#tabela{
height:100%;
table-layout: fixed;
border-width:1px;
}
#tabela tr{
width:50%;
height:100%;
border-width:1px;
}
#tabela tr td{
width:100%;
height:16.7%;
}
.TabelaDaCamadaInferior
{
height: 100%;
width: 100%
}
.TabelaDaCamadaInferior tr td
{
width:33%;
}
But this is what is happening with table row:
TD tag does not work as well:
Well the short answer is to make use of a CSS framework like bootstrap, it can be used in an eclipse environment and just attach the classes you need in order to get it to position correctly. Check the link here https://www.texniq.de/en/web-engineering-i/create-first-bootstrap-project
The long answer is that you need to style each td & tr with a class that has the width and height that you want. You'll also need to adjust the font-size accordingly so that the text in each cell will fit properly. Right now the table has some css applied but the tags within it are using their default values.
Related
For example I have this CSS rule:
.dataList table {
width: 100%;
}
.dataList table.onlyThisTables {
width: 400px;
}
<div class="dataList">
<table>
<tr>
<td>
Content of this table
<table class="onlyThisTables">
<tr>
<td>Content of this table
<td>
</tr>
</table>
</td>
</tr>
</table>
</div>
But always get width:100%; in all tables, I want to affect with 400px width for .onlyThisTables class, How can I do it?
This depends on your html structure. Could you put an example of the html code?
Probably the answer is:
.dataList table {
width:100%;
}
.onlyThisTables {
width:400px;
}
UPDATED:
To solve your updated question you can use !important suffix:
.dataList table {
width: 100%;
}
.dataList .onlyThisTables {
width: 400px !important;
}
Here is an example: https://jsfiddle.net/Lksv4dnd/
You need to specify a max-width in your styles:
.dataList table {
width: 100%;
}
.dataList table.onlyThisTables {
width: 400px;
max-width: 400px;
}
I read this article: How to make a vertical line in HTML
but the height style didn't work for <th> tags
My CSS is like this:
.verticalLine
{
width: 1px;
background-color: Black;
height: 10px;
}
My HTML is this:
<th class="verticalLine"></th>
Unfortunately, the vertical line spans the whole border. I have tried percentages instead of pixels, to no avail.
Edited
.navCenter
{
text-align:center;
display:table-cell;
}
<nav style="margin-left:auto; margin-right:auto; width: 70%; height:55px;">
<table>
<tr class="navCenter">
<th><h2><img src="Pictures/BartleHallToppers.jpg" height="42px" width="100px"/></h2></th>
<th class="verticalLine"></th>
<th><h2>Events</h2></th>
<th><h2>Restaurants</h2></th>
<th><h2>Hotels</h2></th>
<th><h2>Points of Interest</h2></th>
<th><h2>Public Works</h2></th>
<th><h2>Road Construction</h2></th>
<th><h2>Contact Us</h2></th>
</tr>
</table>
</nav>
using tables is not a good practice for creating a navigation
you can ul li and for border pseudo
JS Fiddle
li:not(:last-child):after {
content:"|";
position:absolute;
right:0;
top:0;
}
or
li:not(:last-child):after {
content:" ";
width:1px;
position:absolute;
border-right:1px solid;
right:0;
top:0;
bottom:0;
}
Using tables for creating nav menu is not a best practic, but your code must works, if you put th into table:
.verticalLine
{
width: 1px;
background-color: Black;
height: 10px;
}
<table>
<th class="verticalLine"></th>
</table>
`
I'm floating two divs side by side. I can't set the properties for the left div as they seem to be inherited from the right div. I'm guessing I"m just overlooking something here, but what do I need to do so I they aren't inherited?
div.main - content {
width: 1500 px;
}
div.left {
float: left;
width: 300 px;
overflow: hidden;
background - color: #ffffff;
}
table.;
left {
border - collapse: collapse;
width: 300 px;
}
table.left, td {
border: 1 px hidden black;
padding: 5 px;
background - color: #ffffff;
color: #000000;
}
div.right {
float:right;
width:1200px;
overflow:hidden;
}
table.right {
border-collapse:collapse;
width:765px;
}
table.right, th {
border: 1px solid black;
padding:5px;
background-color:# df1e37;
color: #ffffff;
}
table.right, td {
border: 1 px dotted# cccccc;
padding: 5 px;
background - color: #ffffff;
color: #000000;
}
<div class="main-content">
<div class="left">
<table class="left">
<tr>
<td>Left content here</td>
</tr>
</table>
</div>
<div class="right">
<table class=right>
<tr>
<td>Right content here</td>
</tr>
</table>
</div>
</div>
table.;left should be table.left, for starters. Also, as #3rror404 points out, the comma in your selectors may not mean what you think:
table.left, td
means "a table element with class left, and also td elements", whereas
table.left td
means "a table element's children tds".
After the semicolon change, though, things look OK for me. A possible change you may consider is not putting classes on the tables:
<div class="left">
<table>
<tr><td>Left content here</td></tr>
</table>
</div>
and accessing them this way:
div.left table { ... }
or
div.left > table { ... }
...which IMO would eliminate a possible source of future confusion.
There were a few typo in your code
table.;left => .left table
and a few more similar to that... here is the new snippet
div.main-content {
width:1500px;
}
.left {
float:left;
width:500px;
overflow:hidden;
background-color:rgba(123,123,123,0.1);
}
.left table {
background-color: #feade2;
border-collapse:collapse;
width:300px;
}
.left table td {
color:#000000;
}
.right {
float:right;
width:1000px;
overflow:hidden;
background-color:rgba(200,200,200,0.3);
}
.right table {
border-collapse:collapse;
width:765px;
}
.right table th {
border: 1px solid black;
padding:5px;
color:#ffffff;
}
.right table td {
background-color:blue;
color:red;
}
<div class="main-content">
<div class="left">
<table>
<tr><td>Left content here</td></tr>
</table>
</div>
<div class="right">
<table>
<tr><td>Right content here</td></tr>
</table>
</div>
</div>
I added some colors to differentiate various boundaries... you can change the css the way you want it.
you also dont need div.left or div.right . Just use .left or .right and just specify the class on the div...the table will inherit the classes of the div. Hope this helps
Sorry for my bad English, I hope you're going to understand what I want to say...
I'm trying to implement an HTML table which support scrolling of table bodies independently of the table head.
I found the following question which helped me a lot :
How to scroll table's "tbody" independent of "thead"?
I tested the following code, it works on Chrome (22), Firefox (16) and Opera (12) without issue :
HTML :
<table>
<thead>
<tr>
<th>Title1</th>
<th>Title2</th>
<!-- ... -->
</tr>
</thead>
<tbody>
<tr>
<td>...</td>
<td>...</td>
<!-- ... -->
</tr>
<!-- ... -->
</tbody>
</table>
CSS :
thead, tbody {
display: block;
}
tbody {
height:500px;
overflow-y:auto;
overflow-x:hidden;
}
thead {
line-height: 20px;
}
So it works on the main browsers except IE 9, on IE, I have some issues :
The tbody's height is not defined (so I don't have any scrollbar)
Each has an height of 500px (the tbody's height on other browsers)
The two following examples have exactly the same issues : http://jsfiddle.net/nyCKE/2/ , http://www.imaputz.com/cssStuff/bigFourVersion.html
I saw the following question (and answer) but it doesn't help me : IE9 + css : problem with fixed header table
So I'm sure that the bug comes from IE but I don't have any idea how to fix it without change my HTML structure.
Have someone any idea ?
I have slightly tried to fix it. Hope it gives some idea
HTML
<div class="wrap">
<div class="inner">
<table>
<thead><tr>
<th><p>Problem</p></th>
<th><p>Solution</p></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
CSS
p {margin:0 0 1em}
table p {margin :0}
.wrap {
margin:50px 0 0 2%;
float:left;
position:relative;
height:200px;
overflow:hidden;
padding:25px 0 0;
border:1px solid #000;
width:150px
}
.inner {
padding:0 ;
height:200px;
overflow:auto;
}
table { margin:0 0 0 -1px; border-collapse:collapse; width:130px}
td {
padding:5px;
border:1px solid #000;
text-align:center;
}
thead th {
font-weight:bold;
text-align:center;
border:1px solid #000;
padding:0 ;
color:#000;
}
thead th {border:none;}
thead tr p { position:absolute; top:0; }
.last { padding-right:15px!important; }
Demo http://jsfiddle.net/nyCKE/272/
Here is a shorter answer that allows you to scroll the table with a fixed header in ie9.
Add a conditional div around the table
<!--[if lte IE 9]>
<div class="old_ie_wrapper">
<!--<![endif]-->
<table>
...
<!--[if lte IE 9]>
</div>
<!--<![endif]-->
Add the following styles for ie9
.old_ie_wrapper {
height: 500px;
overflow: auto;
}
.old_ie_wrapper tbody {
height: auto;
}
.old_ie_wrapper thead tr {
position: absolute;
}
.old_ie_wrapper tbody tr:first-child {
height: 67px;
vertical-align: bottom;
}
You will have to adjust the heights and probably other properties based on your table.
I have a table of data and each cell is a link. I want to allow the user to click anywhere in the table cell and have them follow the link. Sometimes the table cells are more than one line but not always. I use td a {display: block} to get the link to cover most of the cell. When there is one cell in a row that is two lines and the others are only one line the one liners don't fill the entire vertical space of the table row. Here is the sample HTML and you can see it in action here http://www.jsfiddle.net/RXHuE/:
<head>
<style type="text/css">
td {width: 200px}
td a {display: block; height:100%; width:100%;}
td a:hover {background-color: yellow;}
</style>
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<td>
<a href="http://www.google.com/">Cell 1<br>
second line</a>
</td>
<td>
Cell 2
</td>
<td>
Cell 3
</td>
<td>
Cell 4
</td>
</tr>
</tbody>
</table>
</body>
Set an arbitrarily large negative margin and equal padding on the block element and overflow hidden on the parent.
td {
overflow: hidden;
}
td a {
display: block;
margin: -10em;
padding: 10em;
}
http://jsfiddle.net/RXHuE/213/
You need a small change in your CSS. Making td height:100%; works for IE 8 and FF 3.6, but it doesn't work for Chrome.
td {
width: 200px;
border: solid 1px green;
height: 100%
}
td a {
display: block;
height:100%;
width:100%;
}
But making height to 50px works for Chrome in addition to IE and FF
td {
width: 200px;
border: solid 1px green;
height: 50px
}
td a {
display: block;
height:100%;
width:100%;
}
Edit:
You have given the solution yourself in another post here; which is to use display: inline-block;.
This works when combined with my solution for Chrome, FF3.6, IE8
td {
width: 200px;
border: solid 1px green;
height: 100%}
td a {
display: inline-block;
height:100%;
width:100%;
}
Update
The following code is working for me in IE8, FF3.6 and chrome.
CSS
td {
width: 200px;
border: solid 1px green;
height: 100%;
}
td a {
display: inline-block;
height:100%;
width:100%;
}
td a:hover {
background-color: yellow;
}
HTML
<table>
<tbody>
<tr>
<td>
<a href="http://www.google.com/">Cell 1<br>
second line</a>
</td>
<td>
Cell 2
</td>
<td>
Cell 3
</td>
<td>
Cell 4
</td>
</tr>
</tbody>
</table>
The example lays here
Little late to the party, but there's a nice solution I just discovered.
You can use a combination of relative and absolute positioned elements, along with a pseudo element to get the effect you're looking for. No extra markup needed!
Change the table cell (<td>), to be position: relative;, and create a ::before or ::after pseudo element on the <a> tag, and set it to position: absolute;, and also use top: 0; left: 0; right: 0; bottom: 0;.
Because the pseudo element is attached to the anchor tag, and you're telling it to take up the entire table cell, it will force the anchor tag to be at least that size, whilst not affecting the actual content of the anchor tag itself (thereby retaining its vertically centered alignment).
For example
table {
border-collapse: collapse;
table-layout: fixed;
}
td {
position: relative;
width: 200px;
padding: 0.5em 1em;
border: 2px solid red;
background-color: lime;
}
td a {
/* FONT STYLES HERE */
text-decoration: none;
}
td a::after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 0;
}
<table>
<tbody>
<tr>
<td>
<a href="http://www.google.com/">Cell 1<br>
second line</a>
</td>
<td>
Cell 2
</td>
<td>
Cell 3
</td>
<td>
Cell 4
</td>
</tr>
<tr>
<td>
Cell 5
</td>
<td>
<a href="http://www.google.com/">Cell 6<br>
second line</a>
</td>
</tr>
</tbody>
</table>
Hope this helps!
Following hack works [Tested on Chrome / Firefox / Safari]
Have the same padding for td and anchor elements. And for anchor also have margin which is equal to -ve of padding value.
HTML
<table>
<tr>
<td><a>Hello</a></td>
</tr>
</table>
CSS:
td {
background-color: yellow;
padding: 10px;
}
a {
cursor:pointer;
display:block;
padding: 10px;
margin: -10px;
}
Working Fiddle :http://jsfiddle.net/JasYz/
Try display: block:
td a {display: block; height:100%;}
[EDIT] WTF ... I can confirm this doesn't work in FF 4 and Chrome. This works:
td a {display: block; height: 2.5em; border: 1px solid red;}
That suggests that height:100%; isn't defined in a table cell. Maybe this is because the cell gets its size from the content (so the content can't say "tell me your size" because that would lead to a loop). It doesn't even work if you set a height for the cells like so:
td {width: 200px; height: 3em; padding: 0px}
Again the code above will fail. So my suggestion is to use a defined height for the links (you can omit the width; that is 100% by default for block elements).
[EDIT2] I've clicked through a hundred examples at http://www.cssplay.co.uk/menus/ but none of them mix single line and multi-line cells. Seems like you hit a blind spot.
I will post the same answer here, as I did on my own question.
Inspired by Jannis M's answer, I did the following:
$(document).ready(function(){
$('table tr').each(function(){
var $row = $(this);
var height = $row.height();
$row.find('a').css('height', height).append(' ');
});
});
I added a since empty links (not containing text nodes) can not be styled(?).
See my updated fiddle.
Only problem here is that using display: block forces the browser to ignore the vertical align: center...
oops.
I jury rigged it to look right for one cell with height:60 and a font that occupied 20 pixels by adding a br... Then I realized that I had some items with 2-line text. Dang.
I ended up using the javascript. The javascript doesn't give the nice mousey pointy clicker thing, but the line of text does, so it will actually trigger a visual response, just not where I want it to... Then the Javascript will catch all the clicks that 'miss' the actual href.
Maybe not the most elegant solution, but it works well enough for now.
Now if I could only figure out how to do this the right way....
Any ideas on how to add the mouse icon change to a hand for the area covered by the onclick? Right now, the click to page works, but the icon only changes when it hits the href which only affects the text.
Why don't you just get rid of the <a> altogheter and add an onClick to the <td> directly?
<head>
<style type="text/css">
td {
text-align:center;
}
td:hover {
cursor:pointer;
color:#F00;
}
</style>
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<td onclick="location.href='http://www.google.com/';">Cell 1<br />second line</td>
<td onclick="location.href='http://www.google.com/';">Cell 2</a></td>
<td onclick="location.href='http://www.google.com/';">Cell 3</td>
<td onclick="location.href='www.google.com';">Cell 4</td>
</tr>
</tbody>
</table>
This way you cut out the middle man.
PS: i know this was asked and answered many years ago, but none of the answers above solved the problem in my case. Hope this helps someone.
For me the only solution is to replace <table> <tr> with <div>s and style them using display:table and display:table-row accordingly.
Then you can replace <td> with just <a> and style it with display:table-cell.
Work perfectly even on varying heights of <td> contents.
so original html without anchors:
<table>
<tr>
<td>content1<br>another_line</td>
<td>content2</td>
</tr>
</table>
now becomes:
a:hover
{
background-color:#ccc;
}
<div style="display:table; width:100%">
<div style="display:table-row">
content1<br>another_line
content2
</div>
</div>
I have used this solution: works better then the rest in my case.
CSS:
.blocktd {width: 100%; height: 100%; padding: 0px; overflow: hidden}
a.blocktd {margin: 0em; padding: 50px 20px 50px 20px; display: block;}
a.blocktd:hover {border: 4px solid #70AEE8; border-radius: 10px; padding: 46px 16px 46px 16px; transition: 0.2s;}
And in HTML: ...