Bootstrap nested row margin top/bottom - css

I am trying to build an application that has a metro interface.
Rows are stacked like columns and the children are tiled.
in bootstrap rows have a margin-left of -15px and the same for the right. I have then added 15px padding to the .row. My columns then have a margin of 15px all around. So, I have to make my margin-top: -15px and the padding-top: 15px on my row (aswell as the bottom).
All this should give me exactly 30px between every column and row. The problem is when I nest, it all goes to pot.
My CSS looks like this:
.metro {
width: 10000px;
}
.metro .row-title {
position: absolute;
height: 100px;
top: -50px;
}
.metro > .row {
position: relative;
float: left;
height: 630px;
margin-top: -15px;
margin-right: -15px;
padding: 15px;
}
.metro > .row .row {
padding: 0;
}
.metro > .row > .col-md-1 {
width: 75px;
}
.metro > .row > .col-md-2 {
width: 150px;
}
.metro > .row > .col-md-3 {
width: 225px;
}
.metro > .row > .col-md-4 {
width: 300px;
}
.metro > .row > .col-md-5 {
width: 375px;
}
.metro > .row > .col-md-6 {
width: 450px;
}
.metro > .row > .col-md-7 {
width: 525px;
}
.metro > .row > .col-md-8 {
width: 600px;
}
.metro > .row > .col-md-9 {
width: 675px;
}
.metro > .row > .col-md-10 {
width: 750px;
}
.metro > .row > .col-md-11 {
width: 825px;
}
.metro > .row > .col-md-12 {
width: 900px;
}
.flex {
display: -webkit-box;
/* Safari */
display: flex;
/*> div {
-webkit-box-flex: 1;
flex-basis: auto;
flex-grow: 1;
flex-shrink: 1;
}*/
}
.flex.flex-wrap {
-ms-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
.flex.flex-vertical {
-ms-flex-direction: column;
-webkit-flex-direction: column;
flex-direction: column;
}
.row div[class*="col-"] {
padding-top: 15px;
padding-bottom: 15px;
}
[class*="col-"] > div:not(.row):not(.alert),
[class*="col-"] > a,
[class*="col-"] > form {
display: block;
background-color: #3C60EF;
padding: 10px;
height: 100%;
}
[class*="col-"] > div:not(.row):not(.alert) .form-group:last-child,
[class*="col-"] > a .form-group:last-child,
[class*="col-"] > form .form-group:last-child {
margin-bottom: 0;
}
and the HTML that is messing up is this:
<div class="container metro">
<div class="row">
<div class="col-xs-12 row-title">
<h1>Login</h1>
</div>
<div class="col-md-12">
<div class="row flex flex-vertical">
<div class="col-md-12">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="box-shadow">
<p>
Some welcome text
</p>
</div>
<div class="row">
<div class="col-md-12">
<div>
<p>Nesting</p>
</div>
<div class="row">
<div class="col-md-12">
<div>
<p>Nesting</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="box-shadow">
<p>Disclaimer</p>
</div>
</div>
</div>
</div>
<form class="col-md-12" name="loginForm" role="form">
<div class="box-shadow">
<div class="form-group">
<input class="form-control" type="text" id="userName" placeholder="Enter Username" required="" ng-model="controller.user.userName">
</div>
<div class="form-group">
<input class="form-control" type="password" id="password" placeholder="Enter Password" required="" ng-model="controller.user.password">
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit" ng-disabled="loginForm.$invalid" ng-click="controller.loginUser()">Login</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div>
<p>Another nested row</p>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
I have created a codepen where you can see my issue:
http://codepen.io/r3plica/pen/ojNVeX
does anyone know how I can achieve this?

I managed to do this myself
Basically I just started with the default bootstrap and then played around until I got my desired results.
Here is the CSS that I changed:
.metro > .row {
background-color: red;
padding-left: 15px;
padding-right: 15px;
padding-bottom: 30px;
}
.metro > .row .row {
background-color: orange;
}
.metro > .row .row .row {
background-color: yellow;
}
.row div[class*="col-"] {
border: 1px dashed black;
}
.row [class*="col-"] > div:not(.row),
.row [class*="col-"] > form,
.row [class*="col-"] > a {
background-color: blue;
padding: 15px;
margin-top: 30px;
}
There was no need to add anything else, this solved all my issues.

If I got your question right, you want to create a metro-style UI. Here's a snippet which could be the base for this. As I mentioned in a comment above, do not use bootstrap rows as columns.
body, html {
height: 100%;
}
.metro {
width: 10000px;
height: 100%;
padding-left: 15px;
padding-right: 15px;
}
.metro .page {
width: 100vw;
height: 100%;
display: flex;
flex-direction: column;
float: left;
}
.content {
flex: 1;
}
.content-login {
background-color: #f0f0f0;
}
.content-page2 {
background-color: #e0e0e0;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="metro">
<div class="page">
<h1>Login</h1>
<div class="row content content-login">
Content
</div>
</div>
<div class="page">
<h1>Page 2</h1>
<div class="row content content-page2">
Content
</div>
</div>
</div>

Related

How to make adaptive centered div?

What I have now:
display: flex;
align-items: center;
flex-direction: column;
How it looks with error:
What's the target:
I can do it with
margin-left: *X*px, but it is not the way I want to solve it.
May I do it with some flex properties ?
It is important to do it without bootstrap and grid.
This could be a possible solution: Center the box with flexbox and display the errors with position: absolute;. You need to take care of responsive optimization if you want to use it on a wider range of devices.
* {
box-sizing: border-box;
}
.container {
display: flex;
align-items: center;
justify-content: center;
}
.box {
border: 1px solid black;
padding: 10px;
width: 400px;
}
.field {
position: relative;
}
.input {
margin-bottom: 10px;
width: 100%;
}
.error {
position: absolute;
left: 105%;
top: 0;
width: 200px;
}
<div class="container">
<div class="box">
<div class="field">
<input class="input" type="text">
<div class="error">error 1</div>
</div>
<div class="field">
<input class="input" type="text">
<div class="error">error 2</div>
</div>
<button>Send</button>
</div>
</div>

ngFor Elements in Row

Hello currently I'm trying to display my items from ngFor in a row, but it's not working.
My Code:
<ng-container>
<div class="model" *ngFor="let model of modelService;" >
<div id="Ppicture" > {{model.modelPic}} </div>
<div id="Name" > {{model.modelName}} </div>
<div id="Age"> {{model.modelAge}} </div>
</div>
</ng-container>
CSS:
ng-container{
display: flex;
flex-direction: row;
}
.model{
padding-left: 10px;
padding-top: 10px;
border: solid 1px;
height: 150px;
width: 150px;
justify-content: center;
text-align: center;
}
I also tried to put display flex into the .model class, but flex is only putting the text in a row, not the boxes.
That's how it looks like
https://ibb.co/VLSKVcS
try to put width: 100% in ng-container.
ng-container{
width: 100%;
display: flex;
flex-direction: row;
}
Try this
<ng-container>
<div class="model_sec">
<div class="model" *ngFor="let model of modelService;" >
<div id="Ppicture" > {{model.modelPic}} </div>
<div id="Name" > {{model.modelName}} </div>
<div id="Age"> {{model.modelAge}} </div>
</div>
</div>
</ng-container>
ng-container {
display: block;
width: 100%;
}
.model {
padding-left: 10px;
padding-top: 10px;
border: solid 1px;
height: 150px;
width: 150px;
text-align: center;
}
.model_sec {
display: flex;
width: 100%
}

css table : first column with fixed width

I'm trying to create a css table.
This was working fine, until I started to set a fixed width for the first column.
So basically I have:
<div class="table" style="width:100%;">
<div class="thead">
<div class="table-row">
<div class="table-cell" style="display:flex;align-items:center;min-width: 180px;max-width:180px;">Type</div>
<div class="table-cell">Motif</div>
<div class="table-cell">col3</div>
<div class="table-cell">col4</div>
<div class="table-cell">col5</div>
<div class="table-cell">col6</div>
<div class="table-cell">col7</div>
<div class="table-cell">col8</div>
<div class="table-cell">col9</div>
</div>
</div>
<div class="tbody">
<div class="table-row" ng-repeat="input in vm.inputs">
<div class="table-cell" ng-mouseover="vm.hoverIn(input)" ng-mouseleave="vm.hoverOut(input)" style="display:flex;align-items:center;min-width: 180px;max-width:180px;">
{{input.type}}
</div>
<div class="table-cell">{{input.reason}}</div>
<div class="table-cell">{{input.cim10}}</div>
<div class="table-cell">{{input.start | date:'dd/MM/yyyy' }}</div>
<div class="table-cell">{{input.end | date:'dd/MM/yyyy'}}</div>
<div class="table-cell">{{vm.computeDays(input.start, input.end)}}</div>
<div class="table-cell">{{input.pending}}</div>
<div class="table-cell">{{input.details}}</div>
<div class="table-cell">{{input.comments}}</div>
</div>
</div>
</div>
with the following css:
div.table {
display: table;
}
div.table > div.thead {
display: table-header-group;
background-color:lightgray;
}
div.table > div.tbody {
display: table-row-group;
}
div.table > div.thead > div.table-row,
div.table > div.tbody > div.table-row {
display: table-row;
}
div.table > div.thead > div.table-row > div.table-cell {
display: table-cell;
font-weight: bold;
padding: 3px 10px;
border: 1px solid #999999;
}
div.table > div.tbody > div.table-row > div.table-cell {
display: table-cell;
padding: 3px 10px;
border: 1px solid #999999;
height: 42px;
text-align: left;
vertical-align: middle;
}
Now, the result is this:
As you can see the second column is no more aligned with the first one.
I think the problem is not the fixed width, but the display: flex; you're adding inline, it's overriding display: table-cell;.
You might want to use display: flex; in the inner content of your tab.
div.table {
display: table;
}
div.table > div.thead {
display: table-header-group;
background-color:lightgray;
}
div.table > div.tbody {
display: table-row-group;
}
div.table > div.thead > div.table-row,
div.table > div.tbody > div.table-row {
display: table-row;
}
div.table > div.thead > div.table-row > div.table-cell {
display: table-cell;
font-weight: bold;
padding: 3px 10px;
border: 1px solid #999999;
}
div.table > div.tbody > div.table-row > div.table-cell {
display: table-cell;
padding: 3px 10px;
border: 1px solid #999999;
height: 42px;
text-align: left;
vertical-align: middle;
}
<div class="table" style="width:100%;">
<div class="thead">
<div class="table-row">
<div class="table-cell" style="min-width: 100px;max-width:180px;">Type</div>
<div class="table-cell">Motif</div>
<div class="table-cell">col3</div>
<div class="table-cell">col4</div>
<div class="table-cell">col5</div>
<div class="table-cell">col6</div>
<div class="table-cell">col7</div>
<div class="table-cell">col8</div>
<div class="table-cell">col9</div>
</div>
</div>
<div class="tbody">
<div class="table-row" ng-repeat="input in vm.inputs">
<div class="table-cell" ng-mouseover="vm.hoverIn(input)" ng-mouseleave="vm.hoverOut(input)" style="min-width: 100px;max-width:180px;">
{{input.type}}
</div>
<div class="table-cell">{{input.reason}}</div>
<div class="table-cell">{{input.cim10}}</div>
<div class="table-cell">{{input.start | date:'dd/MM/yyyy' }}</div>
<div class="table-cell">{{input.end | date:'dd/MM/yyyy'}}</div>
<div class="table-cell">{{vm.computeDays(input.start, input.end)}}</div>
<div class="table-cell">{{input.pending}}</div>
<div class="table-cell">{{input.details}}</div>
<div class="table-cell">{{input.comments}}</div>
</div>
</div>
</div>
Fixed in this fiddle
Issue is the display:flex attribute in your html :
<div class="table-cell" style="display:flex;align-items:center;min-width: 180px;max-width:180px;">Type</div>
Min-width is still applied, and table's behaviour is back to normal.

Resize the header and content div dimensions respond when the window size changes but maintain right sidebar dimensions

I am trying to use a flexbox approach to create a layout that will resize the header width and content dimensions when a window is resized, but maintain the sidebar dimensions.
I found the following example from this Flexbox Approach to get me started, and it works as desired for the content div itself. But after looking it over, I'm unsure how to make it work as described with a fixed width, 100% height sidebar.
CSS from example:
<style>
html, body {
height: 100%;
margin: 0
}
.box {
display: flex;
flex-flow: column;
height: 100%;
}
.box .row {
border: 1px dotted grey;
}
.box .row.header {
flex: 0 1 auto; /* The above is shorthand for: flex-grow: 0, flex-shrink: 1, flex-basis: auto */ }
.box .row.content {
flex: 1 1 auto;
}
.box .row.footer {
flex: 0 1 40px;
}
</style>
HTML from example:
<div class="row header">
<p><b>header</b> <br /> <br />(sized to content)</p>
</div> <div class="row content">
<p> <b>content</b> (fills remaining space) </p>
</div>
<div class="row footer">
<p><b>footer</b> (fixed height)</p>
</div>
</div>
The following codepen example gave me the information I needed to get my layout working:
http://codepen.io/JosephSilber/pen/HqgAz
CSS:
.header {
height: 50px;
}
.body {
position: absolute;
top: 50px;
right: 0;
bottom: 0;
left: 0;
display: flex;
}
.sidebar {
width: 140px;
}
.main {
flex: 1;
display: flex;
flex-direction: column;
}
.content {
flex: 1;
display: flex;
overflow: auto;
}
.box {
min-height: -webkit-min-content;
display: flex;
}
.column {
padding: 20px;
border-right: 1px solid #999;
}
.column > div {
height: 2000px;
background: red;
}
.column:nth-child(2) > div {
height: auto;
}
/* All of these are just for this demo's design. */
body {
font-family: sans-serif;
font-size: 20px;
line-height: 50px;
text-transform: uppercase;
font-weight: bold;
}
.header {
text-align: center;
color: #fff;
background: #444;
}
.sidebar {
background: #666;
padding: 4px 20px;
color: #fff;
}
.page-header {
padding: 6px 20px;
background: #004141;
color: #fff;
font-size: .8em;
}
.content {
background: #ddd;
}
HTML:
<div class="header">Main header</div>
<div class="body">
Move this: <div class="sidebar">Sidebar</div>
<div class="main">
<div class="page-header">Page Header. Content columns are below.</div>
<div class="content">
<div class="box">
<div class="column">
<div>Column 1</div>
</div>
<div class="column">
<div>Column 1</div>
</div>
<div class="column">
<div>Column 1</div>
</div>
</div>
</div>
</div>
To here: <div class="sidebar">Sidebar</div>
</div>
To get the sidebar on the right side, I simply moved <div class="sidebar">Sidebar</div>to just above the closing div tag for the .body class.

CSS How do I force a container to be displayed underneath a preceding container whose elements float left

I want the div which displays "D" to appear beneath that one which displays "A" so that divs with matching background colours appear stacked over one another. However, I am getting this:
Where exactly in my CSS code must I clear my float?
#container {
background-color: #333333;
width: 990px;
}
#left {
background-color: red;
width: 300px;
float: left;
}
#splitter {
background-color: green;
width: 90px;
float: left;
}
#right {
background-color: blue;
width: 200px;
float: left;
}
<div id="container">
<div id="left">A</div>
<div id="splitter">B</div>
<div id="right">C</div>
</div>
<div id="container">
<div id="left">D</div>
<div id="splitter">E</div>
<div id="right">F</div>
</div>
You have to deal with floats and for this you need to understand what floats and BFC are :
a few ways to do this, that you should understand once you been reading a bit about floats, clearing and Block formating context.
(last example in the snippet below, oldish, even avoids the floats but does the layout)
/* DEMO purpose : Show the id or class being used on that container*/
section:before {
content: attr(id)' 'attr(class);
display: table;
background: #177EE5;
padding: 5px;
margin: 5px;
color: #fff;
text-shadow: 0 0 1px black, 0 0 1px black, 0 0 1px black, 0 0 1px black, 0 0 1px black, 0 0 1px black;
letter-spacing: 1px;
font-variant: small-caps;
}
/* your css turned into class to be valid since used for many tags */
.container {
background-color: #333333;
width: 990px;
}
.left {
background-color: red;
width: 300px;
float: left;
}
.splitter {
background-color: green;
width: 90px;
float: left;
}
.right {
background-color: blue;
width: 200px;
float: left;
}
/* wrapper for each examples */
section {
clear: both;
overflow: hidden;
margin: 1em;
}
/* different ways shown, usefull for testing only if you read about floats and dig a bit */
/* table */
.table .container {
display: table;
}
/* overflow */
.overflow .container {
overflow: hidden;
}
/* float */
.float .container {
float: left;
}
/* flex */
.flex .container {
display: flex;
}
/* inline-block */
.inline-block .container {
display: inline-block;
vertical-align: top;
}
/* last examples without floats */
/*no float & ie8 */
#table div {
float: none
}
#table #first-row,
#table > div {
display: table-row;
}
#table > div > div {
display: table-cell;
}
#table {
background-color: #333333;
width: 990px;
table-layout: fixed;
}
#left {
width: 300px;
}
#splitter {
width: 90px;
}
#right {
width: 200px;
}
#table > div > div {
background-color: red;
}
#table > div > div + div {
background-color: green;
}
#table > div > div + div + div {
background-color: blue;
}
#table:before {
display: table-caption;
width: 100%;
margin: 0;
}
#table > div:after {
content: "Notice there's a gap to fill here since cols do not cover the 990px";
display: table-cell;
}
<section class="your CSS :-: no BFC involved">
<div class="container">
<div class="left">A</div>
<div class="splitter">B</div>
<div class="right">C</div>
</div>
<div class="container">
<div class="left">D</div>
<div class="splitter">E</div>
<div class="right">F</div>
</div>
</section>
<section class="table">
<div class="container">
<div class="left">A</div>
<div class="splitter">B</div>
<div class="right">C</div>
</div>
<div class="container">
<div class="left">D</div>
<div class="splitter">E</div>
<div class="right">F</div>
</div>
</section>
<section class="overflow">
<div class="container">
<div class="left">A</div>
<div class="splitter">B</div>
<div class="right">C</div>
</div>
<div class="container">
<div class="left">D</div>
<div class="splitter">E</div>
<div class="right">F</div>
</div>
</section>
<section class="float">
<div class="container">
<div class="left">A</div>
<div class="splitter">B</div>
<div class="right">C</div>
</div>
<div class="container">
<div class="left">D</div>
<div class="splitter">E</div>
<div class="right">F</div>
</div>
</section>
<section class="flex">
<div class="container">
<div class="left">A</div>
<div class="splitter">B</div>
<div class="right">C</div>
</div>
<div class="container">
<div class="left">D</div>
<div class="splitter">E</div>
<div class="right">F</div>
</div>
</section>
<section class="inline-block">
<div class="container">
<div class="left">A</div>
<div class="splitter">B</div>
<div class="right">C</div>
</div>
<div class="container">
<div class="left">D</div>
<div class="splitter">E</div>
<div class="right">F</div>
</div>
</section>
<p>another way without float including IE8 ?</p>
<section id="table" class="table">
<div id="first-row">
<div id="left">A</div>
<div id="splitter">B</div>
<div id="right">C</div>
</div>
<div>
<div>D</div>
<div>E</div>
<div>F</div>
</div>
</section>
There could be more examples from the same chunks of code and floatting children.
Clear the floats in the container.
You have 3 simple ways to do that:
1. Float
#container {
clear: both;
}
2. Overflow
#container {
overflow: hidden;
}
3. Micro clearfix hack
Link
Here is what you want done bro..
this one is by using display:inline-block https://jsfiddle.net/p4domjrb/
this one is by using float:left https://jsfiddle.net/p4domjrb/1/
.container {
background-color: #333333;
width: 990px;
display: block;
position: relative;
}
.left {
background-color: red;
width: 300px;
display: inline-block;
margin-left: -4px;
}
.splitter {
background-color: green;
width: 90px;
display: inline-block;
margin-left: -4px;
}
.right {
background-color: blue;
width: 200px;
display: inline-block;
margin-left: -4px;
}
don't use id I suggest use class isntead because idis called only once.
<style>
.container{
background-color: #333333;
width:990px;
display:block;
clear:both;
}
#left{
background-color: red;
width:300px;
float:left;
}
#splitter{
background-color: green;
width:90px;
float:left;
}
#right{
background-color: blue;
width: 200px;
float:left;
}
</style>
<body>
<div class="container">
<div id="left">A</div>
<div id="splitter">B</div>
<div id="right">C</div>
</div>
<div class="container">
<div id="left">D</div>
<div id="splitter">E</div>
<div id="right">F</div>
</div>
</body>
result is

Resources