Making col-auto the same width between multiple rows - css

Lets say I have the following rows:
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2</div>
<div class="col-auto">Row 3</div>
</div>
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2 longest one</div>
<div class="col-auto">Row 3 longest one</div>
</div>
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2 shorter</div>
<div class="col-auto">Row 3 shorter</div>
</div>
This produces:
What I am looking to achieve:
What approach could I take to ensure the columns maintain the same widths between these different rows, so that they all become the width of the largest column?

You can try display:table like this:
.container {
display: table;
}
.container>.row {
display: table-row;
}
.container>.row>* {
display: table-cell;
padding:5px;
white-space:nowrap;
}
.col {
width:100%;
}
<div class="container">
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2</div>
<div class="col-auto">Row 3</div>
</div>
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2 longest one</div>
<div class="col-auto">Row 3 longest one</div>
</div>
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2 shorter</div>
<div class="col-auto">Row 3 shorter</div>
</div>
</div>

Try this.
Using a table which is set to fill the entire width. Have set col1 to take up all the space avaliable. Because its a table, the other 2 columns will just work.
Have set the text in the table cells to not wrap so you can see it working fluidly.
.custom-table {
border: 0;
width: 100%;
}
.col-wide {
width: 100%;
}
.row td {
white-space: nowrap;
padding: 5px;
}
<table class="custom-table">
<tr class="row">
<td class="col-wide">Row 1</td>
<td>Row 2</td>
<td>Row 3</td>
</tr>
<tr class="row">
<td class="col-wide">Row 1</td>
<td>Row 2 longest one ffdssdgg</td>
<td>Row 3 longest one</td>
</tr>
<tr class="row">
<td class="col-wide">Row 1</td>
<td>Row 2 shorter</td>
<td>Row 3 shorter</td>
</tr>
</table>
Any questions, shout.

Maybe you can use display: grid.
And after you can style your rows as you want.
.container>.row {
display: grid;
grid-template-columns: 50% auto auto;
padding: 5px;
}
<div class="container">
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2</div>
<div class="col-auto">Row 3</div>
</div>
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2 longest one</div>
<div class="col-auto">Row 3 longest one</div>
</div>
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2 shorter</div>
<div class="col-auto">Row 3 shorter</div>
</div>
</div>

Use grid display :
<style>
.grid-container {
display: grid;
grid-template-columns: auto auto auto ;
grid-gap: 10px;
}
.grid-container > div {
text-align: left;
padding: 20px 0;
}
</style>
<div class="grid-container">
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2</div>
<div class="col-auto">Row 3</div>
</div>
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2 longest one</div>
<div class="col-auto">Row 3 longest one</div>
</div>
<div class="row">
<div class="col">Row 1</div>
<div class="col-auto">Row 2 shorter</div>
<div class="col-auto">Row 3 shorter</div>
</div>
</div>

Just use col-sm-* instead of col-auto.

use table with no border, for example like this:
<table border="0">
<tr>
<td>Row 1</td>
<td>Row 2</td>
<td>Row 3</td>
</tr>
<tr>
<td>Row 1</td>
<td>Row 2 longest one</td>
<td>Row 3 longest one</td>
</tr>
<tr>
<td>Row 1</td>
<td>Row 2 shorter</td>
<td>Row 3 shorter</td>
</tr>

Related

Bootstrap 4.1 Cards Styling

I have this code:
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-header">Employee Information</div>
<div class="card-body">
<table class="table table-borderless">
<tbody>
<tr>
<td scope="row">First Name: </td>
<td>{{ $employee->first_name }}</td>
</tr>
<tr>
<td scope="row">Last Name: </td>
<td>{{ $employee->last_name }}</td>
</tr>
<tr>
<td scope="row">ID Number: </td>
<td>{{ $employee->id_number }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-8">
<div class="card">
<div class="card-header">External Training Records</div>
<div class="card-body">
External Training Records:
</div>
</div>
</div>
<div class="col-md-8 offset-md-4">
<div class="card">
<div class="card-header">Clients</div>
<div class="card-body">
Clients:
</div>
</div>
</div>
<div class="col-md-8 offset-md-4">
<div class="card">
<div class="card-header">Site</div>
<div class="card-body">
Sites
</div>
</div>
</div>
</div>
</div>
https://jsfiddle.net/aq9Laaew/206869/
I would like the two sections on the right (external training and clients) to be underneath one another (when on a desktop). How does one do that in Bootstrap?
I know very little about front-end development. This is a learning curve for me.
To achieve that using Bootstrap layout utility classes, all you need is to place all your cards into one column, instead of adding a row for each card:
<div class="row">
<div class="col-lg-4">
... your left column card here...
</div>
<div class="col-lg-8">
... rest of your cards here...
</div>
</div>
Working example:
.row {
background: #f8f9fa;
}
.col {
border: solid 1px #6c757d;
}
.card {
margin-top: 15px;
}
.card + .card:last-child {
margin-bottom: 15px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-lg-4 col-md-5">
<div class="card">
<div class="card-header">Employee Information</div>
<div class="card-body">
<table class="table table-borderless">
<tbody>
<tr>
<td scope="row">First Name: </td>
<td>Jane</td>
</tr>
<tr>
<td scope="row">Last Name: </td>
<td>Doe</td>
</tr>
<tr>
<td scope="row">ID Number: </td>
<td>123456789123</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-lg-8 col-md-7">
<div class="card">
<div class="card-header">External Training Records</div>
<div class="card-body">
External Training Records:
</div>
</div>
<div class="card">
<div class="card-header">Clients</div>
<div class="card-body">
Clients:
</div>
</div>
<div class="card">
<div class="card-header">Site</div>
<div class="card-body">
Sites
</div>
</div>
</div>
</div>
</div>
Please note your current question title doesn't relate too well to the actual problem. You're basically asking a layout utility question. Whatever you place in your layout has no relevance for solving/answering it.
I think this is what you want
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-header">Employee Information</div>
<div class="card-body">
<table class="table table-borderless">
<tbody>
<tr>
<td scope="row">First Name: </td>
<td>Jane</td>
</tr>
<tr>
<td scope="row">Last Name: </td>
<td>Doe</td>
</tr>
<tr>
<td scope="row">ID Number: </td>
<td>123456789123</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col-md-8">
<div class="card">
<div class="card-header">External Training Records</div>
<div class="card-body">
External Training Records:
</div>
</div>
<div class="card">
<div class="card-header">Clients</div>
<div class="card-body">
Clients:
</div>
</div>
</div>
<div class="col-md-8 offset-md-4"></div>
<div class="col-md-8 offset-md-4">
<div class="card">
<div class="card-header">Site</div>
<div class="card-body">Sites</div>
</div>
</div>
</div>
</div>

convert table to div as per bootstrap v4 beta

I am using bootstrap v4 beta. I have created a table. How can i create the same table using div.
<div class="container">
<table class="table">
<thead>
<tr>
<th>#</th>
<th class="text-center"><b>Id</b></th>
<th class="text-center"><b>Name</b></th>
<th class="text-center"><b>Munit</b></th>
</tr>
</thead>
<tbody>
<tr>
<td> 1</td>
<td class="text-center"> 294</td>
<td class="text-center"> nimai</td>
<td class="text-center"> kg</td>
</tr>
<tr>
<td> 2</td>
<td class="text-center"> 200</td>
<td class="text-center"> nitai</td>
<td class="text-center"> kg</td>
</tr>
</tbody>
</table>
</div>
I also want the same format it looks like in the below picture:
You can make that easily using flexbox
.table {
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
}
.table-row {
width: 100%;
height: 10vw;
display: flex;
border-bottom: 1px solid #ccc;
}
.table-header {
font-weight: bold;
}
.table-row div:first-child {
width: 10% !important;
}
.table-row-column {
width: 30%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
<div class="container">
<div class="table">
<div class="table-row table-header">
<div class="table-row-column table-row-index">#</div>
<div class="table-row-column table-center">Id</div>
<div class="table-row-column table-center">Name</div>
<div class="table-row-column table-center">Munit</div>
</div>
<div class="table-row">
<div class="table-row-column table-row-index">1</div>
<div class="table-row-column table-center">294</div>
<div class="table-row-column table-center">nimai</div>
<div class="table-row-column table-center">kg</div>
</div>
<div class="table-row">
<div class="table-row-column table-row-index">2</div>
<div class="table-row-column table-center">200</div>
<div class="table-row-column table-center">nitai</div>
<div class="table-row-column table-center">kg</div>
</div>
</div>
</div>
Try this
.col {
display: inline-block;
}
row {
display: block;
}
<div class="row">
<div class="col">
<div>First column</div>
<div> 1</div>
<div> 2</div>
<div>3</div>
</div>
<div class="col">
<div>Second column</div>
<div>1</div>
<div>2</div>
<div>3</div>
</div>
<div class="col">
<div>Third column</div>
<div>1</div>
<div>2</div>
<div>3</div>
</div>

Align CSS content

I have the following panel:
And what I want is to centralize the circle charts inside the td of my table and keep it centralized when it turns to mobile. I'm having some issues trying to do that. This is how my code is:
<div class="portlet-body row">
<div class="col-lg-12">
<h3 class="nome-rv"><i class="fa fa-user"></i> <?=$_SESSION['nomeCompleto']?></h3>
</div>
<div class="col-lg-4 col-sm-12">
<table class="table table-bordered tabela-meta">
<tbody>
<tr>
<td class="grafico-situacao">
<div class="c100 p100 orange big">
<span>100%</span>
<div class="slice">
<div class="bar"></div>
<div class="fill"></div>
</div>
</div>
</td>
</tr>
<tr>
<td>PISO</td>
</tr>
<tr>
<td>3.500</td>
</tr>
</tbody>
</table>
</div>
<div class="col-lg-4 col-sm-12">
<table class="table table-bordered tabela-meta">
<tbody>
<tr>
<td class="grafico-situacao">
<div class="c100 p82 big">
<span>82%</span>
<div class="slice">
<div class="bar"></div>
<div class="fill"></div>
</div>
</div>
</td>
</tr>
<tr>
<td>META</td>
</tr>
<tr>
<td>3.500</td>
</tr>
</tbody>
</table>
</div>
<div class="col-lg-4 col-sm-12">
<table class="table table-bordered tabela-meta">
<tbody>
<tr>
<td class="grafico-situacao">
<div class="c100 p63 green big">
<span>63%</span>
<div class="slice">
<div class="bar"></div>
<div class="fill"></div>
</div>
</div>
</td>
</tr>
<tr>
<td>SUPERMETA</td>
</tr>
<tr>
<td>3.500</td>
</tr>
</tbody>
</table>
</div>
</div>
There are some classes but I'm not using them by now.
Link to codepen: http://codepen.io/anon/pen/apNrxy
Any suggestion? Thanks!
It's easy to do if you can leverage flexbox (See browser compatibility here).
If you're using Bootstrap version 4, you can just wrap the content with:
<div class="d-flex justify-content-around">...</div>
See the documentation for more information.
If you're using Bootstrap version 3, you can still use the flexbox styles directly:
display: flex;
justify-content: space-around;
Update your CSS to this
.c100 {
position: relative;
font-size: 120px;
width: 1em;
height: 1em;
border-radius: 50%;
/* float: left; */
margin: 0 auto 0.1em auto; /* margin: 0 0.1em 0.1em 0; */
background-color: #cccccc;
}

Put all div in a row

How would you put all of these <div>s in a row?
<div style="background-color: aquamarine; margin:50px">
<div style="background-color: azure;width:25%;">
1
</div>
<div style="background-color: darkolivegreen;width:25%;">
2
</div>
<div style="background-color: darkorange;width:25%;">
3
</div>
<div style="background-color: bisque;width:25%;">
4
</div>
</div>
Use the awesome display:table.
<div style="background-color: aquamarine; margin:50px; display:table">
<div style="background-color: azure;width:25%;display:table-cell">
1
</div>
<div style="background-color: darkolivegreen;width:25%;display:table-cell">
2
</div>
<div style="background-color: darkorange;width:25%;display:table-cell">
3
</div>
<div style="background-color: bisque;width:25%;display:table-cell">
4
</div>
</div>
In fact, you don't even need to specify widths for the inner divs. With table-layout:fixed the browser will automatically calculate the widths and lay it out nicely. :)
Be sure to specify a width on the parent div though.
<div style="background-color: aquamarine; margin:50px; width:100%; display:table; table-layout:fixed">
<div style="background-color: azure;display:table-cell">
1
</div>
<div style="background-color: darkolivegreen;display:table-cell">
2
</div>
<div style="background-color: darkorange;display:table-cell">
3
</div>
<div style="background-color: bisque;display:table-cell">
4
</div>
</div>
you need to use floats
give this four inner divs a class and then use css float: left

CSS display:table-cell with div inside table

How to make display:table-cell style works (or look-alike alternative) if divs with style table-row are inside table cells? (see the link)
http://jsfiddle.net/ELKQg/460/
I'd like the container1 div behave like the container2.
code: (if the link were to become unreachable)
html:
<div id="container1" class="container">
<table>
<tr>
<td>
<div class="row">
<div class="cell">aaaa</div>
<div class="cell expand">b</div>
<div class="cell">c</div>
</div>
</td>
</tr>
<tr>
<td>
<div class="row">
<div class="cell">d</div>
<div class="cell expand">eeeee</div>
<div class="cell">f</div>
</div>
</td>
</tr>
</table>
</div>
<div id="container2" class="container">
<div class="row">
<div class="cell">aaaa</div>
<div class="cell expand">b</div>
<div class="cell">c</div>
</div>
<div class="row">
<div class="cell">d</div>
<div class="cell expand">eeeee</div>
<div class="cell">f</div>
</div>
</div>
css:
.container{width: 500px;overflow:hidden; /* instead of clearfix div */}
div { border:1px solid;padding: 1px;}
.row {display:table-row;}
.cell {display:table-cell;}
.expand{overflow:hidden;width:100%;}
The extra <table> containing your <div>s in .container1 needs to have width: 100%
display: table-cell elements don't necessarily need a containing display: table-row as long as the parent is display: table. Set the .row to that (ideally you'd re-name it, seeing as the rule no longer makes sense)
Fixed and forked your demo:
http://jsfiddle.net/barney/ahMg8/
Use display: table for the parent table before using display:table-cell
Use td's instead of divs inside tr:
<div id="container1" class="container">
<table>
<tr>
<td class="cell">aaaa</td>
<td class="cell expand">b</td>
<td class="cell">c</td>
</tr>
<tr>
<td class="cell">d</div>
<td class="cell expand">eeeee</td>
<td class="cell">f</td>
</tr>
</table>
</div>
Working fiddle

Resources