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>
Related
This question already has answers here:
Make container shrink-to-fit child elements as they wrap
(4 answers)
CSS when inline-block elements line-break, parent wrapper does not fit new width
(2 answers)
Closed 4 years ago.
I've got a question for which I didn't find any easy solution.
Using only HTML and CSS,
is there a nice way to fits the parent div to "match" the total sizes of its contained elements?
Note that the box elements all have the same fixed, mandatory sizes. But this size may vary, so I'd like to not use #media queries.
Here is a commented snippet to illustrate what I mean:
#page{
width: 500px;
}
.container {
display: inline-block;
border: 1px solid black;
background: #ddd;
height: auto;
}
.box {
width: 200px;
height: 30px;
background: #fff;
line-height: 30px;
text-align: center;
border: 1px solid gray;
float: left;
}
#con1{
width: 404px;
}
<div id="page">
<p>How is it possible to have the container sized to fit its children?</p>
<div class="container">
<div class="box">x</div>
<div class="box">x</div>
<div class="box">x</div>
</div>
<br><br>
<p>Here is what I want, but without setting width in the CSS!</p>
<div class="container" id="con1">
<div class="box">x</div>
<div class="box">x</div>
<div class="box">x</div>
</div>
</div>
Doing this snippet, it appears to me I've got another little question…
Why is there some space between the boxes in my snippet?
Thanks in advance for any helpful answer.
Use of Media Query like this:
.container {
border: 1px solid black;
background: #ddd;
display: inline-block;
}
#media screen and (max-width: 631px) {
.container {
width: 409px;
}
}
#media screen and (max-width: 421px) {
.container {
width: 202px;
}
}
.box {
width: 200px;
height: 30px;
display: inline-block;
background: #fff;
line-height: 30px;
text-align: center;
border: 1px solid gray;
}
<p>How is it possible to have the container sized to fit its children?</p>
<div class="container">
<div class="box">x</div>
<div class="box">x</div>
<div class="box">x</div>
</div>
Note: Resize browser and see result!
is there a way using css to shift rows down the container when using #media originally two columns per row (3 rows total),need 1 column only when resized to multiple widths ex: 980, 760px, etc. (making 5 lines or rows). Thanks for any help
<div class="container">
<div id="portfolio" class="col-sm-6">
<div class="row">
<h1>Portfolio</h1>
</div>
<br />
<div class="realign">
<div class="row">
<div class="col-sm-6">
<div id="gym"><span class="text">Gym</span></div>
</div>
<div class="col-sm-6">
<div id="hiking"><span class="text">Hiking</span></div>
</div>
<div class="row">
<div class="col-sm-6">
<div id="overwatch"><span class="text">Overwatch</span></div>
</div>
<div class="col-sm-6">
<div id="running"><span class="text">Running</span></div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div id="programming"><span class="text">Programming</span></div>
</div>
</div>
</div>
</div>
</div>
/* Portfolio Only*/
#gym {
background-image: url("images/gym.jpg");
height: 150px;
width: 150px;
}
#hiking {
background-image: url("images/hiking.jpg");
height: 150px;
width: 150px;
margin-bottom: 15px;
margin-left: 15px;
}
#overwatch {
background-image: url("images/overwatch.jpg");
height: 150px;
width: 150px;
margin-left: 15px;
margin-bottom: 15px;
}
#running {
background-image: url("images/running.jpg");
height: 150px;
width: 150px;
padding: 0;
margin-left: 15px;
}
#programming {
background-image: url("images/programming.jpg");
height: 150px;
width: 150px;
margin-left: 15px;
}
#portfolio {
background-color: #ffffff;
padding: 20px;
}
.text {
background-color: #4aaaa5;
color: #ffffff;
width: 150px;
position: absolute;
text-align: center;
top: 120px;
font-family: 'Georgia', Times, "Times New Roman", serif;
}
/* #Media Settings */
#media screen and (max-width: 980px) {
body { width: 100%; }
.linebreak {margin-top: 300px;}
#bio img {margin-left: 50px;}
.realign {
}
/* check if its working */
.footnote {width: 50%;}
You already have classes with names such as col-sm-6, so I'm assuming you're using Bootstrap. That will handle most responsiveness automatically for you, by simply using col-sm (small screens), col-md (medium size screens), and col-lg (large screens). Simply make each row have column widths that add up to 12.
In your case, it sounds like you want to give everything that currently has <div class="col-sm-6"> a class that instead is:
<div class="col-sm-12 col-md-6">
That will result in two columns per row on laptops and desktops, with one column per row on mobile devices.
However, assuming you want to override BootStrap classes (or use your own class with the same name), here's an alternative solution.
First, set a default width of 50% for the class, and apply a float, so that two columns will be next to each other:
.col-sm-6 {
width: 50%;
float: left;
}
Then make said columns occupy 100% of the width at certain screen widths:
#media screen and (max-width: 980px) {
.col-sm-6 {
width: 100%;
}
}
Hope this helps!
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.
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; }
}
I've been trying to achieve this for hours and I'm not quite getting it to work, so here it goes nothing:
I have this site:Site HomePage
composed by this HTML elements:
<div id="headerwrap">
<div id="header">
</div>
</div>
<div id="navigationwrap">
<div id="navigation">
</div>
</div>
<div id="midcontentwrap">
<div id="leftwrap">
<div id="left">
</div>
</div>
<div id="midwrap">
<div id="midleft">
</div>
<div id="midright">
</div>
</div>
<div id="rightwrap">
<div id="right">
</div>
</div>
</div>
</div>
What I need is:
- When the browser window is resized, either left and right columns stay where they are and the MID COLUMN RIGHT SIDE needs to go below MID COLUMN LEFT SIDE.
My CSS file is pretty simple by now and this is the only major thing I need to do as the window size changes.
Thanks in advance for any help.
Yep, you're going to want to use media queries. Here's a JSFiddle of it in action.
Resize the display iFrame of the Fiddle back and forth past 500px width to view the results. I spruced up your HTML a little, too, to make it more modern (sorry):
HTML:
<section class='contentWrap'>
<aside>
This element corresponds to the element on the far left of the image you linked to.
</aside>
<div class='mainContent'>
<article class='left'>
This element corresponds to the mid-left element in the image you linked to.
</article>
<article class='right'>
This element corresponds to the mid-right element in the image you linked to.
</article>
</div>
<nav>
This element corresponds to the element on the far right side of the image you linked to.
</nav>
</section>
CSS:
.contentWrap {
width: 100%;
}
.contentWrap aside {
display: inline-block;
width: 25%;
height: 200px;
border: 1px solid purple;
}
.mainContent {
display: inline-block;
width: 45%; /* only because the borders are upsetting the percantages */
height: 200px;
border: 1px solid gray;
vertical-align: top;
}
.mainContent article {
border: 1px solid #00cae9;
margin-bottom: 2px;
}
.contentWrap nav {
display: inline-block;
width: 25%;
height: 200px;
border: 1px solid orangered;
vertical-align: top;
}
#media screen and (min-width: 500px) {
.contentWrap {
width: 500px;
margin: 0 auto;
}
.mainContent article {
display: inline-block;
width: 47%;
vertical-align: top;
}
}
NB: if you're viewing it on a super small screen, it won't work; that's JSFiddle's problem.
Oh fun, an excuse to have a play with CSS Media Queries!
DEMO: http://jsfiddle.net/Vn2QY/1/
CSS
#midcontentwrap {
min-width: 500px;
}
#leftwrap, #midwrap, #rightwrap {
float: left;
min-height: 400px;
}
#leftwrap, #rightwrap {
min-width: 100px;
width: 25%;
background-color: #15a;
}
#midwrap {
width: 50%;
background-color: #45a
}
#midleft, #midright {
width: 50%;
float: left;
}
#midleft {
background-color: #a45;
}
#midright {
background-color: #4a5;
}
#media all and (max-width: 500px) {
#midleft, #midright {
width: 100%;
}
}
The key piece here is the final part of the CSS. It basically states that "for all media (screen, printing, etc) when the browser width is less than 500 pixels in width, change the styling for #midleft and #midright and make them 100% of the available width."
By increasing their widths their existing float styling will force them on to new lines.
Try this DEMO
I'm guessing your want to get a fluid/responsive design. This should work for you.
Use float:left and min-width
To solve this problem....use % value for all div id width