Tile layout with CSS and HTML - html

Without relying on tables, what would be a good solution to accomplish a tile layout such as this: that automatically adapts to the screen size of the user. That is, the whole screen should be filled by the tiles, regardless of the with and height of the resolution.
I appreciate any ideas.
~ Robert

Here is a working example:
jsfiddle
Html:
<div class="container">
<div class="first">first</div><div class="third">third</div>
<div class="second">second</div><div class="fourth">fourth</div><div class="last">last</div>
</div>​
CSS:
html, body, .container
{
height: 100%;
min-height: 100%;
}
.first {
float: left;
width: 20%;
height: 30%;
background-color: red;
}
.second{
float: left;
width: 20%;
height: 70%;
background-color: green;
}
.third{
float: right;
width: 80%;
height: 80%;
background-color: blue;
}
.fourth {
float: right;
width: 40%;
height: 20%;
background-color: #DDDDDD;
}
.last{
float: right;
width: 40%;
height: 20%;
background-color: yellow;
}
​

I would go with some div using absolute positionning. And specify for each tile the width/height/top/left using % unit.

Hint:
Use a "content div" with 100% of width and height
Use into the "content div" two divs: one for the left column and one for the right one. Remember to give those "%" dimension (to "content" div also)
Remember that a floated right div have to come BEFORE a left floated div
With this three point, you should be able to try yourself.

Disclaimer
This will not mean the needs of your project. That has been answered alread by other uses.
For future reference, I would look into an oocss-approach to layout classes. You may have pages that have a different amount of tiles, etc. I use the following for my projects.
Tiles Object
Used for creating tile layouts.
css
.tiles
{
display: block;
}
.tiles__item
{
display: block;
height: auto;
float:left;
}
.tiles--2
{
margin-left: -4%;
}
.tiles--3
{
margin-left: -2%;
}
.tiles--4
{
margin-left: -2%;
}
.tiles--2 .tiles__item
{
margin-left: 4%;
width: 46%;
}
.tiles--3 .tiles__item
{
margin-left: 2%;
width: 31.3%;
}
.tiles--4 .tiles__item
{
margin-left: 2%;
width: 23%;
}
html
<div class="tiles tiles--2">
<div class="tiles__item">
</div>
<div class="tiles__item">
</div>
</div>
Dock Object
Docks content to the edge of the screen.
css
.dock
{
position: absolute;
height: auto;
width: auto;
}
.dock--t
{
width: 100%;
top: 0;
}
.dock--b
{
width: 100%;
bottom: 0;
}
.dock--l
{
height: 100%;
left: 0;
}
.dock--r
{
height: 100%;
right: 0;
}
html
<div class="dock dock--t">
The content will be docked to the top of the screen.
</div?
Other Ones
I would look at the Tiles object in the Metro UI Framework. They allow for heights
http://metroui.org.ua/
If you are looking for a good layout system that uses proportions:
https://github.com/stubbornella/oocss/wiki/Grids

Related

How do I set a floating element automatically fill the remaining height of its parent element (height not fixed and displayed as a table)?

I have the following code:
.parent {width: 960px; display: table}
.1 {
width: 45%;
margin: 20px;
float: left;
height: 1000px; /* it can be smaller or bigger than this value to fit its content */
}
.2 {
width: 45%;
margin: 20px;
float: right;
height: 200px;
}
.3 {
width: 45%;
margin: 20px;
float: right;
}
<div class="parent">
<div class="1">1</div>
<div class="2">2</div>
<div class="3">3</div>
</div>
How do I write the CSS for class "3" so that its height automatically fill the remaining height of the table (in the case above, 720px, as the parent element will have, I assume, height of 1000px too)? Note that the height of class "1" can change according to its contents.
Off-topic: Is there a better way to make it look like the picture below other than the codes I'm using now (only using CSS and HTML)?
The Image of the Table
Try this one. the third element(green) will adjust based on the height of .one. But it is implemented based on the assumption that .two is having fixed dimensions.
.parent {
width: 960px;
border: solid 2px #999;
float: left;
position: relative;
}
.one {
width: 50%;
float: left;
height: 1000px;
background: #ccc;
}
.two {
width: 50%;
float: right;
height: 200px;
background: #aaa;
}
.three {
position: absolute;
top: 200px;
left: 50%;
right: 0;
bottom: 0;
background: green;
}
<div class='parent'>
<div class='one'>one</div>
<div class='two'>two</div>
<div class='three'>three</div>
</div>

CSS set the margin of a div equal to another div's width

I have these two classes that define a sidebar :
.w-sidebar {
width: 250px;
min-width: 250px;
max-width: 250px;
}
.row.collapse {
margin-left: -250px;
left: 0;
}
The margin-left of the second must be equals the negative of the width of the first for it to work.
But then I wanted to make the width dynamic instead of a fixed pixel amount :
.w-sidebar {
width: 35vw;
min-width: 250px;
max-width: 100vw;
}
.row.collapse {
margin-left: -250px;
left: 0;
}
How can I make the margin-left of the .row-collapse dynamic and equal to the width of the .w-sidebar using only css?
I tried using a mix of min/max inside a calc but that isn't supported.
Also tried using the media queries, but to be honest just found out about it and couldn't figure it out.
My fork/attempt : https://www.codeply.com/go/eUGo31Lwho
Working original demo : https://www.codeply.com/go/clX6THorTK
What about CSS variables :
:root {
--v: 250px;
}
.box {
width: var(--v);
display: inline-block;
background: red;
height: 100px;
}
.left {
margin-left: calc(-1 * var(--v));
width: 20px;
display: inline-block;
background: blue;
height: 50px;
}
<div class="box"></div><div class="left"></div>

CSS Footer with an overflow scrollbar

I suppose the easiest way to show this would simply be to give a link to the website where it needs to be added.
I NEED a simple footer that is always stuck at the bottom of the page, no matter how much content is placed within the main CONTENT and SIDEBAR divs.
I've tried using the sticky footer, and a few other methods. Such as putting it at the bottom of the page with bottom 0, etc.. But, with my setup it never seems to work. If you need anymore information feel free to ask.
change the css of your site to this one...this may help you...
#Wrapper {
color: #FFFFFF;
min-height: 100%;
overflow: auto;
width: 100%;
z-index: 6;
}
#Banner {
height: 169px;
position: relative;
top: 0;
width: 100%;
}
#Navbar {
background-color: #666666;
color: #FFFFFF;
float: left;
height: 35px;
position: relative;
width: 100%;
}
#Outer {
float: left;
height: auto;
margin-top: 35px;
width: 100%;
z-index: 2;
}
#Sidebar {
background-color: #00FF00;
float: left;
margin-left: 10px;
min-height: 600px;
width: 12.5%;
}
#Content {
background-color: #00FF00;
float: right;
margin-right: 10px;
min-height: 65%;
width: 85%;
}
#Copyright {
background-color: #FF3333;
float: left;
height: 35px;
width: 100%;
z-index: 20;
}
Ok what you want is a css class that looks more or less like this.
EDIT
.MyBottomBasicClass {
position: relative;
bottom 0;
margin: 0 auto;
padding: 0;
Width: 100%;
height : 300px // or whatever...
overflow-x: hidden;
overflow: scroll;
}
EDIT
You also need to wrap your other content.
.wrapper{
min-height: 100%;
}
and...
html, body {height: 100%;}
now in your html...
<div cssClass="wrapper">
// your site content
</div>
<div cssClass="MyBottomBasicClass">
// here you enter all the information you may need to include copyright information
</div>

CSS Issue Overlapping Image

Please see the attached image,I want to design this in html,Quite successful.But when I test it on different resolutions the red box moves here and there.I made the design in 100% width and height 100%
<style type="text/css">
#green-box { width: 75%; background: green; float: left; position: relative; height: 100%; overflow: visible; position: relative; }
#blue-box { width: 25%; background: blue; float: left; height: 100%; }
#red-box {
position: relative;
top: 50px;
left:450px;
width: 357px;
background: red;
height: 207px;
margin:0 auto;
}
#green-box-content
{
margin:0 auto;
width:1600px;
height:800px;
}
</style>
<div id="container">
<div id="green-box">
<div id="green-box-content">
<p>Here is some text!</p>
<div id="red-box"></div>
</div>
</div>
<div id="blue-box">
</div>
<div style="clear: both"></div>
</div>
Part of the problem is in how you are trying to position the element. It looks like you want it to be centered between the blue and green, but you're positioning from the left-hand side. Once the width of the green changes, it won't be where you want it. It would be better to position from the right (the border between the two) and set right to -1/2 of the width.
Also, 100% height will only work if the parent containers have a set height
Here's the modified CSS, and a fiddle to demonstrate
#blue-box,
#green-box {
height: 300px;
}
#green-box {
position: relative;
width: 75%;
float: left;
background: green;
}
#blue-box {
width: 25%;
float: left;
background: blue;
}
#red-box {
position: absolute;
top: 50px;
right: -178px; /* width / 2 */
width: 357px;
height: 207px;
background: red;
}
Remove width and height from #green-box-content, works perfectly in my local.
#green-box-content
{
margin:0 auto;
}
check this after making the change in my local.
I think you should Percentage of the red box as you have used it for green and blue and position as absolute.
http://jsfiddle.net/ccEKk/
if I am wrong update the fiddle so that someone can help you with it
#red-box {
position: absolute;
top: 5%;
left:45%;
width: 35%;
background: red;
height: 20%;
margin:0 auto;
}

Div Layout Issue with Positioning

I have the following HTML snippet:
<body>
<div class="main">
<div class="topBar">
<p>testing</p>
</div>
<div class="content">
<div class="broadcastBar">
<p>testing</p>
</div>
<div class="mainBody">
<p>more testing</p>
</div>
</div>
</div>
</body>
Here is my CSS:
div.main {
}
div.topBar {
background-color: Black;
color: White;
height: 50px;
width: 100%;
position: absolute;
top: 0px;
left: 0px;
}
div.broadcastBar {
background-color: Gray;
width: 300px;
position: absolute;
right: 0px;
top: 0px;
height: 100%;
}
div.content {
background-color: Yellow;
position: absolute;
width: 100%;
top: 50px;
left: 0px;
height: 100%;
}
My question is this. As you can see by the markup and CSS, I'm trying to have divs be the sections of the screen. But because <div class="content" /> has a position of absolute, it is causing the div to push below the browser window by 50px (which is what it is relative to the topBar).
I've tried making it so that the content div doesn't have to be position absolute, but everything just pushes the divs all around and the div edges are no longer flush to each other or the browser window.
Any idea what I can do hear to alleviate my issue?
Edit
Added desired output: this screenshot is currently what the above markup and CSS render. This is what I'm going for (for the most part, without the extended/scroll bar effect). I want to have my divs flush against each other and to the browser window.
What is the best way to do this if not through absolute positioning?
What you are going to want to learn is using some standard formatting practises with float.
Using absolute to position your elements will in the long run hurt you. If all your elements are using float, you will be able to better control their appearance.
For Example:
div.topBar {
background-color: Black;
color: White;
height: 20%;
width: 100%;
float: left;
}
div.broadcastBar {
background-color: Gray;
width: 70%;
height: 80%;
float: left;
}
div.content {
background-color: Yellow;
width: 30%;
height: 80%;
float: left;
}
#EDIT:
So you Have 3 divs and you will want to stack them sequencially.
<div class="header">headerdiv</div>
<div class="left">leftdiv</div>
<div class="right">rightdiv</div>
Float follows this sequence so that by using these properties, elelments will be forced to fall after one another based on space constraints:
div.header {
background-color: Black;
color: White;
height: 20%;
width: 100%;
float: left;
}
div.left {
background-color: Gray;
height: 80%;
width: 70%;
float: left;
}
div.right {
background-color: Yellow;
height: 80%;
width: 30%;
float: left;
}
#QUESTION:
So If you need to use pixel measurements, then you will need to encapsulate all of the elements in another container with the max width and height that your layout will be.
<div class="container">
<div class="header">headerdiv</div>
<div class="left">leftdiv</div>
<div class="right">rightdiv</div>
</div>
div.container{
height: 100px;
width: 100px;
float: left;
}
div.header {
background-color: Black;
color: White;
height: 20px;
width: 100px;
float: left;
}
div.left {
background-color: Gray;
height: 80px;
width: 70px;
float: left;
}
div.right {
background-color: Yellow;
height: 80px;
width: 30px;
float: left;
}