My html markup is:
<table>
<tbody>
<tr>
<td><span class="test">This is span.</span></td>
</tr>
</tbody>
css is:
.test{
font-size : 12px;
}
My span element take a height of 12px. So td should also have a height of 12px. But if I inspect in chrome developers tool, td has a height of 21px. Where is 9px coming from? How to get rid of it? Here is my code pen
set span to display:block
.test{
font-size : 12px;
display:block;
background : rgba(255,0,0,.5);
}
for removing default margin and padding of all elements use this
*{
margin:0;
padding:0;
}
* {
margin: 0;
padding: 0;
}
td {
background: black;
padding: 0;
margin: 0;
}
.test {
font-size: 12px;
display: block;
background: rgba(255, 0, 0, .5);
}
<table>
<tbody>
<tr>
<td><span class="test">This is span.</span>
</td>
</tr>
</tbody>
</table>
Edit
the issue is because of inline-block one fix is adding font-size:0; to parent removes the white-space
demo - http://jsfiddle.net/s4ufsbd3/
td {
background: black;
padding: 0;
margin: 0;
font-size:0;
}
* {
margin: 0;
padding: 0;
}
td {
background: black;
padding: 0;
margin: 0;
font-size: 0;
}
.test {
font-size: 12px;
display: inline-block;
background: rgba(255, 0, 0, .5);
}
<table>
<tbody>
<tr>
<td><span class="test">This is span.</span><span class="test">This is span.</span>
<span class="test">This is span.</span>
<span class="test">This is span.</span>
</td>
</tr>
</tbody>
</table>
Vitorino Fernandes solution does work, but you will have issues when you have text inside td since font size : 0px;.
<table>
<tbody>
<tr>
<td>SOME TEXT HERE<span class="test">This is span.</span></td>
</tr>
</tbody>
</table>
Here's my css to fix that issue.
td{
line-height : 0;
}
.test{
font-size : 12px;
display:inline-block;
background : rgba(255,0,0,.5);
line-height : 1;
}
Just add this style to td and check style="line-height : 0;"
As suggested, the line-height is the cause of this space. Also, others suggestions may works as well, but with this you can also adjust the height over and/or bellow the text to your taste using "margin".
HTML
<table>
<tbody>
<tr>
<td><p>This is a paragraph. This paragraph is looooooooooooooooong and wants overlap.</p></td>
</tr>
</tbody>
</table>
CSS
table {
border-collapse: collapse; /*only if you don't want border space between the cells*/
}
td {
font-size:12px;
padding: 0;
margin: 0;
line-height:0;
}
p {
display:block;
line-height: 1em;
margin-top: 0px; /*adjust to your necessities*/
margin-bottom: 0px; /*adjust to your necessities*/
}
Related
I am working on my website and I have most of the design worked out, shown in the first image. I am trying to make the header row have no space (more accurately, make it look that way by having the image span across the entire row with no spaces.), but still have the elements themselves have space in between them.
Image showing a joined header, but separate body elements:
I am aware of the border-spacing css style, but it has to be applied to the table element, which means it will apply to headers and body elements. This with with a border-spacing set
Image showing what happens to the images when the border-spacing is set on the table:
I did attempt to find an answer before posting and usually I find the answer fairly quickly, but this one seems to be a rare request. I prefer to avoid hacks if possible, but I will use them if its the only way. Also, if possible, I'd like it to be cross-browser capable. (changes to the solution are ok of course, just something that I can make work will all of them.)
I guess code is helpful to show. Here is the html:
<table id="users">
<caption>Point Totals</caption>
<thead>
<tr>
<th>Name</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<tr>
<td>Xogue</td>
<td>64433</td>
</tr>
<tr>
<td>Jesse</td>
<td>104040</td>
</tr>
<tr>
<td>Nanokarp</td>
<td>280</td>
</tr>
<tr>
<td>Brandon</td>
<td>70</td>
</tr>
</tbody>
</body>
and the css:
#users {
border-spacing: 6px;
width: 444px;
float: left;
margin: 20px 90px;
}
#users caption {
background-image: url("_images/points_label.png");
background-size: 200px 35px;
background-position: center center;
background-repeat: no-repeat;
height: 31px;
font-size: 20px;
padding-top: 8px;
}
#users thead {
background-image: url("_images/point_tr_head_back.png");
background-repeat: no-repeat;
}
#users th {
text-align: left;
padding: 9px 30px;
font-size: 20px;
}
#users td {
border: 2px solid #226fdb;
border-radius: 25px;
font-size: 20px;
padding: 18px 5px 2px 25px;
line-height: 15px;
background: #FFFFFFEE;
}
Note: Some of the styles used are likely unnecessary. I've been toying with it for a while and haven't cleaned it up yet.
SOLVED: further down if you would like to see the example. but put simply, wrap the content in a different element (like a span) and move all styles to the new element.
I think you could get there fairly easily with some margins and padding if you can wrap the cell contents in a span (or whatever).
table {
text-align: left;
border-spacing: 0;
}
thead tr {
box-shadow: inset 0 0 12px rgba(0,0,0,0.5);
border-radius: 24px;
}
th {
padding: 6px 1em;
}
th:first-child {
border-radius: 24px 0 0 24px;
}
th:last-child {
border-radius: 0 24px 24px 0;
}
tbody td > span {
display: block;
border: 2px solid blue;
background: aliceblue;
border-radius: 24px;
margin: 6px 6px 0 0;
padding: 0.25em 1em;
}
<table>
<thead>
<tr>
<th>Name</th>
<th>Points</th>
</thead>
<tbody>
<tr>
<td><span>Xogue</span></td>
<td><span>262677</span></td>
</tr>
<tr>
<td><span>Jesse</span></td>
<td><span>17632</span></td>
</tr>
<tr>
<td><span>Nanokarp</span></td>
<td><span>12344</span></td>
</tr>
</tbody>
</table>
One option is to add padding to your CSS for td only and keep rest of the attributes same among td and th as below, also if you can share the used code snippet someone can help better:
td {
padding: 5px;
}
I am trying to add cell spacing to a html table.
I want to add spacing between cells without the outer spacing.
My problem is, that the cellspacing html attribute and border-spacing CSS property adds spacing outside too.
I would like to put cell spacing without the red (outer) part - only the yellow one.
Is it possible?
Edit:
The image was drawn by hand (MS-Paint) only for illustration.
The coloring is for debugging - so that one can see where the borders, and spacing is.
I have found a roundabout solution including some additional div-s:
.inner-spacing {
border-collapse: collapse;
background-color: yellow;
border: 2px solid black;
}
.inner-spacing td {
padding: 0;
}
.inner-spacing td > div {
width: 60px;
height: 60px;
background-color: green;
border: 2px solid black;
margin: 10px;
}
.inner-spacing tr:first-child > td > div {
margin-top: 0px;
}
.inner-spacing tr:last-child > td > div {
margin-bottom: 0px;
}
.inner-spacing tr > td:first-child > div {
margin-left: 0px;
}
.inner-spacing tr > td:last-child > div {
margin-right: 0px;
}
<table class="inner-spacing">
<tr>
<td>
<div/>
</td>
<td>
<div/>
</td>
</tr>
<tr>
<td>
<div/>
</td>
<td>
<div/>
</td>
</tr>
</table>
So to summarize, I would like the table to have border spacing with the table border collapsing onto the cells (no spacing).
I wonder if there are some other solutions - so any new solution is welcome!
This will be tricky a little bit...you will need to set display:block and border-spacing:10px for spacing between cells and same negative margin:-10px to remove the outer spacing
Stack Snippet
table {
font: bold 13px Verdana;
background: black;
margin: 30px auto;
border-spacing: 0;
}
table td {
padding: 30px;
background: red;
color: #fff;
}
table tbody {
margin: -10px;
display: block;
border-spacing: 10px;
}
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
This is kinda tricky, you need to follow something like this:
table, td {border: 1px solid #999; border-collapse: collapse;}
table {margin: -5px;}
table td {width: 32px; height: 32px; margin: 5px;}
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
How can I display my image and the table on the same level? This is really depressing me because I can't get "inline-block" to work. :(
<p id="play">
hey
</p>
<div id="menu">
<table>
<tr>
<td>Models</td>
</tr>
<tr>
<td>Cars</td>
</tr>
<tr>
<td>Modern Houses</td>
</tr>
<tr>
<td>Vacation Spots</td>
</tr>
<tr>
<td>Sports and Outdoors</td>
</tr>
<tr>
<td>Books</td>
</tr>
<tr>
<td>Abandoned Houses</td>
</tr>
<tr>
<td>Summer Wear</td>
</tr>
<tr>
<td>Makeups</td>
</tr>
<tr>
<td id="site">Site Info</td>
</tr>
</table>
</div>
<img src="C:\Users\Elexie\Documents\Downloads\faki2.jpg"/>
body {
background: #181818;
margin: 0;
padding: 0;
}
/* set body display to inline-table*/
#play {
background: black;
color: white;
margin: 0;
padding: 0;
height: 35px;
}
table,td {
color: white;
border: 1px solid white;
border-collapse: collapse;
width: 160px;
padding: 10px;
font-family: ;
}
table {
}
#site {
height: 350px;
}
img {
float: right;
}
I changed the picture, but it's of similar size
http://jsfiddle.net/w6d5g/
In your css code:
table{
float:left;
}
Should do the trick.
Read more: http://www.w3schools.com/css/css_float.asp
Check this fiddle: http://jsfiddle.net/Mohamed_nabil/F8MKp/
/*******Added style******/
img
{
/*165px is your Menu width with borders*/
max-width: calc(100% - 165px);
/*For cross browser*/
-webkit-max-width: calc(100% - 165px);
-moz-max-width: calc(100% - 165px);
-o-max-width: calc(100% - 165px);
-ms-max-width: calc(100% - 165px);
display: inline-block;
vertical-align: top;/* Can be middle, bottom */
}
#menu{
display: inline-block;
}
Firstly, wrap your image tag with a div. Name this div anything you want. Let's name it: "image-test".
<div class="image-test">
<img src="(URL for IMAGE)">
</div>
Next, let's say you want your table to take up 50% of the width and your image to take up the other 50%. We are also going to float these div elements so they are not in the flow of the document.
#menu{
float:left;
width:50%;
}
.image-test{
float:left;
width:50%;
}
You'll notice your image is larger than the containing div, so let's set a max width on all images to avoid future problems.
img {
max-width:100%;
}
I have this:
And I want to get to something like this:
Here is my html:
<table>
<tbody>
<tr>
<td><div class="box">P</div></td>
<td>My First Game</td>
<td>100 / 250 plays</td>
<td>Players</td>
<td>Duplicate</td>
<td>Archive</td>
</tr>
<tr>
<td><div class="box">P</div></td>
<td>The best game ever if it was done.</td>
<td>0 / 250 plays</td>
<td>Players</td>
<td>Duplicate</td>
<td>Archive</td>
</tr>
<tr>
<td><div class="box">P</div></td>
<td>Could be better but ya.</td>
<td>0 / 50 plays</td>
<td>Players</td>
<td>Duplicate</td>
<td>Archive</td>
</tr>
</tbody>
</table>
Here is my css (scss):
table {
border: none;
height: 33px;
padding: 0;
margin: 0;
}
.box {
width: 33px;
height: 33px;
background-color: #5AD427;
text-align: center;
margin: 0;
padding: 0;
}
A fiddle is here: http://jsfiddle.net/MattCamp/dzDm3/
My main concern is how to fix the boxes on the right side of each row. I can't seem to figure out how to format them so they don't have so much space around them and also to make the letter in the middle centered.
demo
<tr>
<td>P</td>
<td>My First Game</td>
<td>100 / 250 plays</td>
<td>Players</td>
<td>Duplicate</td>
<td>Archive</td>
</tr>
table {
width:100%; /**/
padding: 0;
margin: 0;
text-align:right; /**/
border-collapse:separate;
border-spacing: 0 2px;
}
table tr {background:#fff;}
table tr:hover {background:#eff;}
table tr td {padding:5px 8px;}
table tr td:first-child {border-left: 3px solid #fff;}
table tr td:last-child {border-right:3px solid #fff;}
table tr:hover td:first-child {border-left: 3px solid #4EB2E2;}
table tr:hover td:last-child {border-right:3px solid #4EB2E2;}
table tr td:nth-child(1){
color:#fff;
width: 33px;
background-color: #5AD427;
padding: 5px 0;
text-align: center;
}
table tr td:nth-child(2){
text-align:left;
}
Why not remove the div
<table>
<tbody>
<tr>
<td class="box">P</td>
<td>My First Game</td>
and then add vertical-align: middle to the .box css
According to http://css-tricks.com/using-divs-inside-tables/ absolute positioning should work but I'm not sure if I read your question right. Check this site out, it gives a good tutorial and explanation on divs inside tables.
Put the box class on the td cell itself instead of on a div inside the td (remove the div entirely). You're probably fighting cell padding, which is why you have so much whitespace around the box.
Look in to line-height and vertical-align CSS properties for the character positioning inside the box.
See fiddle for example: http://jsfiddle.net/dzDm3/2/
<td class='box'>P</td>
.box {
width: 26px;
height: 26px;
background-color: #5AD427;
text-align: center;
margin: 0;
padding: 0;
line-height: 26px;
}
I want table header with fixed width without using div tag outside table. I need some solution in which i just need to change css file only. i have tried by putting table in side div with style:
width:100%;overflow-x:scroll
and on minimizing the browser's height and width, it is working fine.
But this is not what i want. I want to change in css style only, to avoid change in all the jsp files in my project
PSB my code:
CSS
h3 {
font: bold 1.2em Verdana, Helvetica, Arial, sans-serif;
background: #B7BBD6;
padding: 5px;
margin: 10px 0 0 0;
clear: both;
}
.list {
float: left;
width: 100%;
color: #000099;
border: 1px solid #DEDFDE;
margin: 0 0 15px 0;
overflow-x: scroll
}
.list th, .list td {
vertical-align: top;
border: 1px solid #B7BBD6
}
.even {
background: #F1F1F1
}
/*.odd {background: #F1F1F1}*/
.odd {
background: #FFF
}
HTML
<h3>Test Table</h3>
<table class="list">
<tr>
<th>a</th>
<th>b</th>
<th>c</th>
<th>d</th>
<th>e</th>
<th>f</th>
<th>g</th>
<th>h</th>
<th>i</th>
</tr>
<tr class="odd">
<td>98052826</a></td>
<td>Company</td>
<td>asdfsafdsa</td>
<td>asdfsadf</td>
<td>asdfsafs</td>
<td>sadfsaf</td>
<td>1234</td>
<td>asfsdf</td>
<td>asfsafdf</td>
</tr>
<tr class="even">
<td>234568992</a></td>
<td>Private</td>
<td>asfsdfaf</td>
<td>asfsaf</td>
<td>safsdafsdf</td>
<td>Some address</td>
<td>3344</td>
<td>&safsdafsda</td>
<td>sadfsaddfdaf</td>
</tr>
<table>
Please suggest??
Set the following to your css stylesheet:
table{width: 100%;table-layout: fixed;}
Edit
If you could use jQuery, its easy:
$(document).ready(function(){
/*define table class then place your class here instead of 'table'*/
var tablewidth = $('table').width();
/*define h3 class then place your class here instead of 'h3'*/
$('h3').css('width',tablewidth - 10);
});
demo
h3{
position:fixed;
width:100%
}
table{
top:60px;
position:relative;
}
demo