I am having the following layout for my website and is built using responsive Bootstrap.
Now when I view it in a mobile device it comes in the following order:
HEADER
FORM
PROMOTIONS
INFORMATION
FOOTER
However, I don't want the promotions feature to come below the form for a mobile device. Instead I need the information section to come after the form and then the promotions section and then the footer.
Is there a way to achieve this using #media query?
I think, if you can control height of promotion block, this example can help you:
http://jsfiddle.net/vXb95/
<div id="header" class="bordered">header</div>
<div class="content">
<div id="form" class="bordered">form</div>
<div id="info" class="bordered">infomation</div>
<div id="promotion" class="bordered" >promotion</div>
</div>
<div id="footer" class="bordered">footer</div>
.bordered{
border:1px solid #333;
text-align: center;
min-height: 50px;
padding: 10px;
margin-bottom: 10px;
}
.content{
position:relative;
}
#form{
margin-right: 35%;
}
#promotion{
position: absolute;
right: 0;
top: 0;
width: 30%;
}
#media screen and (max-width: 400px) {
#promotion{
position: static;
width: auto;
}
#form{
margin-right: 0;
}
}
Live Demo
A dumb way to do this is by duplicating the promotional features part and showing/hiding them by media queries:
HTML
<div id="header">header</div>
<div id="form">form</div>
<div id="promotion">promotion</div>
<div id="info">info</div>
<div id="promotion2">promotion</div>
<div id="footer">footer</div>
CSS
#promotion2 { display: none; }
#media (max-width: 400px) {
#promotion { display: none; }
#promotion2 { display: block; }
}
Related
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/
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>
I'm trying to make an booking box with an white background over an image on my front page. So far I have managed to put an box on top with the following code:
Code:
<div class="row">
<div class="col-sm-12 contentpage">
<div class="frontimage">
<img src="~/images/index.jpg" />
<div class="col-sm-4">
<div class="bookingbox">
</div>
</div>
</div>
</div>
</div>
Css:
.bookingbox {
background-color: white;
position: absolute;
height: 100px;
margin-top: -580px;
margin-left: 10px;
}
#media (min-width: 1200px) {
.bookingbox {
display: none;
}
}
The problem now is that when you going from, lets say 1600px to 1200px the white box moves, can't make it to be static inside the image.
All my images are set with the following css the they become responsive:
img {
max-width: 100%;
}
What should I change? any ideer?
Update:
The box fitting perfectly now.. but now the image is off the aligniment with the rest of the page.
Left side is good, but right side has become bigger somehow?
The answer here, you should use z-index to do this.
.bookingbox {
background-color: red;
position: absolute;
height: 100px;
width: 100px;
z-index: 2;
position: absolute;
top: 0;
}
.frontimage {
z-index: 1;
position: absolute;
}
#media (min-width: 1200px) {
.bookingbox {
display: none;
}
}
<div class="row">
<div class="col-sm-12 contentpage">
<div class="frontimage">
<img src="https://www.wonderplugin.com/wp-content/plugins/wonderplugin-lightbox/images/demo-image0.jpg" />
<div class="col-sm-4">
<div class="bookingbox">
</div>
</div>
</div>
</div>
</div>
I'm looking to create a right sidebar on my page, however after going over multiple guides and I am still a stuck. What's the best way and most browser/mobile-friendly way to create a sidebar with minimal code?
HTML
<div class="wrapper">
<section id="content" class="content">
{squarespace.main-content}
<div id="sidebar" class="sidebar">
<squarespace:block-field id="sidebarBlocks" columns="12" />
</div>
</section>
And CSS
.wrapper {}
.content {}
#sidebar {}
Design your sidebar as a web usercontrol and put it inside the following div structure on to the masterpage.
<div id="parentContainer">
<div id="sitebody" >
<asp:ContentPlaceHolder runat="server" ID="MainContent" />
</div>
<div id="sidebar">
<uc1:ucSideBar ID="ucSideBar1" runat="server" />
</div>
</div>
Touch up the divs using css;
#sidebar
{
float: left;
height: 80%;
width: 250px;
}
#sitebody
{
float: left;
padding: 0 10px;
width: 60%;
height :80%;
}
#parentContainer
{
clear: both;
float: left;
width: 1500px;
}
to see this in fiddle
A better approach would be to use a CSS table layout with a fixed or dynamic width sidebar like this fiddle. This doesn't require any hacky float clearfixes and is cross-browser compatible.
.page {
display: table;
width: 100%;
max-width: 100%;
border-collapse: collapse;
}
.content, .nav {
display: table-cell;
}
.content {
width: 100%;
}
.nav {
min-width: 200px; /* Specify a fixed or percentage width or min-width here if required */
}
/* Stack at smaller widths */
#media screen and (max-width: 640px) {
.nav {
/* You could stack sidebar ontop of content using table-header-group instead */
display: table-footer-group;
}
}
I'm making a homepage and it works great in my resolution, but if I try to resize the window, the different logos (divs) start to overlap each other.
This is how it's supposed to look:
But whenever I resize the window, the logos (divs/pictures) overlap.
I have a lot of code that is what I believe to be irrelevant to the problem, but just in case, this is the complete code at jsfiddle (the pictures/font doesn't work though): http://jsfiddle.net/sXy3u/
Otherwise, this is an example of code of each div that I believe you'll need to help:
<div id="youtube">
<img src="youtube.png"/>
<a href="http://www.youtube.com/">
<div id="youtubeHover">
<div id="youtubeCircle">
<div id="youtubeArrow">
</div>
</div>
</div>
</a>
</div>
That's an example of one of the tiles. Now for two of the css codes:
#youtube {
width: 195px;
height: 195px;
margin-top: 5px;
padding-top: 5px;
position: relative;
overflow: hidden;
}
And the one that's overlapping:
#yahoo {
margin-top: -810px;
margin-left: 600px;
width: 195px;
height: 195px;
position: relative;
overflow: hidden;
}
This is where you have to use the Grid System Link
It gives you responsive layout depends on your screen such as Mobile, iPad, 1024x768 or HD Wide Screen. so if you use grid system, you don't need to recode your massive CSS. just attach every Metro Style Boxes in HTML part only with almost less coding.
I guess you have no idea about Grid Systems in Web Pages. no problem. I'll give you some basic tutorial links. have a look.Link
and this one is all available Grid System in the Web Industry nowadays. just have a look.
and if you use Grid System to this concept, you will amaze :)
You need to make your own custom responsive system up for this. Here's some basic stuff you can try out:
DEM0: http://jsbin.com/AKopuGo/1/
Notice how the sizes for the smallest device, which is 240px, the boxes don't exceed 200px total, but as the page gets bigger, the boxes are sized differently. Then the floats don't take effect until a certain min-width. You will need to learn more about responsive and fluid css if you intend to make this a career. All these min-widths are guesses and the styles will need to be set up and adjusted for each min-width, but not repeated. If a class is used for all sizes, put it outside any media queries, if it's use for a certain min-width (like the sizes of the box) put it there.
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both
}
.page-container {
margin: 0 auto;
padding: 3%;
}
.logo-box {
width: 210px;
border: 1px solid red;
}
.logo-box > div {
float: left;
width: 100px;
height: 100px;
background: #fff;
margin-right: 5px;
margin-bottom: 5px;
}
.logo-box > div.wide {
width: 205px
}
.text {
margin-bottom: 3%
}
#media (min-width:600px) {
.logo-box {
width: 250px
}
.logo-box > div {
width: 120px;
height: 120px;
}
.logo-box > div.wide {
width: 245px
}
}
#media (min-width:800px) {
.float-left {
float: left
}
.float-right {
float: right
}
.text {
margin-left: 3%
}
.logo-box {
width: 310px
}
.logo-box > div {
width: 150px;
height: 150px;
}
.logo-box > div.wide {
width: 305px
}
}
#media (min-width:1200px) {
.logo-box {
width: 410px
}
.logo-box > div {
width: 200px;
height: 200px;
}
.logo-box > div.wide {
width: 405px
}
}
HTML
<div class="page-container">
<h1>Title</h1>
<section class="text float-right"> Date time etc. </section>
<section class="logo-box first float-left clearfix">
<div class="wide">
Reddit
</div>
<div class="square">
YouTube
</div>
<div class="square">
Google
</div>
<div class="square">
Gmail
</div>
<div class="square">
NetFlix
</div>
<div class="wide">
Pandora
</div>
</section>
<!--/.logo-box-->
<section class="logo-box second float-right clearfix">
<div class="wide">
Reddit
</div>
<div class="square">
YouTube
</div>
<div class="square">
Google
</div>
<div class="wide">
Reddit
</div>
</section>
<!--/.logo-box-->
</div>
<!--/.page-container-->
You'll also need to use fluid images.