Bootstrap last child css changes on page resize - html

So i have a 4 column row in bootstrap and i want to add a divider in between them.
I've added this through the css and made it so .divider-right:last-child has no border. This is fine until you resize the page and it goes from a 4 column grid, to a two column grid.
.divider-right {
border-right:1px solid #dddddd;
}
.divider-right:last-child {
border-right:transparent;
}
<section class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-3 divider-right">
Content box in here
</div>
<div class="col-xs-12 col-sm-6 col-md-3 divider-right">
Content box in here
</div>
<div class="col-xs-12 col-sm-6 col-md-3 divider-right">
Content box in here
</div>
<div class="col-xs-12 col-sm-6 col-md-3 divider-right">
Content box in here
</div>
</div>
</section>

This should handle removing the border as the viewport is reduced.
Add the appropriate Pseudo Class to the relevant media query.
.row div.divider-right {
border-right: 1px solid #f00;
}
.row div.divider-right:last-child {
border-right: none;
}
#media(max-width:991px) {
.row div.divider-right:nth-child(2n) {
border-right: none;
}
}
#media(max-width:767px) {
.row div.divider-right {
border-right: none;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<section class="container">
<div class="row">
<div class="col-sm-6 col-md-3 divider-right">
<div class="alert alert-info">Content box in here1</div>
</div>
<div class="col-sm-6 col-md-3 divider-right">
<div class="alert alert-info">Content box in here2</div>
</div>
<div class="col-sm-6 col-md-3 divider-right">
<div class="alert alert-info">Content box in here3</div>
</div>
<div class="col-sm-6 col-md-3 divider-right">
<div class="alert alert-info">Content box in here4</div>
</div>
</div>
</section>

i think you want to remove border of second element when it jumps to next div
try this code
#media (max-width:991px) {
.divider-right:nth-child(2n) {
border-right: medium one;
}
}

Related

unable to manage bootstrap 4 div elements to the responsive design

I'm working with bootstrap 4 and following codes,
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.css">
<div class="card-header rounded-0 border border-dark">
<div class="row">
<div class="col-12 col-md-4 ">
<img src="{{asset('images/usa.jpg')}}" alt="..." class="rounded-circle">
</div>
<div class="col-12 col-md-8 ">
<p>This is not a game fgfhg dfghdh dhdhdf dfgdhfhg dfdfhfh dfhdfhdf dfhdfh</p>
</div>
</div>
</div>
I need display above two div elements in the same row on large screen and need separate two rows (image is above and paragraph is under the image) when it is displaying mobile device. I use following col-12 col-sm-8 col-md-6 col-lg-4 col-xl-3 item codes in side to the div but not success.
how could I manage this problem?
View in Full Page , You will get it
body {
padding-top: 40px;
}
.col-sm-6 {
background: #ccc;
}
.other {
background: #a4a4a4;
}
.p {
text-align: center;
padding-top: 120px;
}
.p a {
text-decoration: underline;
color: blue;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-sm-6">
<h1>Bootstrap Grid Demo</h1>
</div>
<div class="col-sm-6 other">
<h1>2 Columns</h1>
</div>
</div>
</div>
<p class="p">Demo by Jabir Sayed. See article.</p>

How to setup breakpoints on nested rows Bootstrap

I'm currently learning to make a responsive website. I'm confused about how do I do the breakpoints of the content when the screen size changed. Here's what I wanted to do :
This code below only work for the desktop size :
<div className="row wrapper-about">
<div className="col-lg-6 col-md-6 col-6">
<div className="img-box">
<img src="/pp1.jpg" alt="foto.jpg" />
</div>
</div>
<div className="col-lg-6 col-md-6 col-6">
<div className="row">
<div className="desc-container">
<h5 className="text-justify">
Content 2
</h5>
</div>
</div>
<div className="row desc2-d">
<span>
Content3
</span>
</div>
</div>
</div>
The simplest way (no extra CSS or duplicate markup) to get this layout would be to disable flexbox for the larger screen width and use the float utils:
https://www.codeply.com/go/snVOquHz1k
<div class="container">
<div class="row d-md-block">
<div class="col-6 col-md-8 float-left border border-danger c1">
c1
</div>
<div class="col-6 col-md-4 float-left border border-success">
c2
</div>
<div class="col-12 col-md-4 float-left border border-warning">
c3
</div>
</div>
</div>
Similar questions have been answered before:
Rearranging responsive Bootstrap 4 grid layout
Bootstrap with different order on mobile version
One tall div next to two shorter divs on Desktop and stacked on Mobile with Bootstrap 4
Bootstrap 4 - Stack 2 columns with 1 large column on the right
With the Bootstrap grid, you'd have to place the C3 div twice. Once inside the 2nd column of the first row (for desktop view) and the other below the first row (for mobile view); Then toggle the visibility based on the 768px breakpoint to get what you wanted...
code snippet below:
.divC1 {
border: 5px solid red;
height: 300px;
}
.divC2 {
border: 5px solid green;
height: 150px;
}
.divC3 {
border: 5px solid yellow;
height: 150px;
}
#media screen and (max-width:768px) {
.divC2 {
height: 300px
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row">
<div class='col-6 col-sm-6'>
<div class="row">
<div class="col-sm-12 divC1"> C1
</div>
</div>
</div>
<div class='col-6 col-sm-6'>
<div class="row">
<div class="col-sm-12 divC2"> C2
</div>
<div class="col-sm-12 divC3 d-none d-md-block"> C3
</div>
</div>
</div>
<div class='col-12 divC3 d-block d-md-none'> C3
</div>
</div>
</div>
I think following code will help you.
.c1 { height:200px; outline:2px solid red; outline-offset: -5px; }
.c2 { height:100px; outline:2px solid green; outline-offset: -5px; }
.c3 { height:100px; outline:2px solid yellow; outline-offset: -5px; }
#media only screen and (max-width:768px) and (min-width:200px) {
.c1 { height:auto; }
.c2 { height:auto; }
.c3 { height:auto;}
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 c1">
C1
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 c2">
C2
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 c3">
C3
</div>

Change background colour of whole div on hover

I have the following layout:
<div class="index-card" data-card-index="5">
<div class="row">
<div class="col-md-12 text-center">
5
</div>
</div>
<div class="row">
<div class="col-md-12 text-center card-symbol">
ה
</div>
</div>
<div class="row">
<div class="col-md-12 text-center"><i>He</i></div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<i>H</i>
</div>
</div>
</div>
And this CSS rule:
.index-card :hover {
background-color: lightgoldenrodyellow;
}
Yet when I hover over empty space in the .index-card div, nothing happens. When I hover over individual child divs, such as .card-symbol, then only the background colour of that inner div changes.
How do I make the whole background of the .index-card div change colour on hover? Also, why does the whole div not change colour? The CSS rule is not for the inner divs but for the whole outer div.
The space after the class in the CSS, this causes any child elements to have the property applied instead. Remove the space, remove the issue
.index-card {
background: white;
}
.index-card:hover {
background: red;
}
<div class="index-card" data-card-index="5">
<div class="row">
<div class="col-md-12 text-center">
5
</div>
</div>
<div class="row">
<div class="col-md-12 text-center card-symbol">
ה
</div>
</div>
<div class="row">
<div class="col-md-12 text-center"><i>He</i></div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<i>H</i>
</div>
</div>
</div>
.my-card {
background-color: white;
}
.my-card:hover {
background-color: green;
}
if you want transition so you can use it transition: 0.5s;
.my-card {
background-color: white;
transition: 0.5s;
}
.my-card:hover {
background-color: white;
}

Divs don't span whole width.

Looking at other SO questions, I managed to get the left divs span the whole page, but not the right divs. How do I fix this problem?
HTML:
<div class="container-fluid">
<div class="row col-lg-6 col-md-6 col-sm-6 col-xs-6">
<div id="kpop" class="selection">
</div>
<div id="fashion" class="selection">
</div>
</div>
<div class="row col-lg-6 col-md-6 col-sm-6 col-xs-6">
<div id="martialarts" class="selection">
</div>
<div id="nature" class="selection">
</div>
</div>
</div>
CSS:
body .container-fluid {
padding-left: 0;
padding-right: 0;
}
.selection {
height: 50vh;
}
Here's a demo:
http://codepen.io/davegumba/pen/QNzpey
You didn't wrap your col classes in a row tag. Also you don't need to specify all the viewport sizes if they are all 6, for example. Col-xs-6 alone will apply to all sizes higher if you don't specify.
http://codepen.io/ruchiccio/pen/oxJWLQ
<div class="container-fluid">
<div class="row">
<div id="kpop" class="selection col-xs-6">
</div>
<!--kpop-->
<div id="fashion" class="col-xs-6 selection">
</div>
<!--fashion-->
</div>
<!--first column-->
<div class="row">
<div id="martialarts" class="col-xs-6 selection">
</div>
<!--martial arts-->
<div id="nature" class="selection col-xs-6"> </div>
<!--nature-->
</div>
<!--second column-->
</div>
<!--container-->
You should not use a twitter bootstrap's "row" in a col. Row class was ment and built to rows not columns. So it has a negative margin on each side. That's what is making your 50% return a lower value.
Get rid of the class row and it will be fixed. Or if you want to preserve it remove the negative margin on both sides of both columns
You can fix this by removing the "row" class from your columns, then removing the padding on the columns. The "row" class should be used as a container for the columns. Although I find that not even using it works fine at times, but it isn't proper. Also, like some others have said, you don't need to use multiple column sizes. You need to choose a size based on what you want your content to do at smaller viewport widths.
<div class="container-fluid">
<div class="col-xs-6">
<div id="kpop" class="selection">
</div>
<!--kpop-->
<div id="fashion" class="selection">
</div>
<!--fashion-->
</div>
<!--first column-->
<div class="col-xs-6">
<div id="martialarts" class="selection">
</div>
<!--martial arts-->
<div id="nature" class="selection">
</div>
<!--nature-->
</div>
<!--second column-->
</div>
<!--container-->
Styles:
.col-lg-6, col-md-6, col-sm-6, col-xs-5 {
margin: 0;
padding: 0;
}
The problem isn't with the code itself, it's with the structure of the HTML. In order to properly use Bootstrap, you need a row to wrap the columns. What you have right now is the rows and columns all in the same. Also, just as a side note, it's considered best practice to define starting at the smallest screen and work your way up to larger screens since the framework is mobile-first.
Here is how you could rewrite your code with the suggested changes:
<div class="container-fluid">
<div class="row">
<div class="col-xs-6">
<div id="kpop" class="selection">
</div>
<div id="fashion" class="selection">
</div>
</div>
<!-- End col -->
<div class="col-xs-6">
<div id="martialarts" class="selection">
</div>
<div id="nature" class="selection">
</div>
</div>
<!-- End col -->
</div>
<!-- End row -->
</div>
<!-- End container-fluid -->
Another thing you should keep in mind is that since Bootstrap is mobile-first, you don't need to repeat column definitions, as they automatically ripple up. For example, you defined 6-block columns for xs, s, m, and l screens, but you only need to define it for xs since it will automatically apply to all larger screens (s, m, l) unless it gets overwritten.
Inspecting the code seems the problem is related to the fact you have the class row .row with margin-right and margin left = -15px;
set both to 0
.row {
margin-right: 0px;
margin-left: 0px;
}
I did this:
Basically, removed row class and added no-padding class to all column classes.
http://codepen.io/anon/pen/mPamEZ
<div class="container-fluid">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 no-padding">
<div id="kpop" class="selection">
</div>
<!--kpop-->
<div id="fashion" class="selection">
</div>
<!--fashion-->
</div>
<!--first column-->
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 no-padding">
<div id="martialarts" class="selection">
</div>
<!--martial arts-->
<div id="nature" class="selection">
</div>
<!--nature-->
</div>
<!--second column-->
</div>
<!--container-->
body .container-fluid {
padding-left: 0;
padding-right: 0;
background-color:#ccc
}
.selection {
height: 50vh;
}
#kpop {
background: #7BECED;
}
#fashion {
background: #FFB5A7;
}
#martialarts {
background: #F3BB72;
}
#nature {
background: #B1DC76;
}
.no-padding{ padding-left: 0;
padding-right: 0;}
You can simply reset your margin and padding in .col-xs-6 to 0. Also, I dixed your markup - .row class should wrap .col-s classes. Take a look to Bootstrap documentation of grid system.
Here it is.
body .container-fluid {
padding-left: 0;
padding-right: 0;
}
.full-width {
margin: 0;
padding: 0;
}
.selection {
height: 50vh;
}
#kpop {
background: #7BECED;
}
#fashion {
background: #FFB5A7;
}
#martialarts {
background: #F3BB72;
}
#nature {
background: #B1DC76;
}
<div class="container-fluid">
<div class="row">
<div class="full-width col-lg-6 col-md-6 col-sm-6 col-xs-6">
<div id="kpop" class="selection">
</div>
<!--kpop-->
<div id="fashion" class="selection">
</div>
<!--fashion-->
</div>
<!--first column-->
<div class="full-width col-lg-6 col-md-6 col-sm-6 col-xs-6">
<div id="martialarts" class="selection">
</div>
<!--martial arts-->
<div id="nature" class="selection">
</div>
<!--nature-->
</div>
<!--second column-->
</div>
</div>
<!--container-->
Be careful, this changes can touch other divs in your page.
P.S It's better to create new class, for example full-width and give to it same rules. This will not broke your page. JSFiddle.

How to change the bg color on hover for entire row in bootstrap 3

Actuly i want to make a grid tiles like below image
My all columns comes in a parent div thats why i am unbale to change the bg color on hover for entire row.
If i use multiple rows as a parnet for cloumns than these columns wont comes correctly to each other.
HTML:
<div class="container grid-layout">
<div class="row">
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
</div>
</div>
CSS:
.grid-layout .row .col-md-3{
text-align: center;
border-bottom:#eee solid 1px;
}
.grid-layout .row .col-md-3 > a{
padding:10px 0;
display: inline-block;
width:100%;
color:#999999;
outline: none;
}
.grid-layout .row .col-md-3 > a:hover{
color:#5fa9e3;
text-decoration: none;
}
.grid-layout .row .col-md-3:hover{
background: #f7f7f7;
cursor: pointer;
}
.name{
padding:15px 0;
}
Please let me know what would be the correct approach.
You can try this using CSS like this:
.row:hover div[class^="col-"]{
background-color: #dcdcdc;
}
Hope this is what you are looking for.
If you just want to change the .row background-color this will work.
$('body > div > div').on( "mouseover", function() {
$( this ).css( "background-color", "red" );
});