I'm having trouble with this.
I have a bootstrap 3 site with html like this:
<div class="item-container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="item">
</div>
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="item">
</div>
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="item">
</div>
// and so on...
</div>
</div>
I'd like to make it so that the last "row" (not bootstrap row) of col's get margin-bottom: 0
When device is xs screen size:
.item-container {
.row {
.col-xs-12.col-sm-6.col-md-4 {
margin-bottom: 20px;
#media screen and (max-width: $xs-max) {
&:last-child {
margin-bottom: 0;
}
}
}
}
}
When device is sm screen size:
.item-container {
.row {
.col-xs-12.col-sm-6.col-md-4 {
margin-bottom: 20px;
#media screen and (max-width: $xs-max) {
&:last-child,
&:nth-last-child(2):nth-child(odd) {
margin-bottom: 0;
}
}
}
}
}
That worked fine selecting the last "row".
However, I'm having trouble with the three column rows. Trying to select the last row.
I've made a jsfiddle: https://jsfiddle.net/rx03nan6/
I'm trying to select the red boxes.
<hr /> is just a break line to show you different types of layout it can have depending on the number of boxes.
<br /> please ignore the br tag, I just wanted the show you how it looks like, so please don't look into the HTML in the jsfiddle.
So you need to style only the items on the last row, where each row contains 3 items.
You can't simply select the last 3 items with :nth-last-child(-n + 3) because let's say you have 4 items - that would select items 2,3,4 - when we only want to select item 4.
So we need additional logic here:
1) We always select the last item
2) We only want to select the second last item if it is also item (3n + 2) - 2,5,8,etc.
3) We only want to select the third last item if it is also item (3n + 1) - 1,4,7,etc.
So the selector will look something like this:
li:nth-child(3n + 1):nth-last-child(-n + 3),
li:nth-child(3n + 2):nth-last-child(-n + 2),
li:last-child {
border-color: blue;
}
Here's a Codepen demo
Here's an updated fiddle
Try this solution for number of column like one , two and three column. There is no need to add nth child. this solution depend on parent class like .raw class
.item-container {
.row {
.col-xs-12.col-sm-6.col-md-4 {
margin-bottom: 20px;
}
#media screen and (max-width: $xs-max) {
& > div:last-child {
margin-bottom: 0 !important;
}
}
}
}
Related
How can i display the two links for small screen one after another. Now the two links are left and right. But i want those link one up and another at bottom.
<div className="homeContent">
<div className="content">
<h1>Text</h1>
<div className="pdf">
XX Download
BB Download
</div>
</div>
</div>
#media screen and (max-width:580px){
.homeContent {
h1 {
font-size: 3rem !important;
}
.content {
.pdf {
a {
// one after another
}
}
}
}
}
Adding display:block on a will do what you want, like so (I am using css so that it works here):
#media screen and (max-width: 580px) {
a {
display: block;
}
}
<div className="homeContent">
<div className="content">
<h1>Text</h1>
<div className="pdf">
XX Download
BB Download
</div>
</div>
</div>
I am currently having an issue with styling my two column container, Below piece of code works perfectly for creating a two column grid. My new requirement is to have a horizontal line (<hr>) in between based on some condition.
Would be really helpful if anyone can help me out in solving this.
HTML:
<div class="two-column-container" >
<div *ngFor="let item of list; let i = index" >
<div class="two-column-item">
<div class="attribute-name">
{{item.id}}
</div>
</div>
</div>
</div>
CSS:
two-column-item {
max-width: 375px;
width: 100%;
margin-top: 25px;
}
two-column-container {
#include columnar-flex();
#include media-breakpoint-down(sm) {
min-width: 250px;
}
#include media-breakpoint-between(sm, md) {
min-width: 500px;
}
#include media-breakpoint-up(lg) {
min-width: 980px;
}
}
Existing output
New Requirement
For the following code
<div class="two-column-container" >
<div *ngFor="let item of list; let i = index" >
<div class="two-column-item">
<div class="attribute-name">
{{item.id}}
</div>
<div class="horizontal-line">
<hr>
</div>
</div>
</div>
</div>
CSS:
horizontal-line {
width: 100%;
margin-top: 25px;
}
the output is as shown below. I would like to have horizontal line in two columns.
I have two columns. Desktop:
Mobile:
This is expected behavior, but I want the column on the left "Browse Programs" to show up on top of the left column, not below it. I've tried a few different things, including reversing the order of columns in HTML and using "float-left" (which works, but not a great solution). I've also used col-md-pull and col-md-push but neither is working.
For what it's worth, I'm not using bootstraps 4 and I'd prefer to keep that as is for now.
Place the blocks inside the layout in the order in which they should go on the mobile.
Introduction: Bootstrap is developed mobile first, a strategy in which we optimize code for mobile devices first and then scale up components as necessary using CSS media queries.
Change their order. To do this, Bootstrap 3 provides classes of the type .col-md-push-9 and .col-md-pull-3, and Bootstrap 4 provides the order classes.
Demo for Bootstrap 3: https://codepen.io/glebkema/pen/qBONaQd
/* Demo Decorations */
.row-demo > div {
color: white;
font: bold 20px sans-serif;
padding: 9px 15px 30px;
}
.row-demo > div:first-child {
background: #69c;
}
.row-demo > div:last-child {
background: #c69;
}
<div class="container">
<div class="row row-demo">
<div class="col-md-3 col-md-push-9">Top on mobile / Right on desktop</div>
<div class="col-md-9 col-md-pull-3">Bottom on mobile / Left on desktop</div>
</div>
</div>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet"/>
Demo for Bootstrap 4: https://codepen.io/glebkema/pen/GRpZVZq
/* Demo Decorations */
.row-demo > div {
color: white;
font: bold 20px sans-serif;
padding: 9px 15px 30px;
}
.row-demo > div:first-child {
background: #69c;
}
.row-demo > div:last-child {
background: #c69;
}
<div class="container">
<div class="row row-demo">
<div class="col-md-3 order-md-last">Top on mobile / Right on desktop</div>
<div class="col-md-9 order-md-first">Bottom on mobile / Left on desktop</div>
</div>
</div>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
Using FlexBox and Sass, I am trying to create stacked vertical bars as shown in the images pasted below. What I am expecting is the vertical text to take up the one-columned row, creating a stacking effect. What is happening, though, is the text is overlapping.
The html mark up is like so:
<div class="container__row">
<div class="container__col-sm-12 container__col-md-6 container__col-md-6">
<h1>Another section</h1>
</div>
<div class="container__col-sm-12 container__col-md-6 container__col-md-6">
<div class=container__row>
<div class="container__col-sm-12 container__col-md-12 container__col-md-12 skills-bar">
Front-End Technologies
</div>
</div>
<div class=container__row>
<div class="container__col-sm-12 container__col-md-12 container__col-md-12 skills-bar">
Front-End Technologies
</div>
</div>
<div class=container__row>
<div class="container__col-sm-12 container__col-md-12 container__col-md-12 skills-bar">
Design
</div>
</div>
<div class=container__row>
<div class="container__col-sm-12 container__col-md-12 container__col-md-12 skills-bar">
GIS
</div>
</div>
</div>
<div class="container__row">
This is the Sass .scss code that makes up the css styling:
//site container with set max width
$grid__bp-md: 768;
$grid__bp-lg: 992;
$grid__cols: 12;
//sass map to define breakpoints
$map-grid-props: ('-sm':0, '-md': $grid__bp-md, '-lg' : $grid__bp-lg);
//mixin to dynamically create media query for each breakpoint
#mixin create-mq($breakpoint) {
#if($breakpoint == 0) {
#content;
} #else {
#media screen and (min-width: $breakpoint *1px) {
#content;
}
}
}
#mixin create-col-classes($modifier, $grid__cols, $breakpoint) {
#include create-mq($breakpoint) {
//class to set up columns for all screen sizes - mobile first
#for $i from 1 through $grid__cols {
&__col#{$modifier}-#{$i} {
flex-basis: (100 / ($grid__cols / $i)) * 1%;
}
}
}
}
.container {
max-width: $grid__bp-md * 1px;
margin: 0 auto;
//attribute to override max width
&--fluid {
margin: 0;
max-width: 100%;
}
//attribute to position row's child elements. remove overflow with wrap and 100% width for nesting
&__row {
display: flex;
flex-wrap: wrap;
width: 100%;
}
#each $modifier, $breakpoint in $map-grid-props {
#include create-col-classes($modifier, $grid__cols, $breakpoint);
}
}
p {
font-size: .85em;
color: #aaa;
}
}
.skills-bar {
transform: rotate(90deg);
transform-origin: left top 0;
float: left;
}
There is this strange overlap that happens. Can anyone suggest why the vertical text won't make rows?
If you look in the inspector, you can see that the original height of the container isn't being effected by the transform and that's why this is happening. I can't think of a way around it without measuring the new height after the transform with js.
I'm not sure what browsers you need to support, but text-orientation / writing-mode will do, mostly, what you need without js.
.skills-bar {
writing-mode: sideways-lr; // only supported in FF, use 'vertical-lr' for more support
text-orientation: upright;
float: left;
}
https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode
https://developer.mozilla.org/en-US/docs/Web/CSS/text-orientation
In order to measure the divs after the css transform, I used getBoundingClientRect().
With a few lines of jquery, I got what I needed:
$(document).ready(function(){
var skills = $(".skills-bar")
$.each(skills, function(i, div) {
console.log(div);
var dimensions = div.getBoundingClientRect();
console.log(dimensions);
$(this).css("width", dimensions.width).css("height", dimensions.height);
});
});
I have a html template like the following:
<div class="my-grid-container">
<div class="summary-card" ng-repeat="cardData in summaryCardsCtrl.summaryDetails" >
<div ng-include="'.....'"></div>
</div>
</div>
The included html looks like:
<div class="card">
<div class="card-title" id="{{cardData.label}}">{{cardData.label}}</div>
<div class="card-data">
<div class="card-ico">
.....
</div>
<div class="card-value">
<span title="{{cardData.rawValue}}">{{cardData.value}}</span>
<span>%</span>
</div>
</div>
</div>
I want the first card to span for two rows, like:
I am using CSS3 GridBox like the following:
.my-grid-container {
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 10px;
padding: 10px;
}
.my-grid-container > div {
text-align: center;
padding: 20px 0;
font-size: 30px;
max-height: 70px;
}
div.my-grid-container > div.card:first-child {
grid-row: 1 / 2;
}
But it did not work till now. First div did not span two rows.
What am I doing wrong?
Your code:
div.my-grid-container > div.card:first-child {
grid-row: 1 / 2;
}
You're telling the grid item to span from grid row line 1 to grid row line 2. That spans one row.
If you want to span two rows, then use this instead:
div.my-grid-container > div.card:first-child {
grid-row: 1 / 3;
}
or this:
div.my-grid-container > div.card:first-child {
grid-row: 1 / span 2;
}
Keep in mind that in every grid the number of row lines is equal to the number of rows + 1, because the last row has an extra (final) line. The same concept applies to columns.
Firefox offers a useful tool for seeing this.
In Firefox dev tools, when you inspect the grid container, there is a tiny grid icon in the CSS declaration. On click it displays an outline of your grid.
More details here: https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to/Examine_grid_layouts