Here is my html:
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 div1">DIV1</div>
<div class="col-sm-6 div2">DIV2</div>
<div class="col-sm-6 div3">DIV3</div>
<div class="col-sm-6 div4">DIV4</div>
</div>
</div>
Here is my css:
.row div{
height: 100px;
}
.div1{
background: blue;
}
.div2{
background: red;
}
.div3{
background: darkcyan;
}
.div4{
background: cyan;
}
Its ok in normal view
Is it possible to alter div4 with div3 on mobile view like below image
You can swap the color of div3 and div4 using media query for mobile min-width: 767px
.row div{
height: 100px;
}
.div1{
background: blue;
}
.div2{
background: red;
}
.div3{
background: darkcyan;
}
.div4{
background: cyan;
}
#media(max-width:767px){
.div3{
background: cyan;
}
.div4{
background: darkcyan;
}
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 div1"></div>
<div class="col-sm-6 div2"></div>
<div class="col-sm-6 div3"></div>
<div class="col-sm-6 div4"></div>
</div>
</div>
Related
Im trying to add hover to my grid.
I literally manage to do so for every single cell including the whole div, but when im trying to do for the whole row nothing happens! (IGNORE please the colorful rows at the start)
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="test.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-12 text-lg-start text-start text-sm-right text-md-start col-sm-12 col-md-6 col-lg-3">Make</div>
<div class="col-12 text-lg-center text-center text-sm-center text-md-center col-sm-12 col-md-6 col-lg-3">Things</div>
<div class="col-12 text-lg-center text-center text-sm-center text-md- center col-sm-6 col-md-6 col-lg-3">Go</div>
<div class="col-12 text-lg-end text-end text-sm-end col-sm-6 col-md-6 text-md-end col-lg-3 ">Right</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div id="dif" class="col">animal</div>
<div id="dif" class="col">price</div>
<div id="dif" class="col">image</div>
</div>
<div class="row">
<div id="td" class="col">kitten</div>
<div id="td" class="col">70$</div>
<div id="td" class="col"> <img src="https://s3.eu-central-1.amazonaws.com/bootstrapbaymisc/blog/24_days_bootstrap/sheep-3.jpg" class="img-fluid img-circle " class="rounded" alt="Sheep"></div>
</div>
<div class="row">
<div id="td" class="col">puppy</div>
<div id="td" class="col">80$</div>
<div id="td" class="col"> <img src="https://s3.eu-central-1.amazonaws.com/bootstrapbaymisc/blog/24_days_bootstrap/sheep-3.jpg" class="img-fluid img-thumbnail" alt="Sheep"></div>
</div>
<div class="row">
<div id="td" class="col">bunny</div>
<div id="td" class="col">30$</div>
<div id="td" class="col"> <img src="https://s3.eu-central-1.amazonaws.com/bootstrapbaymisc/blog/24_days_bootstrap/sheep-3.jpg" class="img-fluid img-thumbnail" alt="Sheep"></div>
</div>
</div>
</body>
</html>
CSS:
.row {
margin-bottom: 10px;
}
.row > div {
height: 50px;
font-size: x-large;
text-align: center;
}
.row > div:nth-child(1) {
background: red
}
.row > div:nth-child(2) {
background: yellow
}
.row > div:nth-child(3) {
background: blue
}
.row > div:nth-child(4) {
background: purple
}
#dif {
background:white;
font-weight: 900;
border: solid black 1px;
height: 150px;
}
#td {
height: 150px;
background:white;
border: solid black 1px;
margin: 0px;
}
.row {
margin: 0px
}
.row:hover{background-color:gray;}
img {
border-radius: 50%;
}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Remove the following code and the rows will highlight in grey:
.row > div:nth-child(1) {
background: red
}
.row > div:nth-child(2) {
background: yellow
}
.row > div:nth-child(3) {
background: blue
}
.row > div:nth-child(4) {
background: purple
}
Remove background:white; from
#td {
height: 150px;
background:white;
border: solid black 1px;
margin: 0px;
}
I have two columns and each column contains two blocks
The current order in mobile is
1
2
3
4
And I want it to be :
3
1
2
4
I tried to use grid but I don't know how I can get block 3 out from column 2.
See:
body {
padding-top: 50px;
}
.block {
padding: 40px;
text-align: center;
}
.y{
background:yellow;
}
.r{
background:red;
}
.b{
background:lightblue;
}
.g{
background:lightgreen;
}
#media only screen and (max-width: 991px) {
.container {
display: grid;
background-color: pink;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="col-md-8">
<div class="block y"> 1</div>
<div class="block r">2 </div>
</div>
<div class="col-md-4">
<div class="block b"> 3</div>
<div class="block g">4 </div>
</div>
</div>
And another question can we did this ordering by using CSS supported by IE11? because display:grid is not supported by IE.
Change the layout a little and you will be able to achieve this using bootstrap classes (https://getbootstrap.com/docs/4.3/utilities/flex/#order) without the need of CSS grid:
body {
padding-top: 50px;
}
.block {
padding: 40px;
text-align: center;
}
.y {background: yellow;}
.r {background: red;}
.b {background: lightblue;}
.g {background: lightgreen;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-8 order-1 order-md-0">
<div class="block y"> 1</div>
</div>
<div class="col-md-4 order-0 order-md-1">
<div class="block b"> 3</div>
</div>
</div>
<div class="row">
<div class="col-md-8">
<div class="block r">2 </div>
</div>
<div class="col-md-4">
<div class="block g">4 </div>
</div>
</div>
</div>
With you current code, the only way is to use display:contents which is not well supported (https://caniuse.com/#feat=css-display-contents)
body {
padding-top: 50px;
}
.block {
padding: 40px;
text-align: center;
}
.y {
background: yellow;
}
.r {
background: red;
}
.b {
background: lightblue;
}
.g {
background: lightgreen;
}
#media only screen and (max-width: 991px) {
.container {
background-color: pink;
display:flex;
flex-direction:column;
padding:0!important;
}
.container > .row,
.container > .row > div{
display:contents;
}
.b {
order:-1;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="block y"> 1</div>
<div class="block r">2 </div>
</div>
<div class="col-md-4">
<div class="block b"> 3</div>
<div class="block g">4 </div>
</div>
</div>
</div>
I want to have two columns which fills up every time the full page size unattached from the given content.
The problem is that my solutions work until I began to scroll the page.
Example
html,body {
height: 100%;
min-height: 100%;
}
.left-content {
background: red;
}
.right-content {
background: green;
}
.container-fluid {
height: 100%;
}
.row {
height: 100%;
}
[class^="col-"] {
height: 100%;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 left-content">
LEFT COLUMN
</div>
<div class="col-sm-6 right-content">
RIGHT COLUMN
</div>
</div>
</div>
Anyone have a solution for this problem?!
How about adding col-xs-6 that accommodates extra small screens as well:
html,body {
height: 100%;
min-height: 100%;
}
.left-content {
background: red;
}
.right-content {
background: green;
}
.container-fluid {
height: 100%;
}
.row {
height: 100%;
}
[class^="col-"] {
height: 100%;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-xs-6 left-content">
LEFT COLUMN
</div>
<div class="col-md-6 col-xs-6 right-content">
RIGHT COLUMN
</div>
</div>
</div>
http://jsfiddle.net/meh/tdmdunpn/1/
.c1:hover {background-color: #b00806}
I wish to have all cells of this flex table (not an actual table) with the class .c1 to change background colour to the lighter red colour when any one element with the class .c1 is hovered.
I am looking to use pure CSS without JS but I am willing to use if necessary.
Please do not suggest using an actual table, as that is inconvenient for my purposes.
You will need Javascript to do that.
If you're interested in Jquery I would probably manage it by toggling a new class based on an existing selector.
.slide:hover, .slideHover {
background-color: rgba(176,8,6,0.45);
}
$( ".c1" ).hover(function() {
$(".c1" ).toggleClass("slideHover");
});
JSFiddle Demo
$( ".c1" ).hover(function() {
$(".c1" ).toggleClass("slideHover");
});
#slider {
clear: both;
width: 100%; margin-left: auto; margin-right: auto;
height: 250px;
display: flex;
flex: 0 1 auto;
flex-direction: column;
flex-wrap: no-wrap;
background-color: white;
box-sizing: border-box;
}
.slide {
height: 100%;
min-width: 100%;
width: 33.3%;
border: thin black solid;
border-right: medium black solid;
border-left: medium black solid;
flex-grow: 1;
display: flex;
flex: 0 1 auto;
flex-flow: no-wrap row;
box-sizing: border-box;
}
.slide:hover, .slideHover {
background-color: rgba(176,8,6,0.45);
}
.slide:first-child {
border-bottom: medium #b00806 solid;
border-top: medium black solid;
}
.slide:last-child {
border-bottom: medium black solid;
}
.row {
border-right: thin black solid;
flex-grow: 1;
box-sizing: border-box;
}
.row:first-child {
flex-grow: 3;
}
.row:nth-child(2) {
flex-grow: 2;
}
.row:nth-child(3) {
flex-grow: 2;
}
.row:last-child {
border-right: none;
}
.row:hover {
background-color: rgba(143,6,4,0.48);
}
.tab1text {
line-height: 100%;
width: 100%;
padding: 5px;
}
.row {
width: 1px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div id="tab-content1" class="tab-content">
<div id="w1"><div id="slider">
<div class="slide">
<div class="row c1"><a class="tab1text" href=""></a></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
<div class="slide">
<div class="row c1"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
<div class="slide">
<div class="row c1"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
<div class="slide">
<div class="row c1"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
<div class="slide">
<div class="row c1"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
<div class="slide">
<div class="row c1"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
<div class="slide">
<div class="row c1"></div>
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
I think it is not possible using pure css. You can use the following jquery code to achieve this:
$(document).ready(function () {
$(".c1").hover(function () {
$(".c1").css("background-color", "rgba(176,8,6,0.45)");
}, function () {
$(".c1").css("background-color", "white");
});
});
Explanation: When we hover on ".c1", then it will change the background-color to whatever color(say light red color) and on hover out it will change it to 'white' again as specified by the second part of the hover().
See the updated fiddle: "http://jsfiddle.net/tdmdunpn/12/"
I'm building a web page where the search results should appear horizontally aligned. The elements could have different heights.
The examples I'd like to reproduce are:
Google Plus posts layout
Isotope (http://isotope.metafizzy.co).
I tried to use floating elements but you can see my failure in this Plunkr
http://plnkr.co/8ex35N8OraWZBnbE5EoY
Option #1 : nth-child
If you have a fixed number of columns, you can use :
/* Style */
.item { background: yellow; width: 48px; border: 1px solid black; }
.item:nth-child(2n) { background: blue; }
.item:nth-child(3n) { background: red; }
/* Position */
.container {
width: 200px;
}
.item {
float: left;
}
.item:nth-child(4n+1) {
clear: left;
}
<div class="container">
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred<br>plugh<br>xyzzy<br>thud</div>
<div class="item">foo<br>bar<br>baz<br>qux</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred<br>plugh<br>xyzzy<br>thud</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo</div>
<div class="item">foo<br>bar<br>baz</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault</div>
<div class="item">foo</div>
<div class="item">foo<br>bar<br>baz</div>
</div>
Option #2 : clearfix
Under IE9, you can use a clearfix :
/* Style */
.item { background: yellow; width: 48px; border: 1px solid black; }
.item:nth-child(2n) { background: blue; }
.item:nth-child(3n) { background: red; }
/* Position */
.container {
width: 200px;
}
.item {
float: left;
}
.clear {
clear: both;
height: 0px;
}
<div class="container">
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred<br>plugh<br>xyzzy<br>thud</div>
<div class="item">foo<br>bar<br>baz<br>qux</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred<br>plugh<br>xyzzy<br>thud</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo</div>
<p class="clear"> </p>
<div class="item">foo<br>bar<br>baz</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault</div>
<div class="item">foo</div>
<div class="item">foo<br>bar<br>baz</div>
</div>
Options #3 : rows
Another way to do it under IE9 : add rows.
/* Style */
.item { background: yellow; width: 48px; border: 1px solid black; }
.item:nth-child(2n) { background: blue; }
.item:nth-child(3n) { background: red; }
/* Position */
.container {
width: 200px;
}
.item {
float: left;
}
.row {
clear: both;
}
<div class="container">
<div class="row">
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred<br>plugh<br>xyzzy<br>thud</div>
<div class="item">foo<br>bar<br>baz<br>qux</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred<br>plugh<br>xyzzy<br>thud</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo</div>
</div>
<div class="row">
<div class="item">foo<br>bar<br>baz</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault</div>
<div class="item">foo</div>
<div class="item">foo<br>bar<br>baz</div>
</div>
</div>
Option #4 : columns
This option requires to rearrange items order.
/* Style */
.item { background: yellow; width: 48px; border: 1px solid black; }
.item:nth-child(2n) { background: blue; }
.item:nth-child(3n) { background: red; }
/* Position */
.container {
width: 200px;
}
.column {
width: 50px;
float: left;
}
<div class="container">
<div class="column">
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge</div>
<div class="item">foo<br>bar</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply</div>
</div>
<div class="column">
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred<br>plugh<br>xyzzy<br>thud</div>
<div class="item">foo<br>bar</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge</div>
</div>
<div class="column">
<div class="item">foo<br>bar<br>baz<br>qux<br>quux</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred</div>
<div class="item">foo<br>bar<br>baz<br>qux</div>
</div>
<div class="column">
<div class="item">foo<br>bar<br>baz</div>
<div class="item">foo<br>bar<br>baz</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge</div>
</div>
</div>
Option #5 : Masonry
Finally, a JS solution with Masonry :
var container = document.querySelector('.container');
var msnry = new Masonry( container, {
// options
columnWidth: 50,
itemSelector: '.item'
});
/* Style */
.item { background: yellow; width: 48px; border: 1px solid black; }
.item:nth-child(2n) { background: blue; }
.item:nth-child(3n) { background: red; }
/* Position */
.container {
width: 200px;
}
<script src="http://cdnjs.cloudflare.com/ajax/libs/masonry/3.1.2/masonry.pkgd.js"></script>
<div class="container">
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge</div>
<div class="item">foo<br>bar</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred<br>plugh<br>xyzzy<br>thud</div>
<div class="item">foo<br>bar</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge<br>grault<br>garply<br>waldo<br>fred</div>
<div class="item">foo<br>bar<br>baz<br>qux</div>
<div class="item">foo<br>bar<br>baz</div>
<div class="item">foo<br>bar<br>baz</div>
<div class="item">foo<br>bar<br>baz<br>qux<br>quux<br>corge</div>
</div>