I am very new to responsive website design (well front end development in general) and I am trying to create a basic little angular chat application, using bootstrap, designing with responsiveness in mind the whole way. I am however running into a lot of issues when I start nesting flex boxes, and I think I just don't fully understand it. Ideally these are my views when on a larger device and smaller.
Large:
Small device (note I have not done anything to make the settings change to a button):
And here is the reality that I get when using h-100 (I don't see any built in responsive classes for height, but I could be totally wrong):
I think I understand the issue, I am using h-100 with col-12 and so the left side takes up all the room, and the right side is shunted off the page. I have tried getting this same look with flex-fill and flex-grow-1, but they seem to do nothing to the actual document. Here is my code:
<app-header></app-header>
<div class="container-fluid" id="mainContent">
<div class="row h-100 flex-column-reverse flex-md-row">
<div class="col-md-3 col-12 flex-fill">
<div class="d-flex flex-column h-100 justify-content-between">
<div>
<app-channels></app-channels>
</div>
<div>
<app-settings></app-settings>
</div>
</div>
</div>
<div class="col-md-9 col-12">
<app-messages></app-messages>
</div>
</div>
</div>
(app-messages also uses h-100 to fill the screen)
custom scss:
#import "../node_modules/bootstrap/scss/bootstrap";
html, body {
height: 100% !important;
width: 100% !important;
}
Is there a way I can get this content to switch between the views that I have posted above with purely flexbox instead of using h-100? Or are there responsive classes like, for example, h-sm-100 so that it only uses 100% height on small and above?
Thanks for your time.
for height, you may have to take matter in your own hands... which is not that complex as you can see in this Angular demo
This following code helps produce what you require..
CSS part:
.outsideDiv{ overflow-y:hidden;}
.app-header { height:10vh; background:#000; color:#fff;}
.myHeight{ background: lightgray; }
.mySection{padding:0; }
.app-messages { background: #c7b6c7;}
.createMessage{background: lightyellow; margin: 1%; position: absolute; bottom: 0px; width: 98%; }
.app-settings { background:blue; }
.app-channels { background:#b3fbfb;}
#media SCREEN AND (min-width: 768px){
.myHeight{ height:90vh; }
.app-channels { height: 80%; }
.app-messages { height: 100%; }
.app-settings { height: 20%; }
}
#media SCREEN AND (max-width: 767px){
.myHeight{ height:auto; }
.myHeightSection1 { height:20vh;}
.myHeightSection2 { height:70vh;}
.app-channels { height: 100% }
.app-messages { height: 100%; }
.app-settings { height: 5%; width:20%; position:fixed; right:0; bottom:0; }
}
HTML part:
<div class='outsideDiv'>
<div class="app-header">
<app-header>
</app-header>
</div>
<div class="container-fluid" id="mainContent">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-12 col-12 d-flex flex-column mySection">
<div class="d-flex flex-column h-100 justify-content-between order-last">
<div class='myHeight myHeightSection1'>
<div class="app-channels">
<app-channels></app-channels>
</div>
<div class="app-settings">
<app-settings></app-settings>
</div>
</div>
</div>
</div>
<div class="col-lg-9 col-md-9 col-sm-12 col-12 order-first order-lg-2 order-md-2 mySection">
<div class='myHeight myHeightSection2'>
<div class="app-messages">
<app-messages></app-messages>
<div class='createMessage'>Create Message</div>
</div>
</div>
</div>
</div>
</div>
</div>
Related
I need it to be responsive.. I've tried setting larger image as a div background but it's not responsive.. I end up with the two right images large than the large image... I'm not sure what to do.. I'm using bootstrap, please see my code and any advice would be appreciated.
Also, the two images on the right will display:none on mobile.. so it's not mobile I'm worried about, its from ipad and up that I need it to be responsive and all stay aligned
.large-image {
div {
position: relative;
background-repeat: no-repeat;
background-size: cover;
background-position: center;
width: 100%;
}
}
.large-image-two {
div {
height: 50vw;
#include breakpoint(up, xl) {
height: 43vw;
}
}
#include breakpoint(up, xl) {
max-height: 1100px;
}
}
.tile {
display: none;
#include breakpoint(up, lg) {
display: block;
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<section class="image-tile">
<div class="container-fluid padding-sides padding-large pt-0">
<div class="row">
<div class="col-xxl-10 col-lg-9 col-12 large-image large-image-two">
<div class="full-height" style="background-image: url(https://i.picsum.photos/id/847/1370/700.jpg?hmac=kz_PXEVjCOQtig90AKAetNcWNNoJdWMjRMYhOLc6r7w)"></div>
</div>
<div class="col-xxl-2 col-lg-3 col-12 tile">
<div class="row d-flex flex-column full-height">
<div class="top-image col-8">
<img class="full-width" src="https://i.picsum.photos/id/682/250/400.jpg?hmac=ub0-x7bHa0z6PHozDd9A5baHp22hyWuq0NZuhHYmmBE">
</div>
<div class="col-4">
<img class="full-width" src="https://i.picsum.photos/id/545/250/270.jpg?hmac=lfBUvuMl6_uUp1lJI6e4A7KBiB4vzkocSlai_L0fUyE">
</div>
</div>
</div>
</div>
</div>
</section>
I am trying to create a layout that would be responsive using Bootstrap 4. The problem I am having is when two divs wrap vertically for a smaller device the top div seems to push the lower div down exceeding the parent container (please see the images below). I want the lower div to fit with in the container, how can I achieve this using Bootstrap 4 or minimal css?
I added a yellow border on the bottom of the second div so we can see the push.
Large device view
Small device view
html,
body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
.bottom-border {
border-bottom: 50px solid yellow;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<body>
<div class="container-fluid p-0 h-100">
<div class="row h-100">
<div class="col-md-8 bg-primary h-md-100 ">
<div class="d-md-none text-center bg-primary">
<h5>Left Section</h5>
</div>
<div class="d-none d-md-block m-3">
<h1>Left Section</h1>
</div>
</div>
<div class="col-md-4 h-100 text-center bg-danger bottom-border">
<h4>Right Section</h4>
</div>
</div>
</div>
</body>
After you explained the significance of the border height, now I see what you mean, as mentioned previously, your h-100 classes are the issue.
That class tells the element to use 100% of its parents height, since you put that class on the main container and on the row elements, those two are using the full screen's height since the container's parent is the browser window and the row parent is the container.
When you use that same class on the children div, in this case, the red div, it also tries to use the full height of its parent (the row), but it does not take into consideration the other item inside (the blue div), if you remove the h-100 class from the red div, then each of them will use half the available space.
html,
body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
.bottom-border {
border-bottom: 50px solid yellow;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<body>
<div class="container-fluid h-100">
<div class="row h-100 flex-column flex-md-row">
<div class="col-md-8 bg-primary">
<div class="d-md-none text-center bg-primary">
<h5>Left Section</h5>
</div>
<div class="d-none d-md-block m-3">
<h1>Left Section</h1>
</div>
</div>
<div class="col-md-4 flex-grow-1 text-center bg-danger bottom-border">
<h4>Right Section</h4>
</div>
</div>
</div>
</body>
If I understand correctly, you'd wish to keep the left and right div keep doesn't go on top of eachother?
col-md means everything that the window size is above 768px, keep that number of columns. if you use col-sm, it would be everything above 576px. If you just say col-number, you'll keep it responsive reguardeless of the container width.
html,
body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
.bottom-border {
background-color: yellow;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
<body>
<div class="container-fluid p-0 ">
<div class="d-flex flex-row flex-wrap bd-highlight text-center ">
<div class="col-md-8 ">
<div class=" h-100 bg-primary">left</div>
</div>
<div class="flex-column col-md-4">
<div class=" bg-danger ">Right</div>
<div class=" bottom-border ">Bottom</div>
</div>
</div>
</div>
</body>
Also, since you're using Bootstrap 4, I'd also recommand checking Flex, which you basically put d-flex class on the parent and all the child will become responsive. You can make them even more precices with columns like you've did, but Flexbox is pretty powerful and really braindead to apply when you know how.
I have a page with a banner and 3 columns, and I am trying to make it so that when the screen width gets too small, that the first 2 columns change from 1/3rd width to 50% width and the last column width change to 100% so that it's below the first two.
When I do this, the height of the columns does change (they change to 50%, considering the columns will now fit underneath each other inside a 100% row), but the width does not. How could I fix this? Thanks in advance!
Codepen
HTML
<section class="section">
<div class="container-fluid">
<div class="aboutBanner"> </div>
<div class="row">
<div class="col">
</div>
<div class="col">
</div>
<div class="col">
</div>
</div>
</div>
</section>
related CSS
.aboutBanner {
height: 30%;
border: 1px solid blue;
}
.row {
height: 70%;
}
.row .col {
height: 100%;
border: 1px solid red;
}
#media screen and (max-width: 768px){
.row .col:nth-of-type(1),
.row .col:nth-of-type(2) {
height: 50%;
width: 50%;
}
.row .col:nth-of-type(3) {
height: 50%;
width: 100%;
border-style: dashed;
}
}
Use the Bootstrap responsive grid columns...
https://codepen.io/anon/pen/eMzRyb
<section class="section">
<div class="container-fluid">
<div class="aboutBanner">
</div>
<div class="row">
<div class="col-sm-4 col-6">
</div>
<div class="col-sm-4 col-6">
</div>
<div class="col-sm-4 col-12">
</div>
</div>
</div>
</section>
To visualize this in your codepen I changed the CSS...
.row {
height: 70%;
}
.row > div {
border: 1px solid red;
}
Also see:
What is the difference among col-lg-*, col-md-* and col-sm-* in Bootstrap?
Use bootstrap col-[size] class
See documentation
The bootstrap grid is based in 12 columns sizes, that are divided in 5 screen sizes:
Extra small
col-[1 to 12]
Small
col-sm-[1 to 12]
Medium
col-md-[1 to 12]
Large
col-lg-[1 to 12]
Extra large
col-xl-[1 to 12]
Try this:
<section class="section">
<div class="container-fluid">
<div class="aboutBanner"> </div>
<div class="row">
<div class="col-md-4 col-sm-6">
content of first
</div>
<div class="col-md-4 col-sm-6">
content of second
</div>
<div class="col-md-4 col-sm-12">
content of third
</div>
</div>
</div>
</section>
Keep in mind that 12 is 100%, 6 is 50%, 4 is 33%, 3 is 25% and so on...
I need to adjust Bootstrap columns to look like this.
The thing is that on smaller devices I just want to hide this blank areas on the sides, thus I don't wanna use just margins or paddings.
How can I achieve that? col-md-1 seems too small for the indents, while col-md-2 is too broad.
My Codepen with Bootstrap included.
HTML
<div class="container">
</div>
CSS
.container {
height: 230px;
background-color: blue;
max-width: 1050px;
padding-left: 15px;
padding-right: 15px;
}
If you don't want to declare any new classes padding etc. You can simply nest the columns bootply.com
Not really sure what you're trying to achieve here. The container changes it width depending on the screen size using media queries. The white/blank space you're trying to get rid off is disappearing when the size of the screen is less than 768px.
What you can do, if I understand your question correct is this option:
HTML:
<!-- CONTAINER -->
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="row">
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
</div>
</div>
</div>
</div>
<!-- CONTAINER FLUID -->
<div class="container-fluid">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="row">
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
<div class="col-md-3">
This is column nested inside
</div>
</div>
</div>
</div>
</div>
CSS:
.container-fluid,
.container {
height: 230px;
background-color: #333;
/* max-width: 1050px; */
padding-left: 15px;
padding-right: 15px;
margin-bottom: 15px;
}
html, body {
color: #fff;
}
Couldn't you just use a #media tag to cut the padding out when in mobile view? Makes it a lot easier. Just add the class below to either your container or row.
.marginClass{
margin: 0 15px 0 15px;
}
#media screen and (min-width: 480px) {
.marginClass{
margin: 0;
}
Actually you're probably better using margin. I've updated that.
I would like to know how easilly achieve this layout with Bootstrap 3.
You can achieve that layout using bootstrap 3 pretty easy, you just have to arrange your columns in a proper order. The orange~red block I believe its a sidebar, and the other two blocks have the same width (seems bound to the same container), and I think there you have your content.
So, put the sidebar block, in a container with the desired width from the bootstrap grid, like col-md-4, and the content block in a container say col-md-8; add to both these containers col-xs-12 class(will add 100% width on 768px and bellow), we'll need it because we're gonna use pull-left/right(float rule) class to swap them around.
Check out the demo and bellow the markup/css used
The markup:
<div class="container">
<div class='row cf'>
<div class='col-sm-4 col-xs-12 pull-right'>
<div class='orange'>One good lookin sidebar</div>
</div>
<div class='col-sm-8 col-xs-12 pull-left'>
<div class='content-entry orchid'>
Some content here
</div>
<div class='content-entry cyan'>
And some other content here
</div>
</div>
</div>
</div>
And the css:
.orange{
background: orange;
}
.orchid{
background: orchid;
}
.cyan{
background: cyan;
}
**Note: if you want that sidebar to expand it's height to the height of the other 2 blocks combined, that's a different story, but this should get you started.
UPDATE 2
OK since you have a layout a bit tricky on mobile, I guess your safest bet would be to make the sidebar absolute positioned, and on mobile(bellow and 767px), switch it to static position, to make em fall into a natural flow. There are some more other methods out there like flexbox, or maybe some fancy table tricks, but this one should get you going.
Check out the demo, and the changed markup/css bellow:
<div class="container">
<div class='row content-wrapper'>
<div class='col-sm-8 col-xs-12'>
<div class='content-entry orchid'>
Some content here
</div>
</div>
<div class='col-sm-4 col-xs-12 sidebar-wrapper'>
<div class='orange'>One good lookin sidebar</div>
</div>
<div class='col-sm-8 col-xs-12'>
<div class='content-entry cyan'>
And some other content here
</div>
</div>
</div>
</div>
.orange{
background: orange;
}
.orchid{
background: orchid;
}
.cyan{
background: cyan;
}
/*added rules*/
.content-wrapper{
position: relative;
}
.sidebar-wrapper{
position: absolute;
top: 0; right: 0;
}
#media all and (max-width: 767px){
.sidebar-wrapper{
position: static;
}
}
Have a look here, I think the .col-md-8 and .col-md-4 classes will be interesting for you.
Since stack Overflow will not do any project i posted you simple and easy step
Bootstrap use media-queries
example
#media screen and (max-width: 500px) {
div {
width: 80%
}
}
this above query works if screen is bellow 500px div width will be 80%
try this example
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightgreen;
}
#media screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
</style>
</head>
<body>
<p>Resize the browserwindow. When the width of this document is less than 300 pixels, the background-color is "lightblue", otherwise it is "lightgreen".</p>
</body>
</html>
Above example will show when screen size is bellow 600px page color will change from lightgreen to lightblue
<body class="container">
<div class="row">
<div class="col-sm-6 col-xs-12">orange</div>
<div class="col-sm-6 col-xs-12">
<div class="row">violet row</div>
<div class="row">light blue</div>
</div>
</div>
</body>
I used xs-12 for the mobile. Please post your example code next time.
Thank you for all your answers.
Here's what i've made with the help of all answers :
<div class="container">
<div class="row">
<div class="col-sm-8 bg-info">
<h4>Content 1</h4>
</div>
<div class="col-sm-4 bg-warning pull-right">
<h4>Sidebar</h4>
</div>
<div class="col-sm-8 bg-success pull-left">
<h4>Content 2</h4>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-8" style="background-color:purple; color:#fff">Contents box 1</div>
<div class="col-xs-12 col-md-4" style="background-color:red; color:#fff">Sidebar</div>
<div class="col-xs-12 col-md-8" style="background-color:blue; color:#fff">Contents box 2</div>
</div>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="col-xs-12 col-md-8" style="background-color:purple; color:#fff">Contents box 1</div>
<div class="col-xs-12 col-md-4" style="background-color:red; color:#fff">Sidebar</div>
<div class="col-xs-12 col-md-8" style="background-color:blue; color:#fff">Contents box 2</div>
</div>