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.
Related
I have 2 columns and on the left and the right side, When I open the web page on a small or xs screen the two columns overlap. I would like for the other column to go below the other.
<div class="container">
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-9 area-style"></div>
</div>
</div>
CSS:
.area-style {
border: 1px solid #ccc;
padding-top: 2em;
background: #fafafa;
height: 500px;
}
Please check if you have given floats to the elements inside any of the "col-md-3" or "col-md-9" divs. The Overlapping 99% occurs If the floats are not cleared.
If you are using Bootstrap4 try this.
<div class="container">
<div class="row">
<div class="col-12 col-md-3"></div>
<div class="col-12 col-md-9 area-style"></div>
</div>
</div>
Try this.
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-3"></div>
<div class="col-xs-12 col-md-9 area-style"></div>
</div>
</div>
Please tell me if this helps you.
My goal is to achieve the following image on my page:
I managed to achieve this with the HTML and CSS you can find below, but it doesn't seem very viable, because the sidebar is losing it's physical height because of the position: absolute.
I'm wondering if it's possible to make one row with two columns on the left and a sidebar on the right, without having to use positioning.
I tried position: relative with a negative top, but since the top col-md-9 has a changing height (depending on what is entered), I can't give it a negative top. It'll simply be too static and impossible to maintain.
Changing the order in the HTML doesn't change anything, since the physical height of the sidebar will move the 2nd content down.
.sidebar {
position: absolute;
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-md-9">
Changing content
</div>
<div class="col-md-3 sidebar">
Sidebar
</div>
<div class="col-md-9">
More content
</div>
</div>
I use xs columns for this example, but you can change to md in your page.
Firstly create a 9-column and a 3-column div. Then put two divs inside the 9-column one.
.content, .sidebar {
margin: 10px;
padding: 20px;
}
.content {
background-color: navy;
color: white;
}
.sidebar {
background-color: yellow;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row wrapper">
<div class="col-xs-9">
<div class="row">
<div class="col-xs-12">
<div class="content">Content</div>
</div>
<div class="col-xs-12">
<div class="content">Content</div>
</div>
</div>
</div>
<div class="col-xs-3">
<div class="sidebar">Sidebar</div>
</div>
</div>
You can nest col-x-x inside other col-x-x
You just have to create 2 parents: content and sidebar, then add multiple contents into the content parent :
<div class="row">
<div class="col-md-9">
<div class="col-md-12">
Content
</div>
<div class="col-md-12">
More content
</div>
</div>
<div class="col-md-3 sidebar">
Sidebar
</div>
</div>
You cannot have more that 12 columns in a row unless it is not defined in your custom grid.
What you can try is this:
<div class="row">
<div class="col-md-9">
<div class="row">
<div class="col-sm-12">
Changing content
</div>
<div class="col-sm-12">
More content
</div>
</div>
</div>
<div class="col-md-3" style="position: relative;">
<div class="row">
<div class="col-sm-12 sidebar">
Sidebar
</div>
</div>
</div>
</div
As a solution, you can make sidebar to stay at the right side of screen if you'll make left section overflow: auto.
.sidebar {
height: 100vh;
background: lightgreen;
}
.left-section {
height: 100vh;
background: lightblue;
overflow: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-sm-9 left-section">
<div class="row">
<div class="col-sm-12">
Changing content
</div>
<div class="col-sm-12">
More content
</div>
</div>
</div>
<div class="col-sm-3 sidebar">
Sidebar
</div>
</div>
</div>
I'm using bootstrap (version 3.3.6) for the first time to make my site. Readed the docs and start to code. Excluding the <link>'s the code below is my site's structure:
<body>
<div class="container">
<div class="row">
<div class="col-sm-2 col-md-2 col-lg-2 col-lg-pull-1">
<div class="loader">
<div class="loader-bg">
...
</div>
</div>
</div>
<div class="col-sm-10 col-md-10 col-lg-10 col-lg-push-1">
<div class="black-box">
<p class="info-message">Coming <span>VERY</span> soon!</p>
<p class="text-message">Until then, my contacts:</p>
...
</div>
</div>
</div>
</div>
Using push and pull classes I thought I was removed padding for the columns. Setting the main div with 'class="container"' I have the result:
Changing to 'class="container-fluid"' the behavior remains strange. Notice shapes overlapping page:
What I want in my results is: the circle and rectangle (both are divs) remains aligned to the edges of the page (left and right) with no padding or marging. Following docs until now doesn't work. What this behavior occurs?
by default col-* have padding so you just need to reset them
[class^="col"] {
padding: 0
}
[class$="-2"] {
background: orange
}
[class$="-10"] {
background: grey
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="col-xs-2 col-sm-2 col-md-2 col-lg-2">
<div class="loader">
<div class="loader-bg">
...
</div>
</div>
</div>
<div class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
<div class="black-box">
<p class="info-message">Coming <span>VERY</span> soon!</p>
<p class="text-message">Until then, my contacts:</p>
...
</div>
</div>
</div>
I have three rows in my container. I'd like to apply one background across the bottom two rows. I don't want a background on the 1st row. I want to use one background ac I know I missing something, but can't figure out in the code where to edit it. My background only shows up in the first row of columns.
I don't want to apply a class to each .row that needs the background. The point is to specify the background once and have it apply to the two bottom rows.
Here's my bootply:
http://www.bootply.com/X5WsoQbuM1
Here's my HTML:
<div class="content-section-d">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h2>How many apples can you eat?</h2>
<p>
The apple tree (Malus domestica) is a deciduous tree in the rose family best known for its sweet, pomaceous fruit, the apple. I.</p>
</div>
</div>
<h2>Join us to pick the apples:</h2>
<div class="row centered-text" id="backgroundazul">
<div class="col-md-4 col-xs-12">
<h3>4,000,000+</h3>
</div>
<div class="col-md-4 col-xs-12">
<h3>1,500,000+</h3>
</div>
<div class="col-md-4 col-xs-12">
<h3>150,000+</h3>
</div>
</div>
<div class="row">
<div class="col-md-4 col-xs-12">
<h3>68,000+</h3>
</div>
<div class="col-md-4 col-xs-12">
<h3>2,000+</h3>
</div>
<div class="col-md-4 col-xs-12">
<h3>3 years</h3>
</div>
</div>
</div>
<!-- /.container -->
Here's my CSS:
#backgroundazul {
background: url(http://www.psdgraphics.com/file/green-hexagons-background.png) no-repeat center center;
padding: 0 0 50px 0;
}
If you want the background for all row use a class and repeat row
/* CSS used here will be applied after bootstrap.css */
.backgroundazul {
background: url(http://www.psdgraphics.com/file/green-hexagons-background.png) no-repeat center center;
padding: 0 0 50px 0;
}
<div class="container">
<div class="row">
<h2>Join us to access:</h2>
</div>
<div class="row centered-text backgroundazul " >
<hr class="section-heading-spacer">
<div class="col-md-4 col-xs-12">
<h3>4,000,000+</h3>
<p>Apples</p>
</div>
<div class="col-md-4 col-xs-12">
<h3>1,500,000+</h3>
<p>Oranges</p>
</div>
<div class="col-md-4 col-xs-12">
<h3>150,000+</h3>
<p>Mangos</p>
</div>
</div>
<div class="row centered-text backgroundazul " >
<div class="col-md-4 col-xs-12">
<h3>68,000+</h3>
<p>Bananas</p>
</div>
<div class="col-md-4 col-xs-12">
<h3>2,000+</h3>
<p>Honeydew</p>
</div>
<div class="col-md-4 col-xs-12">
<h3>3 years</h3>
<p>Blueberries</p>
</div>
</div>
Apply an id to you .container element and then apply the background to the .row elements.
<div id="backgroundazul" class="container">
<div class="row">
<!-- ... -->
</div>
<div class="row">
<!-- ... -->
</div>
</div>
#backgroundazul .row {
background: url(http://www.psdgraphics.com/file/green-hexagons-background.png) no-repeat center center;
padding: 0 0 50px 0;
}
Updated Bootply. Note that you did not wrap your second row of data in a .row and will not have the background applied. I do not know if this was intentional or not.
The solution is simple - you just need to insert in your css code a single line, so the code will look like:
#backgroundazul{
background: url(http://www.psdgraphics.com/file/green-hexagons-background.png) no-repeat center center;
background-size: cover;
padding: 0 0 50px 0;
}
And that's it :-)
I have two groups, A & B. On mobile view, A sidebar will stack on top of A content. Likewise for group B. However, I'm encountering two issues w/ my two column Bootstrap layout.
Issue #1
On mobile view, Content A get's stuck behind Sidebar B. I've tried adding float classes and clearing the floats, z-index, positioning, etc., and I'm just unable to get them to stack A,B,A,B =/
Issue #2
...is that I do want the max-height to be 100%, but what I'm getting is 100% height just for group A. What methods could I use to get both groups A & B to fit (together) 100% on the page?
My code is as follows; I appreciate any and all help! Thanks a ton.
HTML
<div class="container-fluid">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-4 a">
Sidebar content A
</div>
<div class="col-sm-8">
Body content A
</div>
</div> <!-- end row -->
</div> <!-- end col-sm-12 -->
</div> <!-- end container-fluid -->
<div class="container-fluid">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-4 b">
Sidebar content B
</div>
<div class="col-sm-8">
Body content B
</div>
</div> <!-- end row -->
</div> <!-- end col-sm-12 -->
</div> <!-- end container-fluid -->
CSS
html,body,.col-sm-12,.container-fluid, .row {
height:100%;
}
.row > div {
height:100%;
}
.a, .b {
background-color:#e5e5e5;
}
JSFiddle
Please let me know what I'm missing.
You could just add
col-xs-12
to your divs to stop the weird overlap- so your html would read
<div class="col-sm-4 col-xs-12 a">
Sidebar content A
</div>
<div class="col-sm-8 col-xs-12">
Body content A
</div>
Regarding the height issue you can apply a new class to your rows and update your css as follows:
html,
body {
height: 100%;
}
.container-fluid {
height: 50%;
}
.col-sm-12,
.fullheight {
height: 100%;
}
.a,
.b {
background-color: #e5e5e5;
height: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="col-sm-12">
<div class="row fullheight">
<div class="col-sm-4 col-xs-12 fullheight a">Sidebar content A</div>
<div class="col-sm-8 col-xs-12 fullheight">Body content A</div>
</div>
<!-- end row -->
</div>
<!-- end col-sm-12 -->
</div>
<!-- end container-fluid -->
<div class="container-fluid">
<div class="col-sm-12">
<div class="row fullheight">
<div class="col-sm-4 col-xs-12 fullheight b">Sidebar content B</div>
<div class="col-sm-8 col-xs-12 fullheight">Body content B</div>
</div>
<!-- end row -->
</div>
<!-- end col-sm-12 -->
</div>
<!-- end container-fluid -->