I am having a problem on displaying 3 Bootstrap columns in the ContentArea.
When I use Developer tools I can find them, they are at the bottom of the ContentArea, out of sight. I have tried adding the top attribute, and even the margin-top attribute but can't get those columns to move up into view in the ContentArea.
Can someone point out to me where I am going wrong?
$(document).ready(function () {
$('#menu-toggle').toggleClass('menu-hidden');
$('#menu-toggle').on('click', function () {
//alert();
$('#SidebarWrapper').toggleClass('menu-hidden');
$('#ContentArea').toggleClass('content-grew');
$('#SubCategories').toggleClass('slide-left');
});
});
body {
}
#TheLayoutContainer {
position:fixed;
z-index:1000;
width:100%;
height:100%;
border:1px solid black;
background-color:pink;
left:0px;
}
#menu-toggle {
}
#SidebarWrapper {
width:200px;
height:100%;
margin-top:0;
margin-left:0;
position:fixed;
z-index:2000;
background-color:black;
transition:1s;
}
#SidebarWrapper.menu-hidden {
width:50px;
transition:1s;
}
#ContentArea {
position: relative;
height: 100%;
background-color: purple;
z-index: 2000;
left: 325px;
margin-top:0px;
transition:1s;
padding-right:20px;
}
#ContentArea #SubCategories {
margin-left:-125px;
width:125px;
height:100%;
border:1px solid #72cad3;
background-color:#72cad3;
}
#SubCategories.slide-left {
margin-left:-75px;
width:125px;
height:100%;
border:1px solid #72cad3;
background-color:#72cad3;
}
#ContentArea.content-grew {
height: 100%;
left: 175px;
transition:1s;
}
#HeaderControlMenu {
height:45px;
width:100%;
background-color:yellow;
top:0px;
position:fixed;
z-index:2000;
left:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div id="HeaderControlMenu">
<button id="menu-toggle" class="btn btn-success">Click</button>
</div>
</div>
<div id="TheLayoutContainer">
<div id="SidebarWrapper">
</div>
<div id="ContentArea">
<div id="SubCategories">
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">A</div>
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">B</div>
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">C</div>
</div>
</div>
</div>
In addition to what #Temani Afif said, you need to enclose the parent (element that contains the rows) in an element with class container.
<div class="container">
<div class="row">
<div id="HeaderControlMenu">
<button id="menu-toggle" class="btn btn-success">Click</button>
</div>
</div>
<div class="row">
<div id="TheLayoutContainer">
<div id="SidebarWrapper">
</div>
<div id="ContentArea">
<div id="SubCategories">
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">A</div>
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">B</div>
<div class="col-md-4 col-lg-4 col-sm-4 col-xs-4" style="border:1px solid green">C</div>
</div>
</div>
</div>
</div>
</div>
Here is a fiddle
https://getbootstrap.com/docs/4.0/layout/grid/
Because none of the other answers and comments have mentioned all of the mistakes in your code, I will do that in my answer:
Don't use "naked" rows in Bootstrap. Do this instead: If you need a full-width container, use a div (or another suitable element like section etc.) with the class .container-fluid. Otherwise, use a div with the class .container and put your row(s) inside that container.
A Bootstrap .row must always have at least one Bootstrap column (.col-*) inside and all of your content must reside inside columns. Don't put any content directly into a .row.
.col-xs-* classes don't exist in Bootstrap 4 (anymore). Use .col-* instead.
Replace col-lg-12 col-md-12 col-sm-12 col-xs-12 with col-12 because that will do the exact same job. (because Bootstrap 4 is "mobile-first")
Replace col-md-4 col-lg-4 col-sm-4 col-xs-4 with col-4 because that will do the exact same job.
Side note: You can put some content directly into a Bootstrap .container or .container-fluid i.e. without using Bootstrap rows and columns. However, that would make sense only in a few special cases because usually your content wouldn't be responsive if you'd do that. The exceptions to this rule are things like Bootstrap navbars and jumbotrons.
Related
it is actually quite simple:
If I have several children, I want .child to have margin-bottom: 10px;
if there is only one child, I don't want to have that margin
obviously:
Just adding another class to the container is not an option. CSS solution only
<div class="container">
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
so first container's child should have no margin. The other examples should have a margin between each child
You can make use of the :first-of-type pseudo-class in conjunction with the :not negation pseudo-class, and set margin-top instead. This will only give the margin-top to child elements which have a preceding element, thus giving the separation effect you're looking for:
.container {
border: 1px solid black;
}
.child:not(:first-of-type) {
margin-top: 10px;
}
<div class="container">
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
You can add a margin to each element after a previous one, so we only have margin-top if there is an element before.
.container {
border:2px solid;
margin:20px;
}
.child {
height:20px;
background:red;
}
.child + .child {
margin-top:10px;
}
<div class="container">
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
Or remove the margin-bottom from the last element so when having only one element it will also be the last element:
.container {
border:2px solid;
margin:20px;
}
.child {
height:20px;
margin-bottom:10px;
background:red;
}
.child:last-child {
margin-bottom:0;
}
/* OR
.child:not(:last-child) {
margin-bottom:10px;
}
*/
<div class="container">
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
<div class="container">
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
<div class="child">xxx</div>
</div>
Please see this pen for a quick example http://codepen.io/Irish1/pen/mymBje
html
<div class="container A">
<div class="col-xs-12 col-md-4 border1 height"></div>
<div class="col-xs-12 col-md-4 border2 height"></div>
<div class="col-xs-12 col-md-4 border3 height"></div>
</div>
<div class="container B border1">
<div class="col-xs-12 col-md-4 border1 height"></div>
<div class="col-xs-12 col-md-4 border2 height"></div>
<div class="col-xs-12 col-md-4 border3 height"></div>
</div>
css
.height {
height: 20px;
}
.B {
width: 325px;
height: 100px;
}
.border1 {
border: 1px black solid;
}
.border2 {
border: 1px blue solid;
}
.border3 {
border: 1px red solid;
}
container A has the width of the browser window and contains 3 columns that go from 33% width to 100% width when the window width is below 768px
container B is the same set up accept that its width is only 350px. As you can see in the pen the 3 columns are 33% width.
I am sure this is working as intended but is it possible to make the grid relative to its containing div instead of the browser window? ie so that the divs in container B have 100% width because B's width is less than 768px.
This is setting the width to 30%, along with display:inline-block to all div child's of class container. See below how this alters the appearance:
.height {
height: 20px;
}
.B {
width: 325px;
height: 100px;
}
.border1 {
border: 1px black solid;
}
.border2 {
border: 1px blue solid;
}
.border3 {
border: 1px red solid;
}
.container div {
width: 30%;
display: inline-block;
}
<div class="container A">
<div class="col-xs-12 col-md-4 border1 height"></div>
<div class="col-xs-12 col-md-4 border2 height"></div>
<div class="col-xs-12 col-md-4 border3 height"></div>
</div>
<div class="container B border1">
<div class="col-xs-12 col-md-4 border1 height"></div>
<div class="col-xs-12 col-md-4 border2 height"></div>
<div class="col-xs-12 col-md-4 border3 height"></div>
</div>
Media Query approach:
div{
display:inline-block;
width:30%;
height:50px;
background:blue;
border:1px solid black;
margin:1%;
font-weight:bold;
font-size:30px;
text-align:center;
transition: all 0.8s;
}
#media screen and (max-width:768px)
{
div{
background:red;
display:block;
width:100%;
}
}
<div>A</div><div>B</div><div>C</div>
At this point I would like to mention my absolute hatred for bootstrap, mainly due to its lack of functionality. Like, seriously, it would be more beneficial, (and actually less time consuming) to write the css yourself, especially when you want to do anything 'out of the box'. I found bootstrap to be far too restrictive for any sort of 'further functionality'
Looks like the only way is to do it programmatically.
Found a solution in another StackOverflow question.
Basically you have a class that gives 100% width to element and based on parent width, this class is toggled.
.m {
width: 100%;
}
$('.somecontainer').on('resize',function(){
if ($('.somecontainer').width() < 140) {
$('.somecontainer').addClass('m');
} else {
$('.somecontainer').removeClass('m');
}
});
Try this removing the padding of the bootstrap class or you can overright it by giving your own class
HTML:
<div class="container regular">
<div class="col-xs-12 col-md-4 border1 height"></div>
<div class="col-xs-12 col-md-4 border2 height"></div>
<div class="col-xs-12 col-md-4 border3 height"></div>
</div>
<div class="container regular">
<div class="col-xs-12 col-md-offset-4 col-md-4 border1 regular">
<div class="col-xs-12 col-md-4 border1 height"></div>
<div class="col-xs-12 col-md-4 border2 height"></div>
<div class="col-xs-12 col-md-4 border3 height"></div>
</div>
</div>
CSS:
.height {
height: 20px;
}
.target {
width: 325px;
height: 100px;
}
.col-md-4{
padding:0;
}
.border1 {
border: 1px black solid;
}
.border2 {
border: 1px blue solid;
}
.border3 {
border: 1px red solid;
}
Try with this css:
.abs {
position: relative;
display: inline-block;
}
Would it be possible to achieve the attached grid in bootstrap? Each of the squares would probably be an image... or perhaps text!
I've had a go, but hit a wall when it comes to the top-left box for example that spans over two rows.
Grid:
Use nested blocks whenever you need your grid to span several rows.
Something like this:
<div class="row">
<div class="col-sm-6"></div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-6"></div>
<div class="col-sm-6"></div>
</div>
<div class="row">
<div class="col-sm-6"></div>
<div class="col-sm-6"></div>
</div>
</div>
<div class="col-sm-8">
<div class="row">
<div class="col-sm-8"></div>
<div class="col-sm-4"></div>
</div>
<div class="row">
<div class="col-sm-4"></div>
<div class="col-sm-8"></div>
</div>
</div>
<div class="col-sm-4"></div>
</div>
Then you can set the height for your blocks and your grid is good to go.
A newbie here.
So I was learning to make nested grids when I stumble on this question.
My Rules for making nested grids:
1.The entire grid will be in parent container .row (parent wrapper)
2.Columns are always nested in columns, however all nested columns must have a .row(column wrapper) wrapper to align items horizontally e.g.:
<div class='col-md-12'>
<div class='row'>This is the column wrapper.
<div class='col-md-9'></div>
<div class='col-md-3'></div>
</div>
</div>
3.Breakpoints are very key
4.You may have to use custom css to fine tune your grid.
This is my solution to the problem:
<div class='row parent-wrap'>
<div class='col-sm-6 big-left'>Top Left big</div>
<div class='col-sm-6 quarter-grid'>
<div class='row top-wrap'>
<div class='col-sm-6 top-left'>top-left</div>
<div class='col-sm-6 top-right'>top-right</div>
<div class='col-sm-6 bottom-left'>bottom-left</div>
<div class='col-sm-6 bottom-right'>bottom-right</div>
</div>
</div>
<div class='col-sm-12'>
<div class='row mid-wrap'>
<div class='col-sm-3 mid-start'>mid-start</div>
<div class='col-sm-6 mid-center'>mid-center</div>
<div class='col-sm-3 mid-end'>mid-end</div>
</div>
<div class='col-sm-9'>
<div class='row bottom-wrap'>
<div class='col-sm-8 bottom-start'>bottom-start</div>
<div class='col-sm-4 bottom-center'>bottom-center</div>
</div>
</div>
</div>
Rudimentary custom css:
.parent-wrap{
margin:100px;
}
.big-left{
background-color: aqua;
height:300px;
}
.top-left{
background-color:black;
height:150px;
}
.top-right{
background-color: blue;
height:150px;
}
.bottom-left{
background-color:brown;
height:150px;
}
.bottom-right{
background-color:crimson;
height:150;
}
.mid-start{
background-color:grey;
height:200px;
}
.mid-center{
background-color: red;
height:200px;
}
.mid-end{
background-color: pink;
height:400px;
}
.bottom-start{
background-color:blueviolet;
margin-left:-15px;
height:200px;
margin-top:-200px;
}
.bottom-center{
background-color:burlywood;
height:200px;
margin-top:-200px;
}
With Bootstrap 3, I'm trying to make an image stay within the boundaries of it's parent div.
This works fine for width, but no matter what I try, the image keeps falling out of the bottom of the parent div, because it's height doesn't update when I decrease browser height. Is it possible to make this work ? If so, how ? Thanks.
JSFiddle : http://jsfiddle.net/rensdenobel/9486t/
HTML :
<div class="container">
<div class="row">
<div class="col-sm-3 col-md-3 col-lg-4"></div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-4 center">
<div class="content">
<div id="text">You chose this photo :</div>
<div id="thumbnail-container">
<img id="thumbnail-image" class="img-responsive" src="http://placehold.it/800x800" />
</div>
<div id="button-share">
<button class="btn btn-success">Share it !</button>
</div>
</div>
</div>
<div class="col-sm-3 col-md-3 col-lg-4"></div>
<div>
</div>
CSS :
html, body {
height:100%;
}
.container {
height:100%;
width:100%;
border:1px solid blue;
}
.row {
border:1px solid green;
height:100%;
}
.center {
display:table;
border:1px solid red;
padding-top:12px;
padding-bottom:12px;
text-align:center;
height:100%;
max-height:100%;
}
.content {
display:table-cell;
vertical-align:middle;
text-align:center;
height:auto;
border:1px solid green;
}
#thumbnail-image {
margin-left:auto;
margin-right:auto;
height:auto;
}
#thumbnail-container{
width:100%;
border:1px solid pink;
max-height:70%;
height:70%;
margin-top:12px;
margin-bottom:12px;
}
try
<div id="thumbnail-container col-sm-4 col-xs-4">
<img id="thumbnail-image" class="img-responsive" src="http://placehold.it/800x800" />
</div>
change the col-sm-* and col-xs-* to get your desired output
This approach works for me. Please try adding this to your css:
.container {
height:max-content;
}
Here's the jsFiddle: http://jsfiddle.net/RkMFK/
Here's the html and css:
<div class="cont">
<div class="item">one</div>
<div class="item">two</div>
<div class="item">three</div>
<div class="item">four</div>
<div class="item">five</div>
<div class="item">six</div>
<div class="item">seven</div>
<div class="item">eight</div>
<div class="item">nine</div>
<div class="item">ten</div>
<div class="item">eleven</div>
<div class="item">twelve</div>
<div class="item">thirteen</div>
<div class="item">fourteen</div>
<div class="item">fifteen</div>
<div class="item">sixteen</div>
<div class="item">seventeen</div>
<div class="item">eighteen</div>
<div class="island"></div>
</div>
.cont {
width: 240px;
height: 160px;
background-color:blue;
position:relative;
overflow:hidden;
}
.island {
position:absolute;
top:50px;
left:80px;
width:40px;
height:40px;
background-color:red;
}
.item {
float:left;
display:inline;
position:relative;
height:20px;
margin:2px;
padding: 0 10px;
background-color:yellow;
overflow:hidden;
}
How can I make the yellow items flow around the red "island" with css?
Summary: I have a container div of a fixed dimension. Somewhere within it is a small "island" div at a specific location (currently positioned absolutely, which removes it from the flow). How can I fill the container with a number of small elements of unknown width that surround the island? Any way to do this with css only? I'm stuck.
May be you want some what like in this fiddle . If i am lagging some where please let me know. so i can work out..
code:html
<div class="cont">
<div class="island"></div>
<div class="item">one</div>
<div class="item">two</div>
<div class="item">three</div>
<div class="item">four</div>
<div class="item">five</div>
<div class="item">six</div>
<div class="item">seven</div>
<div class="item">eight</div>
<div class="item">nine</div>
<div class="item">ten</div>
<div style="margin:0 20px" class="item">eleven</div>
<div style="margin:0 25px" class="item">twelve</div>
<div class="item">thirteen</div>
<div style="margin-left:58px;" class="item">fourteen</div>
<div class="item">fifteen</div>
<div class="item">sixteen</div>
<div class="item">seventeen</div>
<div class="item">eighteen</div>
</div>