Bootstrap - Responsive Row and Column with 100% height - html

I'm trying to make a responsive website and this is my layout as seen on the
desktop version. With the intended mobile version like so.
Because i'm trying to make the columns to fill 100% of the height in my browser, i have changed a few bootstrap codes. Is there anything that i should change in my code if my css is
html,body,.container{
height:100%;
}
.container{
display:table;
width: 100%;
-moz-box-sizing: border-box;
box-sizing: border-box;
border: 1px solid black;
padding: 0 0 0 0;
margin: 0 0 0 0;
}
.row
{
height: 100%;
display: table-row;
}
.col-xs-6.no-float{
display: table-cell;
width: 50%;
padding: 0 0 0 0;
float: none;
}

It is wrong idea, bootstrap classes shouldn`t be changed. Write your custom css with custom classes.
<div class="container full-height-container">
<div class="row full-height-row">
<div class="col-md-6 col-xs-12 left full-height-col">
<div class="row">
<div class="col-md-4">
c1
</div>
<div class="col-md-4">
c2
</div>
<div class="col-md-4">
c3
</div>
</div>
</div>
<div class="col-md-6 col-xs-12 right full-height-col">
test2
</div>
</div>
</div>
html,body{
height: 100%;
}
.left{
background: red;
}
.right{
background: yellow;
}
.full-height-container{
height: 100%;
}
.full-height-row{
height: 100%;
}
.full-height-col{
height: 100%;
}
Take a look: fiddle

Have you tried using media screen? That way you could set different sizes on different resolutions. For example:
#media screen and (max-width: 480px) {
body {
background-color: lightgreen;
}
}
It means if the resolution is 480 and less then the given example will apply. Also if you do not want to have these media screens in one css you can set them in the head section:
<link rel="stylesheet" type="text/css" href="styleA.css" media="screen and (min-width: 400px)">

Related

How do I create a responsive two column layout using divs instead of tables?

How do I create a responsive two column layout using divs instead of tables?
The left div will have text and a call to action. The right div will have an image or is it better to have a transparent background and a png image?
I want both divs to be aligned and responsive. The divs should also stack on top of each other at different screen resolutions.
Below is what I've done so far. It's not perfect. Is there a way of cleaning this up so that I don't run into issues across multiple browsers.
Thank you.
<style type="text/css">*{
box-sizing: border-box;
padding: 10px;
}
.column {
float: left;
width: 300px;
}
.center {
padding: 50px 0;
}
.row:after {
content: "";
display: table;
clear: both;
}
#media screen and (max-width: 900px) {
.column {
width: 50%;
}
}
#media screen and (max-width: 600px) {
.column {
width: 100%;
}
</style>
<div class="row">
<div class="column" style="background-color:#e0e620;">
<div class="center">
<p style="font-size:18px; ">The Information is now available as an audiobook.<br />
<a class="link-button-green" href="" title="Info guide">Listen now</a></p>
</div>
</div>
<div class="column" style="background-color:#E5E5E5;">
<img src="https://www.w3schools.com/css/img_forest.jpg">
</div>
You can use flex instead of float to put the columns next to each other. In your #media query, you can remove flex for smaller screens so that the columns are displayed under each other.
The image width should be 100% of the flex column. The CSS doesn't have to be inline.
HTML
<div class="row">
<div class="column left">
<div>The Information is now available as an audiobook.<br />
<a class="link-button-green" href="" title="Info guide">Listen now</a>
</div>
</div>
<div class="column right" >
<img src="https://www.w3schools.com/css/img_forest.jpg">
</div>
</div>
CSS
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
.row {
display: flex;
}
.column {
flex:1;
}
.left {
background-color:#e0e620;
padding:20px;
}
.right {
background-color:#E5E5E5;
}
img {
width:100%;
}
#media screen and (max-width: 400px) {
.row {
width: 100vw;
display:block;
}
}
See this jsfiddle: https://jsfiddle.net/tLubao5d/1/

How can I line up images to the same size using CSS and HTML rather than having to scale all the images manually?

I've been trying to line up my images to the same size, using CSS and HTML tags, currently this is what I've come up with, there are just a few pictures that don't seem to follow the directions. I have tried different ways to describe the width (e.g: vw, hf, px or %), though those tags don't seem to completely sort the problem out here. The width is alright, yet the height on some pictures is not.
All pictures have different original sizes, only the last 3 pictures are exactly the same original size.
I have definitely tried finding the same issue asked elsewhere on the internet, but I haven't found anything related yet.
Any ideas on how to fix this, without having to manually edit all the pictures to the thumbnail size?
This is what the images currently look like.
code
.main-container {
max-width: 60%;
max-height: 44.44%;
margin-left: 19.6875%;
margin-top: 20%;
padding: 10px;
overflow: hidden;
background-color: #FEF39F;
}
.imgclass {
border: 1px solid #ddd;
border-radius: 4px;
padding: 5px;
max-width: 13.5vw;
max-height: 15hz;
}
img.imgclass:hover {
box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5);
}
max-height and max-width will only specify that the image should not be more than the specified height and width respectively. Try something like img { height: 200px; width: 100%}
May be you wanna do this:
* {
box-sizing: border-box;
}
/* Create four equal columns that floats next to each other */
.column {
float: left;
width: 25%;
padding: 10px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
.column img{
height: 250px;
width: 100%;
}
#media screen and (max-width: 600px) {
.column {
width: 50%;
}
.column img {
height: 180px;
width: 100%;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>Four Equal Columns</h2>
<div class="row">
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
<div class="column">
<img src="https://picsum.photos/700/600" >
</div>
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
</div>
<div class="row">
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
<div class="column">
<img src="https://picsum.photos/400/600" >
</div>
<div class="column">
<img src="https://picsum.photos/500/600" >
</div>
<div class="column">
<img src="https://picsum.photos/600/600" >
</div>
</div>
</body>
</html>

Bottom aligned div without disabling Bootstrap column floats

I guess this might be impossible, but perhaps any expert can help me out with this. I'm trying to get a quite simple reponsive behaviour working:
A two columns layout, logo left, navbar right. Now the navbar should be aligned at the bottom of the second column for bigger screens and floating to the next line directly under the logo on smaller screens.
Bigger screen:
Smaller screen:
I suppose this can be done only with JS so far, but maybe anyone knows a way to get this realized with pure CSS.
HTML:
<div class="container">
<div class="row">
<div id="col1" class="col-xs-12 col-sm-3">
<div id="logo">Logo</div>
</div>
<div id="col2" class="col-xs-12 col-sm-9">
<div id="navbar">Navbar: tab 1 | Nav tab 2 | Nav tab 3</div>
</div>
</div>
</div>
CSS:
#logo {
background-color: red; height: 100px; width: 150px; color: white;
}
#navbar {
background-color: blue; height: 30px; width: 100%; color: white;
}
I've set up a jsfiddle with the full code: http://jsfiddle.net/m4s4uqhx/6/
Any help is greatly appreciated.
set the height of col-2 similar to logo and set the navbar to position absolute and bottom 0 . replace your css with this solution
/* Latest compiled and minified CSS included as External Resource*/
/* Optional theme */
#import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
#col1 {
//border: 1px solid darkred; padding: 0px;
}
#col2 {
//border: 1px solid darkblue; padding: 0px;
}
#logo {
background-color: red; height: 100px; width: 150px; color: white; padding: 5px;
}
#navbar {
background-color: blue; height: 30px; width: 100%; color: white; padding: 5px;
}
#media only screen and (max-width : 992px){
#navbar{
position: absolute;
bottom: 0px;
}
#col2{
height: 100px;
}
}
#media only screen and (max-width : 768px){
#navbar{
position: relative;
}
#col2{
height: auto;
}
}
If the sizes of your elements are fixed as in your example, you can do the trick with padding-top, and remove it when the screen is too small (xs: <768px).
#media(min-width: 768px) {
#col2 {
padding-top:70px;
}
}
Demo on JSFiddle
Else, I guess you will have to write some JavaScript :)
If you know the exact height of you logo then you can add a padding top to the #col2 div on bigger screens using media queries
tablets and greater #media(min-width:778px){...}
desktops and greater #media(min-width:992px){...}
large screens #media(min-width:1140px){...}
Css example
#media(min-width:992px){
#col2{padding-top:70px;}
}
Working example
http://www.bootply.com/SHj7pkKt80
The issue here is that the columns are not equal height. CSS only offer a couple of options for equalising columsn heights. CSS Tables and Flexbox.
You can leave the floats in place but flexbox will override the floating to a certain extent.
Nevertheless, the impact can be minimal depending on your requirement.
Codepen Demo
#logo {
background-color: red;
height: 100px;
width: 150px;
color: white;
}
#navbar {
background-color: blue;
height: 30px;
width: 100%;
color: white;
}
.row {
display: flex;
flex-wrap: wrap;
}
#col2 {
display: flex;
align-items: flex-end;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div id="col1" class="col-xs-12 col-sm-3">
<div id="logo">Logo</div>
</div>
<div id="col2" class="col-xs-12 col-sm-9">
<div id="navbar">Navbar: tab 1 | Nav tab 2 | Nav tab 3</div>
</div>
</div>
</div>

Bootstrap - Align 2 images on save row with size adaptation

I want to put 2 images on the same row, with size adaptation when I increase/decrease the page size, without have the image move to the other row.
Currently when my page is sized down, my second image (black block on the description) moves to the other row
Here is an screenshot of what I'm trying to do:
CSS:
.album {
margin-top: 10px;
width: 100%;
display: block;
width: auto;
height: auto;
}
.album img {
padding: 10px;
}
And my html part:
<div class="row">
<div class="album">
<img src="images/album2017.png">
<img src="images/album2016.png">
</div>
I hope you can help me,
Thanks in advance :)
You just need to use sm breakpoint FIDDLE
<div class="container">
<div class="row">
<div class="col-sm-8">
<img src="http://placehold.it/350x150">
</div>
<div class="col-sm-4">
<img src="http://placehold.it/350x150">
</div>
</div>
</div>
.album {
margin-top: 10px;
width: 100%;
display: block;
height:auto;
width:auto;
}
.album img {
padding: 10px;
width:50%;
height :auto;
}
Hope this is what you are looking for. Adjust your width % to scale according to your screen size / block size
JSFIDDLE
I hope it's should work
.album {
margin-top: 10px;
width: 100%;
display: block;
width: auto;
height: auto;
}
.album img {
width: 50%;
padding: 10px;
}

Scale images in div according to browser size

I'm trying to create a centered div with 2 images, side by side, and have the one on the right jump under the first image when the browser scales down. And for all of it to be centered.
I tried doing it using divs but I'm stuck and can't figure out if what I'm doing is even correct. Right now the images don't scale down.
Here's a fiddle with my code:
http://jsfiddle.net/v5dejopw/1/
.wrapperlookbook {
overflow:hidden;
width: 1200px;
margin:0 auto;
padding-top: 60px;
}
#onelookbook {
float:left;
width:585px;
}
#twolookbook {
background-color: #fff;
overflow:hidden;
min-height:600px;
width:585px;
}
#media screen and (max-width: 600px) {
#onelookbook {
float: none;
margin-right:0;
}
}
img {
max-width:100%
}
Can anyone point me in the right direction?
Thanks!
My sugestion is add this in your code: if want in one line:
.wrapperlookbook {
max-width: 1200px;
width: 100%;
}
#onelookbook {
width: 50%;
}
#twolookbook {
width: 50%;
}
If want in two line:
#media screen and (max-width: 600px) {
#onelookbook {
width: 100%;
}
#twolookbook {
width: 100%;
}
}
Good luck!! ;)
The problem was about width of your elements. Check it out here:
.wrapperlookbook {
overflow:hidden;
width: 400px;
margin:0px;
margin: auto;
padding-top: 60px;
border: 1px solid green;
}
#onelookbook {
float:left;
width:200px;
}
#twolookbook {
background-color: #fff;
overflow:hidden;
min-height:600px;
width:200px;
}
#media screen and (max-width: 600px) {
#onelookbook {
float: none;
margin-right:0;
}
}
img {
max-width:100%
}
<div class="wrapperlookbook">
<div id="onelookbook">
<a href="#">
<img src="http://placehold.it/585x600" width="585" style="max-width:100%;height:auto;"></a></div>
<div id="twolookbook">
<a href="#">
<img src="http://placehold.it/585x600/c0c0c0" width="585" style="max-width:100%;height:auto;"></a></div>
</div>
Ps: I decreased the width here
I think work with bootstrap is a good option for you, since bootstrap takes care of the resizing of every element.
First, download the latest version of bootstrap from: http://getbootstrap.com/getting-started/#download
next, reference the files in the head
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<script src="js/bootstrap.js"></script>
<link href="css/bootstrap.css" rel="stylesheet" />
<link href="css/bootstrap-theme.min.css" rel="stylesheet" />
then, add a couple of div in your body
<body>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" style="height: 200px">
<img alt="Map of Forecast Area" src="http://www.srh.noaa.gov/wwamap/png/hgx.png" style="width: 100%; height: 100%" />
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" style="height: 200px">
<img alt="Map of Forecast Area" src="http://www.srh.noaa.gov/wwamap/png/hgx.png" style="width: 100%; height: 100%" />
</div>
What means this? Bootstrap works in 12-column mode. In this case, I made two with width 6 each (50%) for resolutions xs (extra small), sm (small), md(medium) and lg(large). Bootstrap will resize the divs depending on device resolution, and, if you resize the browser, the page will be resized accordingly.
This is only a basic example, but can help you as start point to use bootstrap.