Table border spacing with div - html

Hello,
I am newbie on CSS, and I am going to design a pricing table with div(table-less). I use below css. My main problem is customized space between columns and rows.
When I add "border-spacing" four sides of cell would have border. But As you can see in picture I need different space on each side of cells.
For example border space on top and bottom 0, border space on left and right 10px. But I can not find any solution.
css style:
.Table{
display: table;
}
.Title{
display: table-caption;
text-align: center;
font-weight: bold;
font-size: larger;
}
.Heading{
display: table-row;
font-weight: bold;
text-align: center;
}
.Row{
display: table-row;
}
.Cell{
display: table-cell;
border: solid;
border-width: thin;
padding-left: 5px;
padding-right: 5px;
text-align: center;
}
.Full_width{
width: 100%;
}
.No_border{
border: none;
}
.mostpopular_tag{
background-color:#F25050;
color: #fff;
}
.pricing_table_header{
line-height: 21px;
background-color: #181818;
color: #fff;
}
And Table HTML structure is like below:
<div class="Table full_width">
<div class="Row">
<div class="Cell No_border">
<p></p>
</div>
<div class="Cell No_border mostpopular_tag">
<p>Most Popular</p>
</div>
<div class="Cell No_border">
<p></p>
</div>
</div>
<div class="Heading ">
<div class="Cell No_border pricing_table_header">
<p>Heading 1</p>
</div>
<div class="Cell No_border pricing_table_header">
<p>Heading 2</p>
</div>
<div class="Cell No_border pricing_table_header">
<p>Heading 3</p>
</div>
</div>
<div class="Row">
<div class="Cell No_border">
<p>Row 1 Column 1</p>
</div>
<div class="Cell No_border">
<p>Row 1 Column 2</p>
</div>
<div class="Cell No_border">
<p>Row 1 Column 3</p>
</div>
</div>
<div class="Row">
<div class="Cell No_border">
<p>Row 2 Column 1</p>
</div>
<div class="Cell No_border">
<p>Row 2 Column 2</p>
</div>
<div class="Cell No_border">
<p>Row 2 Column 3</p>
</div>
</div>
</div>
This is demo of my table: http://jsfiddle.net/2rFfL/

The border, margin, and padding properties have different versions for "all over" versus "each side"
So, border could be done like this:
border-width: 3px;
Or it can be done like this (first number is top, second right, third bottom, fourth left):
border-width: 3px 5px 2px 10px;
Or, you can specify each like this:
border-top-width: 3px;
border-right-width: 5px;
border-bottom-width: 2px;
border-left-width: 10px;

border-spacing accepts two values. If you supply both values, as in border-spacing: 10px 0;, then the first applies horizontally and the second vertically.
http://www.w3schools.com/cssref/pr_border-spacing.asp
Edit: http://jsfiddle.net/2rFfL/1/

Related

Bootstrap cells with equal height

I have the following
<div class="row">
<div class="col-md-6">
<div class = "box-cell">
<p>
Slightly short text
</p>
</div>
</div>
<div class="col-md-6">
<div class = "box-cell">
<p>
Text that<br>literally<br>spans<br>4 lines
</p>
</div>
</div>
</div>
and css
.box-cell
{
position: relative;
margin: 3px;
border-style: groove ridge ridge groove;
border-width: 3px;
background-size: cover;
}
So the problem that I am facing is that one of the cells is usually taller than the other.IS there any way for me to equalize how much height each cell takes up?
Searching didn't yield me which property I can manipulate to get same height :(
Here is jsfiddle
However in this fiddle I can not get them to be side by side to prove my point
EDIT: I guess I didn't specify it properly. I would like to have the borders be as tall as the tallest cell. So all the examples provided here actually take out the borders and instead color the background. If I do that then yes it gives illusion of every cell being the same, but I would like there to be a border of same height.
I tried replicating what it sounds like you are looking for.
I would recommend you mess around with flexbox since it seems to do exactly what you are looking for.
<div class="myc">
<div class="col">
<p>Text of some sorts</p>
<p>Text of some sorts</p>
<p>Text of some sorts</p>
<p>Text of some sorts</p>
</div>
<div class="col">
<p>Text of some sorts</p>
<p>Text of some sorts</p>
<p>Text of some sorts</p>
</div>
</div>
And for the CSS
.myc {
display: flex;
}
.col {
background-color: yellow;
margin-right: 20px;
}
.row {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
}
.row > [class*='col-'] {
display: flex;
flex-direction: column;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-xs-12 col-sm-4" style="background-color: green">
some content
</div>
<div class="col-xs-6 col-sm-4" style="background-color: orange">
some content
<img src="http://placehold.it/100x120">
</div>
<div class="col-xs-6 col-sm-4" style="background-color: magenta">
some of content
</div>
</div>
Some options to solve it:
Different Tricks on How to Make Bootstrap Columns All the Same Height
<style type="text/css">
.box-cell{
position: relative;
margin: 3px;
border-style: groove ridge ridge groove;
border-width: 3px;
background-size: cover;
}
</style>
<div class="row">
<div class="col-md-6">
<div class = "box-cell">
<p>
Slightly short text
</p>
</div>
</div>
<div class="col-md-6">
<div class = "box-cell">
<p>
<span>Text that</span>
<span>literally</span>
<span>s4 lines</span>
<span>ygthfg</span>
</p>
</div>
</div>
</div>
1- you need to add text in span tag.
2- Or take text in one line .

how to merge the row of the table using css?

ok so i have do the a table . The problem i facing is i want to know how to merge the row of my table ... anyone can help me or teach me on how to merge the row of my table ?? for example if my row1 and row2 below want to merge as one row, how do i merge it ? would be happy if someone can help me :) [ ps : can i merge the table by writing something in the style there ?? if can then how ??
below is my code :]
<html>
<head>
<style type="text/css">
.Table
{
display: table;
}
.Title
{
display: table-caption;
text-align: center;
font-weight: bold;
font-size: larger;
}
.Heading
{
display: table-row;
font-weight: bold;
text-align: center;
}
.Row
{
display: table-row;
}
.Cell
{
display: table-cell;
border: solid;
border-width: thin;
padding-left: 5px;
padding-right: 5px;
}
</style>
<body>
<div class="Table">
<div class="Title">
<p>This is a Table</p>
</div>
<div class="Heading">
<div class="Cell">
<p>Heading 1</p>
</div>
<div class="Cell">
<p>Heading 2</p>
</div>
<div class="Cell">
<p>Heading 3</p>
</div>
</div>
<div class="Row">
<div class="Cell">
<p>Row 1 Column 1</p>
</div>
<div class="Cell">
<p>Row 1 Column 2</p>
</div>
<div class="Cell">
<p>Row 1 Column 3</p>
</div>
</div>
<div class="Row">
<div class="Cell">
<p>Row 2 Column 1</p>
</div>
<div class="Cell">
<p>Row 2 Column 2</p>
</div>
<div class="Cell">
<p>Row 2 Column 3</p>
</div>
</div>
</div>
</body>
</html>
use rowspan attribute on the <td> tag. for example. use <td rowspan="2">this row is two rows merged</td> you could find more resource about this in https://www.w3schools.com/TAGs/att_td_rowspan.asp

Adding a margin between two bootstrap columns makes them stack on top of each other

I have two bootstrap columns, side by side, but when I add a margin to separate them then the columns stack on top of each other. I am using the Mixed: mobile, tablet, and desktop grid template for my two columns, and I'm not sure whether this is the cause.
#antGame { // container
height: 60%;
position: relative;
background-color: #fff;
border: 1px solid grey;
padding: 0 !important;
}
#stimuliContainer {
height: 40%;
}
#stimuli {
width: 100%;
max-height: 100%;
}
#errorMsg {
height: 20%;
width: 100%;
}
#antInstruct {
height: 60%;
background-color: #fff;
border: 1px solid grey;
}
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-lg-8" id="antGame">
<div id="stimuliContainer">
<img id="stimuli" src="images/ant/cues/blank.png">
</div>
<div class="col-xs-12 col-sm-6 col-lg-8" id="errorMsg">
<span>Error Message</span>
</div>
</div>
<div class="col-xs-6 col-lg-4" id="antInstruct">
<h4>Instructions</h4>
<span>Hi</span>
</div>
</div>
</div>
I don't recommend to override the padding of the Bootstrap columns, because it can break the responsive, but you know, sometimes you are forced to do it.
In that case the most clean way you can do, is add a custom class .padding-2, that overrides the Boostrap padding but don't destroy the responsive.
HTML
<div class="container">
<div class="row">
<div class="col-xs-6 padding-2 ">
<div style="border: 1px black solid; background-color: red;">
1 col
</div>
</div>
<div class="col-xs-6 padding-2 ">
<div style="border: 1px black solid; background-color: blue;">
2 col
</div>
</div>
</div>
</div>
CSS
.padding-2 {
padding-left: 2px;
padding-right: 2px;
}
Demo: http://www.bootply.com/eO033QYCn3
Try to use padding instead of margin, and then, if you want to have for example border, you can add another element inside this one with padding.
Here's an example:
<div class="container">
<div class="col-xs-6" style="padding: 5px">
<div style="border: 1px black solid;">
1 col
</div>
</div>
<div class="col-xs-6" style="padding: 5px">
<div style="border: 1px black solid;">
2 col
</div>
</div>
</div>
And demo:
https://plnkr.co/edit/5fCMTJMJWPALk3W45t1i?p=preview

Why does css3 multi-column layout's float causes element's width to be equal to one column's width in all browsers?

I have a problem with multi-column layout. I've designed menu as group of div elements that I want to align into 1-4 columns (depending on screen height and menu items count). It cannot be hardcoded.
Here's my HTML (jsfiddle link):
<nav id="sideMenu" class="side-nav">
<article class="side-nav-content">
<div class="content-box-nav-wrapper">
<div class="content-box">
<div class="box-header pre-box-header"></div>
<div class="box-header">
<p>Option1</p>
</div>
<div class="box-header post-box-header"></div>
<div class="box-content">
<a>Link1</a>
<a>Link2</a>
</div>
</div>
</div>
<div class="content-box-nav-wrapper">
<div class="content-box">
<div class="box-header pre-box-header"></div>
<div class="box-header">
<p>Option1</p>
</div>
<div class="box-header post-box-header"></div>
<div class="box-content">
<a>Link1</a>
<a>Link2</a>
</div>
</div>
</div>
<div class="content-box-nav-wrapper">
<div class="content-box">
<div class="box-header pre-box-header"></div>
<div class="box-header">
<p>Option1</p>
</div>
<div class="box-header post-box-header"></div>
<div class="box-content">
<a>Link1</a>
<a>Link2</a>
</div>
</div>
</div>
<div class="content-box-nav-wrapper">
<div class="content-box">
<div class="box-header pre-box-header"></div>
<div class="box-header">
<p>Option1</p>
</div>
<div class="box-header post-box-header"></div>
<div class="box-content">
<a>Link1</a>
<a>Link2</a>
</div>
</div>
</div>
<div class="content-box-nav-wrapper">
<div class="content-box">
<div class="box-header pre-box-header"></div>
<div class="box-header">
<p>Option1</p>
</div>
<div class="box-header post-box-header"></div>
<div class="box-content">
<a>Link1</a>
<a>Link2</a>
</div>
</div>
</div>
</article>
</nav>
<div class="content">
<p class="wrong">This should be on the right side of mneu.</p>
</div>
and my CSS looks like this:
p, a {
color: black;
}
#sideMenu {
float: left; /*This float seems to mess up column layout's width*/
}
article.side-nav-content {
-webkit-column-width: 255px;
-moz-column-width: 255px;
column-width: 255px;
-webkit-column-gap: 28px;
-moz-column-gap: 28px;
column-gap: 28px;
-moz-column-fill: auto;
height: 200px;
}
.side-nav .content-box {
border: 1px solid #000;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
margin: 0px 0px 23px 0px;
color: #fff;
background: rgba(0, 0, 0, 0.1);
width: 255px;
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
column-break-inside: avoid;
break-inside: avoid;
}
.content {
width: 100vw;
height: 100vh;
float: left;
}
.wrong {
color: red;
font-size: 20px;
}
body {
width: 200vw;
overflow-x:hidden;
}
If you inspect #sideMenu in browser you'll see that despite the fact that it is visible as 3 columns and should have their width it only has first column width.
How can I fix this? (The red text should be next to the last box on the right side)
Removing float is not a a good solution since I need this next to page content.
I need menu div to float as well as page content since I want my menu to slide back and forth on user's click. I want to modify menu width on user's action from 0% to 100%, but that's not possible since the content interferes with menu. I have tested that with newest versions of Chrome and Firefox.
I had the same problem and the only way I came up with is with javascript. (since the column width will be dynamic based on the amount of content in the column div and the window size).
So the #sideMenu has to have "position: relative;" and then in the javascript you set the style.left to be at least the width of the column container which you can get by document.getElementById('columnContainer').clientWidth.
I can provide a jsfiddle or more code here if you need.
you will have to call the javascript function onbody load and anytime widow size changes, at least.
Good luck

div table column width doesn't match rows

Spending way too much time on (what should be) a simple div table. PROBLEM: the column headers will not resize to the width of the table, or the rows. The rows appear okay, but the column headers don't.
Trying to avoid having fixed widths as the next table I post may have a different number of columns. With the following code the column headers are all scrunched to the left, next to each other, but they don't match the rows...
<style type="text/css">
.table-container {
display: table;
width: 50%;
table-layout: fixed;
border-collapse: collapse;
}
.table-heading {
font-weight: bold;
display: table-caption;
background-color: #e9e9e9;
text-align: center;
padding: 8px;
line-height: 21px;
font-size: 18px;
color: #CA8327;
}
.table-row {
display: table-row;
text-align: center;
}
.table-row-shade {
display: table-row;
text-align: center;
background-color: #e9e9e9;
}
.table-col {
display: table-cell;
text-align: center;
border: 1px solid #ca8327;
}
</style>
<div class="table-container">
<div class="table-heading">Approximate Dimensions (inches)</div>
<div class="table-col">
<div class="table-col">size</div>
<div class="table-col">head strap (inc. frame)</div>
<div class="table-col">chin strap</div>
<div class="table-col">lbs.*</div>
</div>
<div class="table-row-shade">
<div class="table-col">XXS</div>
<div class="table-col">3-9 inches</div>
<div class="table-col">2-3 inches</div>
<div class="table-col">< 5 lbs*</div>
</div>
<div class="table-row">
<div class="table-col">XS</div>
<div class="table-col">5-13 inches</div>
<div class="table-col">3-7 inches</div>
<div class="table-col">5 - 10lbs*</div>
</div>
</div>
http://jsfiddle.net/Speedy1/t3e3ken6/
You only put table-col rather than table-row
<div class="table-container">
<div class="table-heading">Approximate Dimensions (inches)</div>
<div class="table-row"> <!-- must be a table-row -->
<div class="table-col">size</div>
<div class="table-col">head strap (inc. frame)</div>
<div class="table-col">chin strap</div>
<div class="table-col">lbs.*</div>
</div>
<div class="table-row-shade">
<div class="table-col">XXS</div>
<div class="table-col">3-9 inches</div>
<div class="table-col">2-3 inches</div>
<div class="table-col">< 5 lbs*</div>
</div>
<div class="table-row">
<div class="table-col">XS</div>
<div class="table-col">5-13 inches</div>
<div class="table-col">3-7 inches</div>
<div class="table-col">5 - 10lbs*</div>
</div>
</div>
http://jsfiddle.net/vgjb578s/
Try this http://jsfiddle.net/t3e3ken6/1/
It's because you have put the class "table-col" next to your heading. Change it to "table-row" and the problem is solved.
<div class="table-row">
<div class="table-col">size</div>
<div class="table-col">head strap (inc. frame)</div>
<div class="table-col">chin strap</div>
<div class="table-col">lbs.*</div>
</div>