display inline without float - html

I have 3 tables that looks like this:
What I would like to do is have them all 3 line up in a row withou a space between each table(bottom table goes where the red square is). The problem I have is apparent, but I cannot seems to get rid of those gaps inbetween the table wihout using negative margins which I would like to avoid since I heard it's not good practice (browsers might break it). Would it also be possible to align the tables without floating them? I've tried to use a couple of these tricks but none seems to work: http://css-tricks.com/fighting-the-space-between-inline-block-elements/
Here is my css:
my main body is 901px wide so I just changed my width to 300 for each table
.measure_data {
width: 299px;
border: solid 1px;
border-collapse: collapse;
display: inline-block;
}

White space between elements is inevitable when using display: inline-block;. Try this. You need to make sure you "tie" the gaps together, like so:
<div>
<p>1/3</p>
</div><!--
--><div>
<p>1/3</p>
</div><!--
--><div>
<p>1/3</p>
</div>

You should reduce the table with 299 to 290
.measure_data {
width: 290px;
border: solid 1px;
border-collapse: collapse;
display: inline-block;
}
Here click here to see in jsfiddle

Add position to second and third table:
.measure_data {
width: 299px;
border: solid 1px;
border-collapse: collapse;
display: inline-block;
}
.2{
position: absolute;
}
.3{
position: relative;
}

Related

Small gaps between table cells

I have a table in which I would like the borders to collapse and all the cells to touch. I feel like I may be missing something obvious, but the bottom borders are not showing at all despite having height assigned to them. They instead just separate the cells from one another allowing the background color to show through (red in the example).
If I change the border-collapse to separate the borders re-appear, but the gaps remain as well as adding gaps between the columns as well.
JSfiddle
You are not targeting the Table Row, see fiddle: https://jsfiddle.net/32o87x7L/3/
.defaultTable tr{border-bottom: 2px solid blue;}
.defaultTable th,
.defaultTable td {
position: relative;
display: table-cell;
vertical-align: top;
padding: 9px 16px;
font-size: 14px;
line-height: 20px;
background: #eee;
border: none;
//border-bottom: 2px solid blue;
box-sizing: border-box;
}
As is usually the case, I solved my own problem right after submitting my question. :-/
Apparently table-cells do not take too well to positioning as they cannot be consistently. Removing position: relative; from the .defaultTable th, .defaultTable td did the trick.

Having trouble to create a third column in this HTML code. How to do this?

I am trying to edit a code that has on the left side an image and on the right side the text content. Below the text content there is a button. What I am trying to do using width=percentage is to create a third column where I will put the button into it and some other text.
I have posted my code into the jsFiddle for better understanding.
http://jsfiddle.net/cm9UC/
.blog-post {
margin-bottom: 40px;
padding-bottom: 40px;
border-bottom: 1px solid #eee;
}
Better explanation
Suppose that now there are two columns. The first one is the picture, and the second is the text. What I want to do is to decrease the width of the text so that will let me to take the created space and make it a third column. The new column should have the button in it.
All you need to do is wrap the h2 and p in one div and wrap button in another div.
and define the width for them and use {float:left;} for each.
It will surely work.
Try this one:
updated jsfiddle
What I did is make your p into:
display: inline-block;
vertical-align: middle;
width: 80%
and then your a into:
width: auto;
vertical-align: middle;
can your vertical-align into top,middle, or bottom depends on your need.
like this you can change the column without making another div.
But of course the better work round is wrap them up with extra divs, that will be sleeker and cleaner.
I've just added 2 new line in your CSS and wrap the h2 and p inside a div.
.post-type+ div{max-width:80%; display:inline-block;}
.post-type~ a{display:inline-block; border:1px solid red;vertical-align:bottom;}
margin-bottom: 40px;
padding-bottom: 40px;
border-bottom: 1px solid #eee;
overflow:hidden; /*new line added*/
}
Here is the working Demo. http://jsfiddle.net/cm9UC/60/

How to style a list so that it looks like a table, with various line height?

I try to have some sort of grid layout on my page:
<ul>
<li>blabla</li>
<li>bla bla bla bla bla</li>
...
</ul>
style :
li {
width: 100px;
display: inline-block;
float: left
}
Trouble comes when an element in a li is longer than the others on its line. I had at some point a height for each item (300px) but if on one line all the elements are 100px then there will be a 200 px gap with the next line.
So somehow I am looking to have the same effect as with a table : on one line, the height is the height of the tallest item, mixed with this ul/li thing where contrary to a table the number of columns and lines is fixed.
Do you know how to do that ? If possible in pure html/css (html5/css3 ok) and no library
http://jsfiddle.net/mF24t/9/
Thanks !
You may want to use display:table-cell on li:
See demo fiddle: http://jsfiddle.net/abhitalks/mF24t/4/
li {
width: 100px;
display: table-cell;
border: 1px solid gray;
padding: 2px;
}
Update:
Variation 2: http://jsfiddle.net/abhitalks/mF24t/13/
Use float:left (as you insist to use) and clear the float say every 5 items. Use only border-top to give a faux table like look. In the fiddle, dotted lines show the actual height (which you can control by min-height).
li {
width: 100px;
border: 1px dotted #ddd;
border-top: 1px solid gray;
padding: 2px;
display: table-cell;
float: left;
}
li:nth-child(5n+1) {
clear: left;
}
Variation 3: http://jsfiddle.net/abhitalks/wdbye/3/
Use flex-box if you can. Check http://caniuse.com to see if you could afford it. This will give you the flexible heights that you want.
ul {
display: flex;
flex-flow: row wrap;
}
Note: Apart from the above mentioned ideas, there is no other way where you can have auto-scaling of height based on content as well as a table layout.

Make whole table-row a link

I'm currently working on a table that has a different link for each row. The-clicking-area must fill the whole table-row.
And please: No Javascript! And if possible no additional Div-elements.
This is what I got so far:
http://jsfiddle.net/WLYW3/
this works pretty good, but there are some problems:
After adding height: 128px; to the a-elements (which seemed necessary), the text in each row wasn't vertically centered anymore. Adding vertical-align: middle; didn't help.
And I can't get the table to have rounded corners. (border-radius: 6px 6px 6px 6px;).
To fix it, simply add this :
#itemTable tbody tr td a
{
line-height: 128px;
}
Vertical alignment
Because you use the <table> elements, you can just make the anchor 100% height. Combined with vertical-align: middle;, which is used on the <tbody> by default, it will calculate the middle based on the total height (100%):
#itemTable tbody tr td a {
display: block;
position: relative;
/*height: 128px;*/
height: 100%;
text-decoration: none;
color: rgb(51, 51, 51);
}
Table radius
A table without a border actually does not support the border-radius property and there is no clean solution, you can only force it.
However, even though you did not want an extra element, a wrapper would be the most clean solution:
#tableWrapper
{
border-radius: 5px;
overflow: hidden;
}
jsFiddle

Stop box from breaking to next line due to extra margin?

Not sure if this is even possible, but I think it's worth asking.
What I am trying to do is have boxes created via my PHP script with ease, where I don't have to check which column, row, etc. each box (.boxes) belongs to. I just want to be able to do a foreach loop of the boxes, and echo them.
Here's what I am talking about: http://jsfiddle.net/LUFFP/4/
In that example, you can see that I am trying to get the wrapper (#main) to ignore the margin-right, and have two boxes per row, with no extra space on the right, without having to assign different classes to every other DIV.
Any help is appreciated.
You can use nth-of-type(2n) to target every other div. Then set the right margin to zero.
http://jsfiddle.net/LUFFP/5/
.boxes_3:nth-of-type(2n) { margin-right: 0px; }
Depending on your browser requirements, there's a CSS3 selector to do that:
http://jsfiddle.net/ttpK6/1/
Compatability list here: http://kimblim.dk/css-tests/selectors/
#main_2
{
background: #FF0000;
width: 404px;
border: 1px solid #000;
overflow: hidden;
}
.boxes_2
{
background: #F3F3F3;
width: 195px;
display: inline-block;
margin-right: 10px;
}
Notice that I changed the width and set overflow to hidden. No special CSS3 requirements.
try it
#main_2 {background: #FF0000; width: 411px; border: 1px solid #000;}
.boxes_2 {background: #F3F3F3; width: 205px; float:left;}