I am working on a structure to have a top navigation fixed, a left nav to be scrollable and a right nav to be fixed.
I have created a fiddle here. just need help with the css.
http://jsfiddle.net/PxbX9/
#header {
position:fixed;
background:red;
width:700px;
height:30px;
}
#left-block {
float:left;
width:350px;
background:blue;
height:1000px;
margin-top:30px;
}
#right-block {
float:left;
width:350px;
height:1000px;
background:pink;
margin-top:30px;
.fixed-block {
postion:fixed;
height:1000px;
}
This can be achieved by restructuring your CSS to this:
#header {
position:fixed;
background:red;
width:700px;
height:30px;
}
#left-block {
float:left;
width:350px;
background:blue;
height:1000px;
margin-top:30px;
}
#right-block {
display: inline-block;
float:right;
width:350px;
height:1000px;
background:pink;
margin-top:30px;
position:fixed;
}
I've only made CSS changes to the #right-block selector.
Removed the class .fixed-block, which had a typo in the form of postion (should be position).
position: fixed; has been added to the #right-block selector.
display: inline-block; and float: right; have been added also.
DEMO
Hope this helps.
Take a look at that Working Fiddle
Pure CSS solution, Very Dynamic, Totally responsive.
HTML:
<div class="Container">
<div class="Header">
</div>
<div class="HeightTaker">
<div class="Wrapper">
<div class="RightContent">
</div>
<div class="LeftContent">
</div>
</div>
</div>
</div>
CSS:
*
{
margin: 0;
padding: 0;
}
html, body, .Container
{
height: 100%;
}
.Container:before
{
content: '';
height: 100%;
float: left;
}
.HeightTaker
{
position: relative;
z-index: 1;
}
.HeightTaker:after
{
content: '';
clear: both;
display: block;
}
.Wrapper
{
position: absolute;
width: 100%;
height: 100%;
}
.Header
{
/*for demonstration only*/
background-color: #bf5b5b;
}
.Wrapper > div
{
height: 100%;
overflow: auto;
}
.LeftContent
{
/*for demonstration only*/
background-color: #90adc1;
}
.RightContent
{
float: right;
width: 500px;
/*for demonstration only*/
background-color: #77578a;
}
Related
Like the question says, I can't float anything to the bottom... I tried float:absolute and it showed that. There's supposed to be 5 different boxes, but it only shows one of them. This is my code:
html,
body {
height: 100%;
}
#one,#two,#three,#four,#five {
margin:0;
padding:0;
float:left;
display:inline-block;
height:50%;
width:20%;
bottom:0;
right:0;
left:0;
position:absolute;
}
div {
margin:-2px;
padding:-2px;
}
#container {
display: inline-block;
width: 100%;
height: 100%;
position: relative;
}
#one {
background-color: blue;
}
#two {
background-color: green;
}
#three {
background-color: yellow;
}
#four {
background-color: orange;
}
#five {
background-color: red;
}
<div id="one">
</div>
<div id="two">
</div>
<div id="three">
</div>
<div id="four">
</div>
<div id="five">
Thanks in advance :)
Your code's not working because you've essentially set all 5 boxes to stack on top of each other by having absolute positioning, 0 margin and left set to 0 for all 5 boxes, so everything takes the same positioning on the bottom left corner of the screen. If you remove right:0 and add an individual left property for each box, you should be able to have all 5 boxes in a neat row at the bottom, like so:
html,
body {
height: 100%;
}
#one,#two,#three,#four,#five {
margin:0;
padding:0;
float:left;
display:inline-block;
height:50%;
width:20%;
bottom:0;
left:0;
position:absolute;
}
#container {
display: inline-block;
width: 100%;
height: 100%;
position: relative;
}
#one {
background-color: blue;
left:0;
}
#two {
background-color: green;
left:20%;
}
#three {
background-color: yellow;
left:40%;
}
#four {
background-color: orange;
left:60%;
}
#five {
background-color: red;
left:80%;
}
jsfiddle: https://jsfiddle.net/hq2hv1pw/
Also on a side note, I'd combine the selector with a class for the CSS style that has 5 IDs haha.
Hope this helps you out
I am just a beginner in HTML/CSS
How to stop the floating div from overlapping.
jsfiddle-link
HTML
<body>
<div class="left">
</div>
<div class="right">
</div>
</body>
CSS
* {
margin: 0;
padding: 0;
}
body {
width: 100%;
}
.left {
float: left;
height: 500px;
width: 300px;
background: #fff;
position: absolute;
}
.right {
float: right;
height: 500px;
width: 300px;
background: #000;
}
Use widths in percentages and remove the absolute positions:
Here is the updated CSS:
*{
margin:0;
padding:0;
}
body{
width:100%;
}
.wrapper {
width: 100%;
}
.left{
float:left;
height:500px;
width:50%;
background:#fff;
}
.right{
float:right;
height:500px;
width:50%;
background:#000;
}
I have also wrapped left and right divs in a wrapper div
Check it here: https://jsfiddle.net/2Lk13045/2/
You set your width fixed instead of 100%.
https://jsfiddle.net/2Lk13045/1/]
Changed your
body{width:100%; }
to
body{width:600px; }
I try to vertically center an image in the middle of the body but nothing seems to work. I've tried different tricks found here (height 100%, table-cell, position:relative...), but with no luck until now. My code is
html:
<div id="container">
<div id="header">Header</div>
<div id="body">
<div class="image"></div>
</div>
<div id="footer">Footer</div>
</div>
CSS:
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ccc;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px;
}
.image {
background: url("http://lorempixel.com/300/200/nature/") no-repeat center;
height: 200px;
width: 100%;
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
background:#ccc;
}
I made a fiddle here: http://jsfiddle.net/dragoeco/hjcz6j0r/1/
I looking for a working solution with IE8+ so maybe there is a jQuery way to do that job? What is important for me is to keep the footer at the bottom of the viewport so that's why I used a obsolute position for footer. Thanks.
Something like this maybe :
LIVE EXAMPLE
html, body {
height: 100%;
}
#container {
height: 100%;
width: 100%;
display: table;
margin-top:-60px; //height of the footer
}
#body {
display: table-cell;
height: 100%;
vertical-align: middle;
}
.image {
background: url("http://lorempixel.com/300/200/nature/") no-repeat center;
height:200px;
}
#header {
background:#ccc;
padding:10px;
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
background:#ccc;
}
I had success with the following CSS:
html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ccc;
padding:10px;
position: relative;
}
#body {
padding:10px;
padding-bottom:60px;
position: relative;
}
.image {
background: url("http://lorempixel.com/300/200/nature/") no-repeat center ;
position: absolute;
height: 200px;
width: 100%;
top: 50%;
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px;
background:#ccc;
}
Source: http://www.w3.org/Style/Examples/007/center.en.html#vertical
Add this:
.image{
position: absolute;
top: 50%;
margin-top: -100px;
}
It works everywhere (except IE6-7, position relative may be needed there). You can do the same for horizontal centering.
Here is the fiddle: http://jsfiddle.net/hjcz6j0r/7/
I'm trying to make a 4 split landing page with an icon and a text underneath it, centered both horizontally and vertically inside each div. I tried various solutions, non of which seems to work, so i'm posting what i have so far. Here's a jsfiddle http://jsfiddle.net/W8gs3/
HTML:
<div id="rect1">
<p><img src="icon.png"/></p>
<p>Sound</p>
</div>
<div id="rect2">rect2</div>
<br />
<div id="rect3">rect3</div>
<div id="rect4">rect4</div>
<br />
CSS:
/* CSS Document */
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
div {
padding:0;
margin: 0;
width:50%;
height:50%;
float: left;
}
#rect1 {
background: #0066FF;
}
#rect2 {
background-color: #CC0033;
}
#rect3 {
background-color: #669966;
}
#rect4 {
background-color: #FFCC33;
}
br {
clear: left;
}
If you add an additional div into your html:
Sound
<div id="rect2" class="outer">
<div class="inner">rect2</div>
</div>
<div id="rect3" class="outer">
<div class="inner">rect3</div>
</div>
<div id="rect4" class="outer">
<div class="inner">rect4</div>
</div>
You can use the following styles:
div.outer {
padding:0;
margin: 0;
width:50%;
height:50%;
float: left;
display:table;
}
div.inner {
display:table-cell;
width:100%;
height:100%;
text-align:center;
vertical-align:middle;
}
Example
According to my understanding you want to align img to center, below is my suggestion
Make the img tag inline which you want to center align.
#rect1 p img {
display: inline;
width:30px;
height:30px;
}
#rect1 p {
text-align:center;
}
hope this will solve your problem
Add this code
HTML
<section>
<div id="rect1">
<p><img src="icon.png"/></p>
p>Sound</p>
</div>
<div id="rect2">rect2</div>
</section>
<section>
<div id="rect3">rect3</div>
<div id="rect4">rect4</div>
</section>
CSS
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
section{
position:relative; height:50%; width:100%; display:table;
}
div {
padding:0;
margin: 0;
width:50%;
height:50%;
display:table-cell;
text-align:center;
vertical-align:middle;
}
#rect1 {
background: #0066FF;
}
#rect2 {
background-color: #CC0033;
}
#rect3 {
background-color: #669966;
}
#rect4 {
background-color: #FFCC33;
}
Here is a working fiddle http://jsfiddle.net/W8gs3/14/
you can make center the image and text using the below CSS. check the DEMO.
#rect1, #rect1 p img {
background: #0066FF;
display:inline-block;
text-align:center;
}
#rect1 p{
margin:0;padding:0;
position: relative;
top: 50%;
transform: translateY(-50%);
}
If ancient browser support is not an issue, you can use css3 flexbox as follows:
div {
display:flex;
flex-direction:column;
justify-content:center;
align-items:center;
padding:0;
margin: 0;
width:50%;
height:50%;
float: left;
}
JSFiddle
try this
div {
padding:0;
margin: 0;
width:50%;
height:50%;
float: left;
text-align: center; /*add this*if it is necessary in the middle of all the elements*/
}
I made an HTML page that includes a header, 3 columns(left, main and right) and a footer.
In the main column I have a table with a height of 100%, so pretty large. Now I want to have my footer under the table.
I do not know what is wrong but my footer is not placed at the bottom, in my case it is almost at the middle of the main table.
The html, body and main class are also set to height 100% so that is working perfect.
The only problem is the footer..
On request here is some more code:
<body>
<div id="wrap">
<div id="hoofding"></div>
<div id="inner-wrap">
<div id="navigatie" style="font-family:old stamper">
<font size="9">Home</font>
</div>
<div id="main">
<div id="right"></div>
<table id= "tabel1">
<div id="inhoud">
<tr><td><p style="font-family:army of darkness"><font size="30">Lettertype 1: The Quick Brown Fox</font></p></td></tr>
<tr><td><p style="font-family:USSR army"><font size="30">Lettertype 2: The Quick Brown Fox</font></p></td></tr>
</div>
</table>
</div>
</div>
</div>
<div id="footer"><font size="1">Copyright © 2013 The Pack</font></div>
</body>
And the CSS file:
html {height:100%; width: 100%;}
body {
margin:0;
padding:0;
height:100%;
width: 100%;
background-color: blue;
}
#hoofding{
margin-right: auto;
margin-left: auto;
height: 355px;
width: 620px;
background-image: url(Afbeeldingen/The%20Pack.png);
}
#navigatie{
z-index: 15;
position: fixed;
height: 50px;
width: 8%;
margin-right: auto;
margin-left: auto;
padding-right: 1%;
padding-left: 1%;
}
#inhoud{
z-index: 2;
position: absolute;
padding-top: 3%;
padding-bottom: 3%;
}
#tabel1{
height: 100%;
width: 70%;
z-index: 1;
background-image: url(Afbeeldingen/Inhoud.png);
margin-left: auto;
margin-right: 15%;
bottom: 0;
padding:15px;
}
#wrap {
position:relative;
min-height:100%;
}
* html #wrap {height:100%; width:100%}
#inner-wrap {
padding-bottom:20px;
}
#inner-wrap:after {
content:" ";
display:block;
clear:both;
}
#footer {
position:absolute;
height:18px;
background-color: red;
bottom:0px;
color:white;
text-align:center;
clear:both;
}
#left {
position:fixed;
float:left;
width:10px;
text-align:center;
}
#main {
position:absolute;
margin-left:10px;
margin-right:10px;
width: 100%;
height: 100%;
}
#right {
float:right;
width:10px;
text-align:center;
}
#content {
padding:5px;
margin-right:10px;
text-align:left;
}
Thank You
use
bottom: 0;
rather than
margin-bottom: 0;
i think it will work for you.
Try:
#footer{
position:absolute;
bottom: 0px;
text-align: center;
}