.top{
width:100%;
height:50vh;
background-color:red;
}
.bot{
width:100%;
height:50vh;
background-color:black;
}
.content{
position:relative;
width:50px;
height:50px;
background-color:white;
left: 0px;
bottom:0px;
}
<div class='top'>
<div class='content'>
</div>
</div>
<div class='bot'>
</div>
content is not laying on the inner bottom of the first div .top, why not position:relative bottom:0px works , while positioning on absolute it comes in bottom of the screen , so can I lay that div on the bottom of the first div .top using position absolute, content width height have to change though.
Add position: relative to .top and set position: absolute to .content
.top{
width:100%;
height:50vh;
background-color:red;
position:relative;
}
.bot{
width:100%;
height:50vh;
background-color:black;
}
.content{
position:absolute;
width:50px;
height:50px;
background-color:white;
left: 0px;
bottom:0px;
}
<div class='top'>
<div class='content'>
</div>
</div>
<div class='bot'>
</div>
bottom 0px not works with position relative , and if you want to do with postion relative i found a solution for you
.top{
width:100%;
height:50vh;
background-color:red;
}
.bot{
width:100%;
height:50vh;
background-color:black;
}
.content{
position:relative;
width:50px;
height:50px;
background-color:white;
left: 0px;
bottom: calc(-100% + 50px);
}
<div class='top'>
<div class='content'>
</div>
</div>
<div class='bot'>
</div>
Related
I have html page ,container div contain header ,content and footer div ,the html cod and css code is like this:
HTML-Code:
<html>
<div class="container">
<div class="header"></div>
<div class="content">
<div class="content2"></div>
</div>
<div class="footer"></div>
</div>
</html>
Css code:
header{
padding-bottom:5px;
width:100%;
position:fixed;
top:0;
z-index:100;
height:70px;
background-color:#006}
.content{
min-height: 100%;
width:100%;
background-color:#006;
margin-top:70px;
margin-bottom:60px }
.content2{
margin:auto;
min-height: 100%;
width:95%;
background-color:#FFFEA5;
padding-bottom: 20px;
}
.footer{
text-align:center;
width:100%;
position:fixed;
bottom:0;
z-index:100;
height:70px;
background-color:#006}
I want the content2 div be full screen either it didn't contain anything ,i did codes above but didn't work ,it is appear like attached image.
Maybe you could try to put all those divs to a parent div like and set to that div 100% width and height(height is not necessary, it will set 100% too) and then you will have div container occupying all screen.
I believe you are missing and need body tag (among other things) which will set whole background to blue.
body{
background-color:#006
}
header{
padding-bottom:5px;
width:100%;
position:fixed;
top:0;
z-index:100;
height:70px;
background-color:#006}
.content{
min-height: 100%;
width:100%;
background-color:#006;
margin-top:70px;
margin-bottom:60px }
.content2{
margin:auto;
min-height: 100%;
width:95%;
background-color:#FFFEA5;
padding-bottom: 20px;
}
.footer{
text-align:center;
width:100%;
position:fixed;
bottom:0;
z-index:100;
height:70px;
background-color:#006}
<html>
<body>
<div class="container">
<div class="header"></div>
<div class="content">
<div class="content2">test</div>
</div>
<div class="footer"></div>
</div>
</body>
</html>
Thank you for all of you ,i changed css files and made it like this ,and it is works now :
.header{
padding-bottom:5px;
width:100%;
position:fixed;
top:0;
z-index:100;
height:70px;
background-color:#006}
.footer{
text-align:center;
width:100%;
position:fixed;
bottom:0;
z-index:100;
height:70px;
background-color:#006}
.content{
min-height: 100%;
width:100%;
background-color:#FFFEA5;
margin-top:70px;
margin-bottom:60px }
.content2{
height: 100%;
margin:auto;
width:95%;
background-color:#FFFEA5;
padding-bottom: 80px;
}
.wrapperDiv{
background-color: #006;
padding:0;
margin:0;
height: 100%;
}
I have several divs, each 2px wide and they dont look the same (depending on their position). Although they are placed on full pixel, their width looks different. This is the problem in all browsers. Is this something that can be fixed?
.a{
position:relative;
width:300px;
height:10px;
background:#ccc;
}
.b1{
position:absolute;
left:50px;
width:2px;
height:100%;
background:blue;
}
.b2{
position:absolute;
left:100px;
width:2px;
height:100%;
background:blue;
}
.b3{
position:absolute;
left:150px;
width:2px;
height:100%;
background:blue;
}
<div class="a">
<div class="b1"></div>
<div class="b2"></div>
<div class="b3"></div>
</div>
If you mean that the first "bar" is 50px from the start and then the distance between the bars decreases by a little, it is because you do not include the width of the bar in the offset of the 2nd and 3rd "bar":
.a{
position:relative;
width:300px;
height:10px;
background:#ccc;
}
.b1{
position:absolute;
left:50px;
width:2px;
height:100%;
background:blue;
}
.b2{
position:absolute;
left:102px;
width:2px;
height:100%;
background:blue;
}
.b3{
position:absolute;
left:154px;
width:2px;
height:100%;
background:blue;
}
[class^="b"]:after {
content: '50px';
width: 50px; height: 2px;
position: absolute; bottom: -2px; left: -50px;
text-align: center;
font-size: 11px; font-family: sans-serif;
background: lightcoral;
}
<div class="a">
<div class="b1"></div>
<div class="b2"></div>
<div class="b3"></div>
</div>
This is what I've tried so far:
.content{
margin-bottom: 50px;
}
.bottom{
position:absolute;
height:50px;
line-height: 50px;
bottom:0;
width:80%;
background:green;
}
<div class="content">
......
</div>
<footer class="bottom">
<p>
this is always at bottom
</p>
</footer>
Here is a Fiddle is an example too.
Did someone know why this happen, and how I can solve it?
Thank you!
1.You have make small change in CSS.According to your demo link.
.parent {
height:1500px;
width:200px;
border:1px solid grey;
position: relative;
background-color: white;
}
.topDiv {
display:block;
background:silver;
width:100px;
height:100px;
position:absolute;
top:0;
left:0
}
.bottomDiv {
background:red;
width:100px;
height:100px;
position:absolute;
bottom:0;
}
body {
height:1500px;
background: linear-gradient(#111, #777);
}
You have to use position:fixed, to achieve this !!
CSS
<style type="text/css">
.content{
margin-bottom: 50px;
}
.bottom{
position:fixed;
height:50px;
line-height: 50px;
bottom:0;
width:80%;
background:green;
}
</style>
HTML
<div class="content">
......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br> ......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br> ......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br> ......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br> ......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br> ......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>......<br>
</div>
<footer class="bottom">
<p>
this is always at bottom
</p>
</footer>
This question already has answers here:
CSS side by side div's auto equal widths
(5 answers)
Closed 8 years ago.
In my layout in the main part of site I need two flexible columns. The height is known and always the same. But the width should be auto-increases with the width of the browser.
I need this because in div#1 should be different content (float right I supposed) and background than in div#2 (float left I supposed). Whole layout is increasing their width with browser (width 100%).
It would be easy to make if the background of div 1 and 2 is the same (wrapper + background set on parent) but in this example backgrounds are different. I do not know how to auto-increase the width of these two divs.
adjust the width parameter of div#1 and div#2
div #header {
display: block;
position: absolute;
top: 0px;
height: 100px;
}
div #div1 {
display: block;
position: absolute;
top: 100px;
width: 50%;
left: 0px;
}
div #div2 {
display: block;
position: absolute;
top: 100px;
width: 50%;
right: 0px;
}
this is what you want:
<div class="container">
<div class="header">
This is header
</div>
</div>
<div class="container">
<div class="div1">
This is left div
</div>
<div class="div2">
This is right div
</div>
</div>
<div class="container">
<div class="footer">
This is footer
</div>
</div>
.container{
max-width:960px;
padding:0 15px;
height:auto;
position:relative;
clear:both;
}
.header{
position:relative;
height:100px;
background-color:yellow;
width:100%;
display:block;
}
.div1{
position:relative;
height:400px;
background-color:pink;
width:50%;
float:left;
}
.div2{
position:relative;
height:400px;
background-color:green;
width:50%;
float:left;
}
.footer{
position:relative;
height:100px;
background-color:cyan;
width:100%;
display:block;
}
I've created a jsfiddle demo
What about a good, simple, semantic layout? The below uses positioning to maintain a fixed footer, here is an example without
Demo Fiddle
HTML
<header></header>
<section></section>
<section></section>
<footer></footer>
CSS
html, body {
height:100%;
width:100%;
margin:0;
}
header, footer, section {
position:absolute;
width:100%;
}
header, footer {
background:green;
height:50px;
}
footer {
bottom:0;
}
section {
top:50px;
bottom:50px;
width:50%;
background:yellow;
overflow-x:auto;
}
section:last-of-type {
background:blue;
left:50%;
}
Try this
#container{
width:100%;
clear:both;
}
#header{
width:100%;
}
#div1{
height:400px;
width:50%;
float:left;
}
#div2{
height:400px;
width:50%;
float:right;
}
#footer{
width:100%;
}
I have one DIV positioned right.
.right {
width:25%;
height:100%;
background-color:#000;
position:fixed;
right:0px;
z-index:1;
And left
.left {
width:25%;
height:100%;
background-color:#000;
position:fixed;
left:0px;
z-index:1;
And I'm trying to put this circle
.circle {
height:100px;
width:100px;
border-radius:50px;
background-color:#F00;
position:fixed;
left:45%;
z-index:99;
in the middle
this is my HTML
<div class="left">
</div>
<div class="centerc">
<div class="circle">
</div>
<div class="right">
</div>
What am I doing wrong and how do I fix it?
Your code seems to be working. However, the circle is off-center.
I suggest that you define the circle's position as 50% of the container's width minus 50% of the circle's width:
.circle {
...
width:100px;
left:50%;
margin-left:-50px;
}
Also, since everything is position:fixed, I don't see the purpose of div.centerc. I removed it.
<div class="left"></div>
<div class="circle"></div>
<div class="right"></div>
Working example (jsFiddle)
Try to put this inside .circle styling:
left:50%;
margin-left:-50px;
left:50%; will put the left side of the .circle in the middle of the screen, then margin-left:-50px; will put the .circle 50px to the left (half of its width).
Also, it's a good idea to remove the non-closed .centerc div.
Demo
*{margin:0;}
body{
background:#fff;
}
.left{
position:fixed;
height:100%;
width:25%;
left:0;
background:#222;
}
.circle{
z-index:1;
position:fixed;
width:100px;
height:100px;
left:50%; /* Left side of the circle centered */
margin-left:-50px; /* A half of circle width to the left */
border-radius:50px;
background:#F33;
}
.right{
position:fixed;
height:100%;
width:25%;
right:0;
background:#222;
}
<div class="left"></div>
<div class="circle"></div>
<div class="right"></div>
If you are meaning to have the left and right divs aligned and the circle div floating over them in dead center here's a quick fiddle to set you in that direction.
http://jsfiddle.net/Hastig/zLsbE/
I added a container div wrapped around all three (left, right and circle) and set it to position: relative
I then set the circle div to position: absolute and played with it's left and top alignment to center it.
Note - It's not a responsive solution.
.container {
width: 500px;
height: 250px;
position: relative;
}
.left {
float: left;
width: 250px;
height: 250px;
background-color: #000;
}
.right {
float: right;
width: 250px;
height: 250px;
background-color: #555;
}
.circle {
height: 100px;
width: 100px;
border-radius: 50px;
background-color: #F00;
position: absolute;
top: 75px;
left: 200px;
}
<div class="container">
<div class="left"></div>
<div class="circle"></div>
<div class="right"></div>
</div>
http://jsfiddle.net/R8YRh/1/ demonstrates using:
.centerc {
text-align:center;
}
and the addition of display: inline-block; to .circle. This required the addition of top: 0; to .right.
.left {
width:25%;
height:100%;
background-color:#000;
position:fixed;
left:0;
z-index:1;
}
.right {
width:25%;
height:100%;
background-color:#000;
position:fixed;
right:0;
top: 0;
z-index:1;
}
.centerc {
text-align:center;
}
.circle {
display: inline-block;
height:100px;
width:100px;
border-radius:50px;
background-color:#F00;
z-index:99;
}
<div class="left"></div>
<div class="centerc">
<div class="circle"></div>
</div>
<div class="right"></div>