How to keep divs from overlapping on resize - html

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.

Related

How to make responsive columns and row

In my project I'm trying to make my help dialog like the design below pic but I'm not really sure how to make responsive to different size so I would be really appreciate If I can get any help or suggestion.
Right now in my laptop view everything is looking fine but when I switch to a screen size that is bigger than my laptop, I see a lot of empty space at the bottom of my help dialog.
<ng-container *ngIf="!isEditMode;else editMode">
<div class="topbar">
<h1 class="primary-text header" style="margin-left: 30px;">Help and About</h1>
</div>
<div mat-dialog-content class="dialog-container">
<div class="row">
<div class="column left">
<mat-nav-list>
<mat-expansion-panel class="exp-panel" *ngFor="let section of mappedSections">
</mat-expansion-panel>
</mat-nav-list>
</div>
<div class="column right">
<div *ngFor="let section of mappedSections">
</div>
</div>
</div>
</div>
<div fxLayout="row" fxLayoutAlign="center start">
<span style="flex-grow: 1;"></span>
<button mat-raised-button color="primary" mat-dialog-close [style.marginRight.px]="20"
matTooltip="Close Help">Close</button>
</div>
</ng-container>
CSS
.dialog-container {
width: 65vw;
height: 65vh;
overflow:hidden;
overflow-y: hidden !important;
padding: 2px;
margin: 0 20px;
}
.container-inside-dialog {
width: 100%;
height: 100%;
padding: 10px;
overflow:hidden;
overflow-y: hidden !important;
}
* {
box-sizing: border-box;
}
.column {
float: left;
padding: 10px;
}
.left {
width: 37%;
position: relative;
height: 530px;
overflow-y: auto;
}
.right {
position: relative;
width: 63%;
height: 530px;
overflow-y: auto;
}
.button{
width: 287px;
text-align: left;
padding-left: 25px;
height: 47px;
}
/* Clear floats after the columns */
.row:after {
position: relative;
content: "";
display: table;
clear: both;
}
So you will need to look into using media rules
#media only screen and (max-width: 1000px) {
}
Anything inside this css rule will then be applied when the screen is smaller than 1000px. There is no set width these should be set to but as a rule of thumb I tend to use 768px as the breakpoint from desktop/laptop to tablets and smaller devices. You can input your own custom breakpoint by establishing what size screen the page starts to look broken or weird and using that px to apply different CSS.
Alternatively, I would recommend looking at the bootstrap grid framework which would resolve a lot of this issue for you!
Let me know if you have any other questions :)

How to get this div with floats responsive?

I made an small html field and now I'm trying to get it responsive.
To make it clear, I made an picture how the fields should move when it's displayed on a smaller screen.
How it should be
After figuring out a few hours I got this solution, whichs works fine on the Desktop but not on a smaller screen. The Logo is not moving to the top but remains on the left side.
Can someone help me with this?
Here is the code:
<div style="background-color: orange; color: white; width: 30%; padding: 4px 4px; text-align: center; margin:0">Stackoverflow</div>
<div style="background-color: #f9f9f9; border: 2px solid orange; max-width:800px; overflow: auto;">
<div style="float: left;width: 30%; overflow: auto;"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR7A3wAuudoXw8butMA-wxJdWYdUlNbWjC6EOV3iXnrUf08dwX3PA" /></div>
<div style="float:left;width:70%">
<div style="text-align: center; font-size: 12pt; background-color:lightgreen">Some Informations
</div>
<div>
<div style="float: left; background-color: lightblue; width:50%">
<ul>
<li>Owner: Stack Exchange, Inc.</li>
<li>Available in: Englisch, Spanisch, Russian, Portuguese ...</li>
<li>Type of site: Knowledge markets</li>
</ul>
</div>
<div style="float: right; background-color: lightgrey; width:50%; padding:5px">
<ul>
<li>Website: stackoverflow.com</li>
<li>Commercial: Yes</li>
<li>Registration: Optional</li>
</ul>
<div style="float: left; width: auto; background-color:yellow">Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky. It features questions and answers on a wide range of topics in computer programming.
</div>
<div style="clear:both;text-align: center;"> <input type="button" value="Go to the Website" />
</div>
</div>
</div>
In order to change styles according to the screen resolution you can use a media query
#media (max-width: 1024px) {
.logo{
width: 100%;
}
}
Add classes to your elements in order to be able to target them with specific css rules:
<div style="float: left;width: 30%; overflow: auto;">
Becomes
<div class = "logo">
...
<style>
.logo{
float: left;
width: 30%;
overflow: auto;
}
</style>
You can't do responsive with inline styles. Once you have your styles separate, you can you use #media queries to style elements based on screen size
* {
box-sizing: border-box;
}
.tab {
background-color: orange;
color: white;
width: 30%;
padding: 4px 4px;
text-align: center;
margin: 0
}
.wrapper {
background-color: #f9f9f9;
border: 2px solid orange;
max-width: 800px;
overflow: auto;
}
.logo {
text-align: center;
}
#media (min-width: 640px) {
.logo {
float: left;
width: 30%;
overflow: auto;
}
.main {
float: left;
width: 70%
}
}
.row:before,
.row:after {
display: table;
content: " ";
}
.row:after {
clear: both;
}
.row {
margin-left: -5px;
margin-right: -5px;
margin-bottom: 5px;
}
.col {
margin: 0 5px;
width: calc(50% - 10px);
}
.col-left {
float: left;
background-color: lightblue;
}
.col-right {
float: right;
background-color: lightgrey;
padding: 5px
}
.highlight {
float: none;
width: auto;
background-color: yellow;
margin-bottom: 10px;
}
<div class="tab">Stackoverflow</div>
<div class="wrapper">
<div class="logo"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR7A3wAuudoXw8butMA-wxJdWYdUlNbWjC6EOV3iXnrUf08dwX3PA" /></div>
<div class="main">
<div style="text-align: center; font-size: 12pt; background-color:lightgreen">Some Informations
</div>
<div class="row">
<div class="col col-left">
<ul>
<li>Owner: Stack Exchange, Inc.</li>
<li>Available in: Englisch, Spanisch, Russian, Portuguese ...</li>
<li>Type of site: Knowledge markets</li>
</ul>
</div>
<div class="col col-right">
<ul>
<li>Website: stackoverflow.com</li>
<li>Commercial: Yes</li>
<li>Registration: Optional</li>
</ul>
</div>
</div>
<div class="highlight">Stack Overflow is a privately held website, the flagship site of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky. It features questions and answers on a wide range of topics in computer programming.
</div>
<div style="clear:both;text-align: center;">
<input type="button" value="Go to the Website" />
</div>
</div>
<!-- /.main -->
</div>
<!-- /.wrapper -->
Your HTML structure is not that bad, even though it will be better if your style code was inside a .css file, if is that the case try it.
Anyways, in your mobile structure you have 3 main containers, I will called:
main-container
image-container
content
Your main-container has image-container and content inside, but both has a villain, in your case that is float: left, this thing will set everything to be on left of themselves an others objects around them.
I will suggest you to change your float: left and start to work with display: flex, you can find tons of information in the internet about it, to help you to construct very polish structures that will obey to any rule that you will build to them.
Thank you guys, I made a solution out of your answers.
I made it with display:flex, flex-wrap:wrap and #media.
For this I seperated the whole "body of the box" into a Logo container and a text fields container (almost like before) and gave both flex attributes. In the text fields I used float (like before).
For smaller screens I changed the flex-direction to column and now it works how I wanted it.

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;
}

Div Repositioning on Window Resize

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