I want to create layout like this:
Desktop
Mobile
but do not know how to achieve that. So far I have this:
<aside class="container-fluid" role="complementary">
<div class="modal-container ">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-6 col-xs-12">
<h2>Name</h2>
<ul class="menu">
<li>Jack</li>
<li>John</li>
<li>James</li>
</ul>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-6 col-xs-12">
<h2>Surname</h2>
<ul class="menu">
<li>Sales</li>
<li>Admin</li>
<li>Sales</li>
</ul>
</div>
<div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12">
<h2>Action</h2>
Connect
Connect
Connect
</div>
</div>
<table>
<tr>
<td>Jack</td>
<td>Sales</td>
</tr>
<tr>
<td>Connect</td>
</tr>
<tr>
<td>John</td>
<td>Admin</td>
</tr>
<tr>
<td>Connect</td>
</tr>
<tr>
<td>James</td>
<td>Sales</td>
</tr>
<tr>
<td>Connect</td>
</tr>
</table>
</div>
</aside>
What's the most sane way to achieve these layouts?
(Should it be table combined with flex? Is it ok to use BS grid for this?)
Your total bootstrap grid understanding here is wrong. Also I dont want to write the whole code for you - please understand the concept and implement the mobile layout.
Below is the grid correction for desktop, you have to add more bootstrap classes for making this more responsive.
You don't need tables for this, you can achieve both layouts completely with BS alone.
Run the below snippet, open it full-screen and resize your browser - you will notice the beauty of BS grid
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<aside class="container-fluid" role="complementary">
<div class="modal-container ">
<div class="row">
<div class="col-xs-12">
<h2 class='col-xs-4'> Name</h2>
<h2 class='col-xs-4'> Surname</h2>
<h2 class='col-xs-4'> Action</h2>
</div>
<div class="col-xs-12">
<span class='col-xs-4'>Jack</span>
<span class='col-xs-4'>Sales</span>
<input type="button" value='Connect' class='col-xs-4'/>
</div>
<div class="col-xs-12">
<span class='col-xs-4'>John</span>
<span class='col-xs-4'>Admin</span>
<input type="button" value='Connect' class='col-xs-4'/>
</div>
<div class="col-xs-12">
<span class='col-xs-4'>James</span>
<span class='col-xs-4'>Sales</span>
<input type="button" value='Connect' class='col-xs-4'/>
</div>
</div>
</div>
</aside>
Concept
Make <tr> into a flexbox on smaller screens
#media (max-width: 575.98px) {
.my-table tr {
display: flex;
flex-wrap: wrap;
}
.my-table tr>td:not(:last-child) {
flex: 1;
}
.my-table tr>td:last-child {
width: 100%;
}
}
It looks like
In total
body {
margin: 0;
}
header {
background: #00ADEE;
color: white;
height: 110px;
}
header h1 {
padding: 0.5rem;
margin: 0;
}
.my-table {
width: 50%;
margin-top: -50px;
margin-left: auto;
margin-right: auto;
background: white;
text-align: center;
border-collapse: separate;
border-spacing: 3rem 1.5rem;
border: 2px solid #E7E7E7;
}
.my-table th,
.my-table td {
padding: 0.5rem;
}
.my-table tr>td:last-child>a {
text-decoration: none;
display: block;
color: black;
padding: 0.5rem;
background: #E7E7E7;
}
#media (max-width: 575.98px) {
header h1 {
text-align: center
}
.my-table {
border-spacing: 1.5rem;
}
.my-table thead {
display: none;
}
.my-table tr {
display: flex;
flex-wrap: wrap;
text-align: center;
margin-bottom: 1.5rem;
}
.my-table tr>td:not(:last-child) {
flex: 1;
}
.my-table tr>td:last-child {
width: 100%;
}
}
<header>
<h1>Table Test</h1>
</header>
<table class="my-table">
<thead>
<th>Name</th>
<th>Surname</th>
<th>Action</th>
</thead>
<tbody>
<tr>
<td>Jack</td>
<td>Sales</td>
<td>Connect</td>
</tr>
<tr>
<td>John</td>
<td>Admin</td>
<td>Connect</td>
</tr>
<tr>
<td>James</td>
<td>Sales</td>
<td>Connect</td>
</tr>
</tbody>
</table>
(Change values according to your needs.)
With Bootstrap 3
Center table with offset. Use same concept as above.
body {
margin: 0;
}
header {
background: #00ADEE;
color: white;
height: 110px;
}
header h1 {
padding: 0.5rem;
margin: 0;
}
.my-table {
margin-top: -50px !important;
text-align: center;
background: white;
}
.my-table * {
border: none !important;
}
.my-table th {
text-align: center;
}
.my-table tr>td:last-child>a {
text-decoration: none;
display: block;
color: black;
background: #E7E7E7;
}
#media (max-width: 575.98px) {
header h1 {
text-align: center
}
.my-table thead {
display: none;
}
.my-table tr {
display: flex;
flex-wrap: wrap;
}
.my-table tr>td:not(:last-child) {
flex: 1;
}
.my-table tr>td:last-child {
width: 100%;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<header>
<h1>Table Test</h1>
</header>
<div class="row">
<div class="col-xs-6 col-xs-offset-3 col-sm-6 col-sm-offset-3">
<table class="my-table table">
<thead>
<th>Name</th>
<th>Surname</th>
<th>Action</th>
</thead>
<tbody>
<tr>
<td>Jack</td>
<td>Sales</td>
<td>Connect</td>
</tr>
<tr>
<td>John</td>
<td>Admin</td>
<td>Connect</td>
</tr>
<tr>
<td>James</td>
<td>Sales</td>
<td>Connect</td>
</tr>
</tbody>
</table>
</div>
</div>
Related
We are printing medical reports with xml/xslt/css and pdfreactor. Therefore we need exact positions in units.
The report is a table and some headers should be repeated on each page (colored red).
In table row 2 (=Analysis2) the field in column Result is too long to fit the column and I would like to have a new line with css (or javascript?) like in table row 3 (Analysis3, I prepared this row so that it looks like my expectation). Results are too important in a medical report and should not be wrapped.
Borders are not relevant.
#media print {
#page {
size: a4;
margin: 1cm;
margin-top: 4cm;
margin-bottom: 8cm;
}
}
body
{
margin:0;
padding:0;
}
.PatientBox, .ResultBox, .AnalysisGroup {
display:table;
/* border-style: solid; */
}
.PatientBoxHeader, .ResultBoxHeader, .AnalysisGruppeHeader {
display: table-header-group;
font-weight: bold;
color: red;
/* border-style: solid; */
}
.Analysis, .Result, .ReferenceRange {
float: left;
}
.Result{ position: absolute; left: 6.2cm;}
.ReferenceRange { position: absolute; left: 10cm; }
.ResultLine {
display: table;
}
.ResultAnalysis, .Value, .ResultUnit, .Reference {
display: table-cell;
border-width: 0.01mm;
border-style: solid;
/* word-wrap: break-word; */
}
.ResultAnalysis { min-width: 6.2cm; max-width: 6.2cm; }
.Value { min-width: 1.8cm; max-width: 1.8cm; }
.ResultUnit { min-width: 1.8cm; max-width: 1.8cm; }
.Reference { min-width: 2.5cm; max-width: 2.5cm; }
<html>
<head>
<link rel="stylesheet" href="test6.css" type="text/css" />
</head>
<body>
<div class="PatientBox"> <!-- Table -->
<div class="PatientBoxHeader">Patient John Doe</div> <!-- TableGroup -->
<div class="ResultBox"> <!-- Table -->
<div class="ResultBoxHeader"> <!-- TableGroup -->
<div class="Analysis">Analysis</div>
<div class="Result">Result</div>
<div class="ReferenceRange">Reference Range</div>
</div>
<div class="AnalysisGroup"> <!-- Table -->
<div class="AnalysisGruppeHeader">Title1 <!-- TableGroup -->
</div>
<div class="ResultLine">
<div class="ResultAnalysis">Analysis1
</div>
<div class="Value">1000</div>
<div class="ResultUnit">very lang ResultUnit xxxx</div>
<div class="Reference">1-10</div>
</div>
<div class="Comment">Comment</div>
<div class="ResultLine">
<div class="ResultAnalysis">Analysis2 veeeery veeeeery veeeery very long
</div>
<div class="Value">1000000000000</div>
<div class="ResultUnit">mg/l</div>
<div class="Reference">1-10</div>
</div>
<div class="Comment">Comment</div>
<div class="ResultLine">
<div class="ResultAnalysis">Analysis3
</div>
<div class="Value">1000000000000</div>
<div class="ResultUnit"></div>
<div class="Reference"></div>
</div>
<div class="ResultLine">
<div class="ResultAnalysis">
</div>
<div class="Value"></div>
<div class="ResultUnit">mg/l</div>
<div class="Reference">1-10</div>
</div>
<div class="Comment">Comment</div>
</div>
</div>
</div>
</body>
</html>
I suggest using real tables too, but you can use word-break: break-all; in your css.
I put it in the body as example, but I wouldn't recommend that since it breaks words on any place.
#media print {
#page {
size: a4;
margin: 1cm;
margin-top: 4cm;
margin-bottom: 8cm;
}
}
body
{
margin:0;
padding:0;
word-break: break-all;
}
.PatientBox, .ResultBox, .AnalysisGroup {
display:table;
/* border-style: solid; */
}
.PatientBoxHeader, .ResultBoxHeader, .AnalysisGruppeHeader {
display: table-header-group;
font-weight: bold;
color: red;
/* border-style: solid; */
}
.Analysis, .Result, .ReferenceRange {
float: left;
}
.Result{ position: absolute; left: 6.2cm;}
.ReferenceRange { position: absolute; left: 10cm; }
.ResultLine {
display: table;
}
.ResultAnalysis, .Value, .ResultUnit, .Reference {
display: table-cell;
border-width: 0.01mm;
border-style: solid;
/* word-wrap: break-word; */
}
.ResultAnalysis { min-width: 6.2cm; max-width: 6.2cm; }
.Value { min-width: 1.8cm; max-width: 1.8cm; }
.ResultUnit { min-width: 1.8cm; max-width: 1.8cm; }
.Reference { min-width: 2.5cm; max-width: 2.5cm; }
<html>
<head>
<link rel="stylesheet" href="test6.css" type="text/css" />
</head>
<body>
<div class="PatientBox"> <!-- Table -->
<div class="PatientBoxHeader">Patient John Doe</div> <!-- TableGroup -->
<div class="ResultBox"> <!-- Table -->
<div class="ResultBoxHeader"> <!-- TableGroup -->
<div class="Analysis">Analysis</div>
<div class="Result">Result</div>
<div class="ReferenceRange">Reference Range</div>
</div>
<div class="AnalysisGroup"> <!-- Table -->
<div class="AnalysisGruppeHeader">Title1 <!-- TableGroup -->
</div>
<div class="ResultLine">
<div class="ResultAnalysis">Analysis1
</div>
<div class="Value">1000</div>
<div class="ResultUnit">very lang ResultUnit xxxx</div>
<div class="Reference">1-10</div>
</div>
<div class="Comment">Comment</div>
<div class="ResultLine">
<div class="ResultAnalysis">Analysis2 veeeery veeeeery veeeery very long
</div>
<div class="Value">1000000000000</div>
<div class="ResultUnit">mg/l</div>
<div class="Reference">1-10</div>
</div>
<div class="Comment">Comment</div>
<div class="ResultLine">
<div class="ResultAnalysis">Analysis3
</div>
<div class="Value">1000000000000</div>
<div class="ResultUnit"></div>
<div class="Reference"></div>
</div>
<div class="ResultLine">
<div class="ResultAnalysis">
</div>
<div class="Value"></div>
<div class="ResultUnit">mg/l</div>
<div class="Reference">1-10</div>
</div>
<div class="Comment">Comment</div>
</div>
</div>
</div>
</body>
</html>
Here's a sample of what an actual table might look like.
body {
font-family: Arial, sans-serif;
}
table {
width: 100%;
}
caption {
text-align: left;
font-size: 18px;
}
th {
background: #eee;
}
td {
border: 1px solid #eee;
padding: 5px;
min-width: 80px;
}
<table>
<caption>Patient John Doe</caption>
<thead>
<tr>
<th>Analysis</th>
<th colspan="2">Result</th>
<th colspan="2" class="ReferenceRange">Reference Range</th>
</tr>
<tr>
<th colspan="5" class="AnalysisGruppeHeader">Title 1</th>
</tr>
</thead>
<tbody>
<tr class="AnalysisGroup">
<td class="ResultAnalysis">Analysis1</td>
<td class="Value">1000</td>
<td class="ResultUnit">mg/l</td>
<td class="Reference">1-10</td>
</tr>
<tr>
<td colspan="5" class="Comment">Comment</td>
</tr>
</tbody>
<thead>
<tr>
<th colspan="5" class="AnalysisGruppeHeader">Title 2</th>
</tr>
</thead>
<tbody>
<tr class="AnalysisGroup">
<td class="ResultAnalysis">Really long analysis 1 goes on for some time.</td>
<td class="Value">10000000000000000000000</td>
<td class="ResultUnit">mg/l</td>
<td class="Reference">1-10</td>
</tr>
<tr>
<td colspan="5" class="Comment">Comment</td>
</tr>
</tbody>
<thead>
<tr>
<th colspan="5" class="AnalysisGruppeHeader">Title 3</th>
</tr>
</thead>
<tbody>
<tr class="AnalysisGroup">
<td class="ResultAnalysis">Analysis1</td>
<td class="Value">1000</td>
<td class="ResultUnit">mg/l</td>
<td class="Reference">1-10</td>
</tr>
<tr>
<td colspan="5" class="Comment">Comment</td>
</tr>
</tbody>
</table>
Problem solved.
#media print {
#page {
size: a4;
margin: 1cm;
margin-top: 4cm;
margin-bottom: 8cm;
}
}
body
{
margin:0;
padding:0;
}
.PatientBox, .ResultBox, .AnalysisGroup {
display:table;
}
.ResultBoxHeader .Analysis,
.ResultBoxHeader .Result,
.ResultBoxHeader .ReferenceRange {
float: left;
color: green;
}
.ResultBoxHeader .Result{ position: absolute; left: 6.2cm;}
.ResultBoxHeader .ReferenceRange { position: absolute; left: 10cm; }
.PatientBoxHeader, .ResultBoxHeader, .AnalysisGruppeHeader {
display: table-header-group;
font-weight: bold;
color: red;
border-style: solid;
}
.AnalysenBox {
clear: left;
}
.ResultLine {
display: table;
}
.ResultLine .ResultAnalysis,
.ResultLine .ResultBox,
.ResultLine .ResultReference {
display: table-cell;
border-width: 0.01mm;
/* border-style: solid; */
color: blue;
}
.Result {
display: block;
}
.ResultValue, .ResultUnit {
display: inline-block;
}
.ResultUnit {
float: right;
}
.ResultAnalysis, .ResultUnit, .ResultReference
{
word-wrap: break-word;
}
.ResultAnalysis { min-width: 6.2cm; max-width: 6.2cm; }
.ResultLine .ResultBox { min-width: 3.8cm; max-width: 3.8cm; }
.ResultValue { min-width: 1.8cm; max-width: 3.8cm; }
.ResultUnit { min-width: 2cm; max-width: 2cm; }
.Reference { min-width: 2.5cm; max-width: 2.5cm; }
<html>
<head>
<link rel="stylesheet" href="test7.css" type="text/css" />
</head>
<body>
<div class="PatientBox"> <!-- Table -->
<div class="PatientBoxHeader">Patient</div> <!-- TableGroup -->
<div class="ResultBox"> <!-- Table -->
<div class="ResultBoxHeader"> <!-- TableGroup -->
<div class="Analysis">Analysis</div>
<div class="Result">Result</div>
<div class="ReferenceRange">Reference Range</div>
</div>
<div class="AnalysenBox">
<div class="AnalysisGroup"> <!-- Table -->
<div class="AnalysisGruppeHeader"> <!-- TableGroup -->
<div class="Title">Title1</div>
</div>
<div class="ResultLine">
<div class="ResultAnalysis">Analysis1</div>
<div class="ResultBox">
<div class="Result">
<div class="ResultValue">1000</div>
<div class="ResultUnit">very lang ResultUnit xxxx</div>
</div>
</div>
<div class="ResultReference">1-10</div>
</div>
<div class="Comment">Comment dhsgdahdhagjsdhas dgashadgahsdg adghsgadhgad adgahdgahdsgahgdhasgd</div>
<div class="ResultLine">
<div class="ResultAnalysis">Analysis2</div>
<div class="ResultBox">
<div class="Result">
<div class="ResultValue">10000000000</div>
<div class="ResultUnit">very lang ResultUnit xxxx</div>
</div>
</div>
<div class="ResultReference">1-10</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
At the bottom of my page/view i got a white box that i can't remove. When i inspect elements there's no elements in that space (not even body or html)
I've tried to set body to height:100%, no paddings, margins etc but it made no difference.
Sorry if i've provided too little code, just shout if you need more.
Here's my CSS:
.header {
border: 0px;
margin: 0px;
padding: 0px;
padding-bottom: 10px;
background-color: black;
color: white;
display: block;
text-align: center;
}
h1 {
border: 0px;
margin: 0px;
padding: 20px;
}
.container-fluid {
height: auto;
border: 0px;
margin-left: auto;
margin-right: auto;
display: flex;
align-items: center;
justify-content: center;
background-color: black;
}
.btn btn-primary {
border: 20px;
}
.card {
align-items: center;
justify-content: center;
}
.card-body {
display: block;
padding: 0px;
}
.card-title > img {
margin-rigth: 5px;
}
.table {
font-size: 20px;
}
HTML:
#{
ViewData["Title"] = "Home Page";
}
<div class="header">
<h1>My Health Vision</h1>
<div class="col-md-3">
<button type="button" class="btn btn-primary btn-lg btn-block">Add new goal</button>
</div>
</div>
<div class="container-fluid">
<div class="card" style="width:400px">
<div class="card-body">
<h4 class="card-title"><img src="images/goal-icon.png" width="60" height="60" />My weigth goal</h4>
<table class="table">
<tbody>
<tr>
<th scope="row">Goal weigth</th>
<td>85</td>
</tr>
<tr>
<th scope="row">Deadline</th>
<td>2018-05-30</td>
</tr>
<tr>
<th scope="row">Current weight </th>
<td>90 <button type="button" class="btn btn-primary btn-sm">Update</button></td>
</tr>
<tr>
<th scope="row">Best weigth</th>
<td>87</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Updated with HTML.
Instead of using:
height: 100%;
Use:
height: 100vh;
I am trying to change the order of the cells I have in a table on #mobile screen, but haven't had any luck.
My table on Mac width is a grid with different cell sizes, colors, font sizes etc., but on Mobile I want it to be a simple list separated by horizontal lines, with a link for each item. I managed to do this, but I'd also like to change the order in which the list appears.
Tried to add divs and order it that way but it didn't work. Any advice would be most welcome!
Here's my HTML and mobile CSS:
#mobile screen CSS
.situations {
table.situ {
margin-left: 0%;
}
tr {
display: block;
color: #161616 !important;
line-height: 1 !important;
border: none;
}
#frame {
height: 100px;
width: 100%;
}
td {
/* Behave like a "row" */
display: block;
background-color: #ffffff;
border: none;
border-bottom: 0.5px solid #161616;
position: relative;
padding-left: 2%;
text-align: center;
height: 60px;
width: $fullWidth;
font-size: 14px !important;
color: #161616 !important;
padding-top: 8%;
padding-bottom: 8%;
line-height: 1 !important;
}
td:before {
/* Now like a table header */
position: absolute;
/* Top/left values mimic padding */
top: 6px;
left: 6px;
width: 45%;
padding-right: 10px;
white-space: nowrap;
color: #161616 !important;
line-height: 1 !important;
border: none;
}
}
<section class="situations responsiveWidth center cinch2">
<div class="table"><table class="situ" id="frame" border="0" cellspacing="0" cellpadding="0">
<tr>
<div id="situ4"><td class="product1" height="33.333%" rowspan="2"><a class="label black" href="product1.html">Text</a></td></div>
<div id="situ6"><td class="product2" height="16.666%"><a class="label black" href="product2.html">Text</a></td></div>
<div id="situ3"><td class="product3" height="50%" rowspan="3"><a class="label black" href="product3.html">Text</a></td></div>
</tr>
<tr>
<div id="situ5"><td class="product4" height="16.666%"><a class="label black" href="product4.html">Text</a></td></div>
</tr>
<tr>
<div id="situ2"><td class="product5" height="33.333%" colspan="2" rowspan="2"><a class="label black big" href="product5.html">Text</a></td></div>
</tr>
<tr>
<div id="situ7"><td class="product6" height="16.666%"><a class="label black" href="product6.html">Text</a></td></div>
</tr>
<tr>
<div id="situ8"><td class="product7" height="16.666%"><a class="label black startout" href="product7.html" id="situ8">Text</a></td></div>
<div id="situ1"><td class="product8" height="33.333%" colspan="2" rowspan="2"><a class="label white big" href="product8.html">Text</a></td></div>
</tr>
<tr>
<div id="situ9"><td class="product9" height="16.66666%"><a class="label black" href="product9.html" id="situ9">Text</a></td></div>
</tr>
</table></div>
<br>
</section>
You could consider using divs instead of a table and have a flexbox for the rows. It's than easy to change the order of the columns.
.table {
display: table;
width: 100%;
}
.row {
display: flex;
justify-content: space-between;
width: 100%;
border-bottom: thin solid lightgray;
}
.cell {
display: table-cell;
padding: 0.5em;
}
.title {
order: 2;
}
.name {
order: 1;
}
.zip {
order: 4;
}
.place {
order: 3;
}
<div class="table">
<div class="row">
<div class="cell title">Title</div>
<div class="cell name">Name</div>
<div class="cell zip">Zip</div>
<div class="cell place">Place</div>
</div>
<div class="row">
<div class="cell title">Title</div>
<div class="cell name">Name</div>
<div class="cell zip">Zip</div>
<div class="cell place">Place</div>
</div>
<div class="row">
<div class="cell title">Title</div>
<div class="cell name">Name</div>
<div class="cell zip">Zip</div>
<div class="cell place">Place</div>
</div>
</div>
I want to basically have a table in my design where the size varies from 3 X 3 to 7 X 7 and need the full table to fit the small screens too.
So now going deeper, when the screen size is that of a mobile device I want the table to stretch full width, while on larger screens I need them to be in the center of the screen. Along with that in any screen size, the cells dimensions should be width = height, in other words a square.
How can I do this with CSS and TWITTER-BOOTSTRAP only?
P.S: I am new to bootstrap.
HTML
<div class="site-wrapper">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand"><span class="icon ion-arrow-left-c"></span> Back</a>
</div>
</div>
</nav>
<div class="container">
<table class="table table-bordered">
<tr>
<td data-cell="0"></td>
<td data-cell="1"></td>
<td data-cell="2"></td>
</tr>
<tr>
<td data-cell="3"></td>
<td data-cell="4"></td>
<td data-cell="5"></td>
</tr>
<tr>
<td data-cell="6"></td>
<td data-cell="7"></td>
<td data-cell="8"></td>
</tr>
</table>
</div>
</div>
CSS
body {
background-color: #fff;
color: #ffffff;
text-align: center;
margin: 0;
}
html, body {
height: 100%;
background-color: #333;
/*overflow: hidden;*/
}
a {
color: #ffffff;
}
a:hover, a:active {
color: #ffffff;
}
.site-wrapper {
width: 100%;
height: 100%;
min-height: 100%;
-webkit-box-shadow: inset 0 0 100px rgba(0,0,0,.5);
box-shadow: inset 0 0 100px rgba(0,0,0,.5);
border-top: 5px solid #5A332B;
background-color: #ccbb99 !important;
}
If I understand your issue then you should change table structure to div. Because you need square box for every device screen size. Also you need to write little bit of JavaScript or jQuery.
$(function(){
var newBoxHeight= $('#square-box .col-xs-4').outerWidth();
$('#square-box .col-xs-4').outerHeight(newBoxHeight);
});
.col-xs-4{
border: 2px solid #000000;
}
.col-xs-4:nth-child(2n+1){
background-color: #020202;
}
.col-xs-4:nth-child(2n+2){
background-color: #121212;
}
.center-content{
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
}
.table-box,
.tbale-cell-box{
color: #ffffff;
font-size: 60px;
height: 100%;
width: 100%
}
.table-box{
display: table;
text-align: center;
}
.tbale-cell-box{
display: table-cell;
vertical-align: middle;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row" id="square-box">
<div class="col-xs-4 col-sm-4"><div class="center-content"><span class="table-box"><span class="tbale-cell-box">1</span></span></div></div>
<div class="col-xs-4"><div class="center-content"><span class="table-box"><span class="tbale-cell-box">2</span></span></div></div>
<div class="col-xs-4"><div class="center-content"><span class="table-box"><span class="tbale-cell-box">3</span></span></div></div>
<div class="col-xs-4"><div class="center-content"><span class="table-box"><span class="tbale-cell-box">4</span></span></div></div>
<div class="col-xs-4"><div class="center-content"><span class="table-box"><span class="tbale-cell-box">5</span></span></div></div>
<div class="col-xs-4"><div class="center-content"><span class="table-box"><span class="tbale-cell-box">6</span></span></div></div>
<div class="col-xs-4"><div class="center-content"><span class="table-box"><span class="tbale-cell-box">7</span></span></div></div>
<div class="col-xs-4"><div class="center-content"><span class="table-box"><span class="tbale-cell-box">8</span></span></div></div>
<div class="col-xs-4"><div class="center-content"><span class="table-box"><span class="tbale-cell-box">9</span></span></div></div>
</div>
</div>
Hope it will help.
Update: Just couldn't do the pure css version and powered with jQuery:
function setHeight() {
var myTable = $("#myTable");
myTable.height(myTable.width());
$( window ).resize(function() {
myTable.height(myTable.width());
});
}
setHeight();
body {
background-color: #fff;
color: #ffffff;
text-align: center;
margin: 0;
}
html, body {
height: 100%;
background-color: #333;
/*overflow: hidden;*/
}
a {
color: #ffffff;
}
a:hover, a:active {
color: #ffffff;
}
.site-wrapper {
width: 100%;
height: 100%;
min-height: 100%;
-webkit-box-shadow: inset 0 0 100px rgba(0,0,0,.5);
box-shadow: inset 0 0 100px rgba(0,0,0,.5);
border-top: 5px solid #5A332B;
background-color: #ccbb99 !important;
}
.container {
}
.table {
width: 50vw;
height: 50vw;
margin-left: 25%;
margin-top: 5%;
}
.table-bordered {
border: 1px solid black;
}
#media screen and (max-width: 750px) {
.table {
margin-left: 0;
margin-top: 0;
width: 100%;
height: 100%;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="site-wrapper">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand"><span class="icon ion-arrow-left-c"></span> Back</a>
</div>
</div>
</nav>
<div class="container">
<table id="myTable" class="table table-bordered">
<tr>
<td data-cell="0">0</td>
<td data-cell="1">1</td>
<td data-cell="2">2</td>
</tr>
<tr>
<td data-cell="3">3</td>
<td data-cell="4">4</td>
<td data-cell="5">5</td>
</tr>
<tr>
<td data-cell="6">6</td>
<td data-cell="7">7</td>
<td data-cell="8">8</td>
</tr>
</table>
</div>
</div>
I have a table created only with divs with fixed width columns. But I need to change width of columns with bootstrap or any other way.
Html:
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="rTable">
<div class="rTableHeading">
<div class="rTableRow">
<div class="rTableHead">Title1 </div>
<div class="rTableHead">Title2 </div>
<div class="rTableHead">Title3 </div>
<div class="rTableHead">Title4 </div>
</div>
</div>
<div class="rTableBody">
<div class="rTableRow">
<div class="rTableCell">row1</div>
<div class="rTableCell">row1</div>
<div class="rTableCell">row1</div>
<div class="rTableCell">row1</div>
</div>
<div class="rTableRow">
<div class="rTableCell">row2</div>
<div class="rTableCell">row2</div>
<div class="rTableCell">row2</div>
<div class="rTableCell">row2</div>
</div>
</div>
</div>
</div>
</div>
Styles:
.rTable {
display: block;
width: 100%;
border: 1px solid #ddd;
}
.rTableHeading, .rTableBody, .rTableFoot, .rTableRow {
clear: both;
}
.rTableHead, .rTableFoot {
background-color: #FBFBFB;
font-weight: bold;
width: 100%;
padding: 0 !important;
}
.rTableCell, .rTableHead {
padding: 5px !important;
border-bottom: 1px solid #ddd;
float: left;
height: 17px;
overflow: hidden;
padding: 3px 1.8%;
width: 24%;
}
.rTableCell {
height: 46px;
}
.rTable:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
When I need 4 columns I should use width=24% for all columns. But how can I create columns with different width? Is there a way to use bootstrap column classes to do this?
You need to put your table in correctly first. Then you can resize columns as you want. I have recreated your table in html, and applied the css style to it to change the width of each column.
You should look at nth-child and nth-of-type in W3Schools sometime. Thery're very helpful.
thead th:nth-child(1) {
background: red;
width: 10%;
}
thead th:nth-child(2) {
background: pink;
width: 20%;
}
thead th:nth-child(3) {
background: purple;
width: 5%;
}
thead th:nth-child(4) {
background: green;
width: 50%;
}
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<table class="table table-striped table-hover table-condensed table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Title1</th>
<th>Title2</th>
<th>Title3</th>
<th>Title4</th>
</tr>
</thead>
<tbody>
<tr>
<td>row1</td>
<td>row1</td>
<td>row1</td>
<td>row1</td>
</tr>
<tr>
<td>row2</td>
<td>row2</td>
<td>row2</td>
<td>row2</td>
</tr>
</tbody>
</table>
</div>
</div>
Yes there is, try this. If I understand the question correctly that is. I'm not 100% sure where you want to actually add the width, but I would assume this would do what you are asking for.
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12">
<div class="rTable">
<div class="rTableHeading">
<div class="rTableRow">
<div class="rTableHead col-sm-3">Title1 </div>
<div class="rTableHead col-sm-3">Title2 </div>
<div class="rTableHead col-sm-3">Title3 </div>
<div class="rTableHead col-sm-3">Title4 </div>
</div>
</div>
<div class="rTableBody">
<div class="rTableRow">
<div class="rTableCell col-sm-3">row1</div>
<div class="rTableCell col-sm-3">row1</div>
<div class="rTableCell col-sm-3">row1</div>
<div class="rTableCell col-sm-3">row1</div>
</div>
<div class="rTableRow">
<div class="rTableCell col-sm-3">row2</div>
<div class="rTableCell col-sm-3">row2</div>
<div class="rTableCell col-sm-3">row2</div>
<div class="rTableCell col-sm-3">row2</div>
</div>
</div>
</div>
</div>
</div>
Also, I would take out the width% in your CSS for rTableCell if you are utilizing the bootstrap column sizing. You can still add sizing here if you would like to see how it impacts your columns. It isn't right or wrong, but first see what it looks like without the width% and then come back to add width to your liking.
.rTableCell, .rTableHead {
padding: 5px !important;
border-bottom: 1px solid #ddd;
float: left;
height: 17px;
overflow: hidden;
padding: 3px 1.8%;
/* width: 24%; */
}
Maybe there is a better solution with bootstrap but I used this approach for now.
.rTableHeading .rTableHead:nth-child(1) ,
.rTableBody .rTableCell:nth-child(1) {
width: 30%;
}
.rTableHeading .rTableHead:nth-child(2) ,
.rTableBody .rTableCell:nth-child(2) {
width: 30%;
}
.rTableHeading .rTableHead:nth-child(3) ,
.rTableBody .rTableCell:nth-child(3) {
width: 15%;
}
.rTableHeading .rTableHead:nth-child(4) ,
.rTableBody .rTableCell:nth-child(4) {
width: 20%;
}
I also cleared width=24% from rTableCell and rTableHead.