I was trying to create a page like this image. But I'm stuck with the sidebar. I tried to make it float left and right. But some tricky problems! Tried to make the sidebar absolute positioned. But when the content area is large, the sidebar background is not keeping up with content area.
Can anyone help me to create a basic structure of this?
This is what I have used!
aside{
width: 215px;
background: #f9f9f9;
padding:5px 0;
padding:5px;
position: absolute;
top: 128px;
bottom:0;
left: 0
}
.main .content{
background:#fff;
padding:5px;
margin-left: 195px;
height:100%;
}
You can do it with absolute positioning on the sidebar, and a margin on the content: http://jsbin.com/ucihul/1/edit
The key properties are:
On the parent element of both sidebar and content: position: relative
On the sidebar:
bottom: 0;
left: 0;
position: absolute;
top: 0;
width: 215px; /* or whatever your fixed width is */
On the content div: margin-left: 215px (or whatever your fixed width is)
You can also have inner divs inside both the sidebar and content for additional control (they are in my demo, but I didn't do anything with them).
How about this:
HTML
<div id="sidebar">Sidebar</div>
<div id="content">Content</div>
CSS
#sidebar { float: left; width: 100px; background: red; }
#content { margin-left: 100px; background: blue; }
Fiddle: http://jsfiddle.net/j7dS5/1/
The easiest way to do this is graphically. Make an image that's as wide as the ".main" area and 1px tall that is colored appropriately for how wide you set your divs to be.
.main{
background:url(images/image.png) top center repeat-y;
}
aside{
width: 215px;
padding:5px 0;
padding:5px;
position: absolute;
top: 128px;
bottom:0;
left: 0
}
.main .content{
padding:5px;
margin-left: 195px;
}
Related
When we have some absolute DIVs in page and one fixed DIV as a child of one of those absolute DIVs that has bigger z-index than those absolute DIVs, the fixed DIV goes behind of absolute DIVs!
Like this: http://jsfiddle.net/3qRaR/1/
HTML:
<div class='l1'>
<div class='data'></div>
</div>
<div class='l1'>
<div class='data'></div>
</div>
<div class='l1'>
<div class='data'></div>
</div>
<div class='l1'>
<div class='data'></div>
</div>
CSS:
.l1{
display: block;
width: 100px;
height: 100px;
background-color: yellow;
z-index:1001;
margin: 5px;
position: absolute;
}
.l1:nth-child(1){
left: 5px;
top: 5px;
}
.l1:nth-child(2){
left: 110px;
top: 5px;
}
.l1:nth-child(3){
left: 220px;
top: 5px;
}
.l1:nth-child(4){
left: 330px;
top: 5px;
}
.data{
display:none;
position: fixed;
left:0px;
top:0px;
right:0px;
bottom:0px;
z-index:2000;
background: black;
}
.l1:first-child .data{
display: block;
}
Why?
How can I make it to go to the front of them?
Thanks
Remove the z-index from the .li rule and the black .data div will sit ontop of the yellow .li divs. I am assuming that is what you are trying to do?
.l1{
display: block;
width: 100px;
height: 100px;
background-color: yellow;
// Removed the z-index from here
margin: 5px;
position: absolute;
}
fixed makes divs fixed to document, not the element, even if it is absolute. Make .data divs of position absolute, not fixed.
http://jsfiddle.net/3qRaR/7/
.data{
display:none;
position: absolute;
left:0px;
top:0px;
right:0px;
bottom:0px;
z-index:2000;
background: black;
}
Edit:
If you want that fixed div to cover the entire document then just make the fixed div's container higher z-index than the rest:
http://jsfiddle.net/3qRaR/11/
.l1:nth-child(1){
z-index: 10000;
left: 5px;
top: 5px;
}
I have one main div that should make the page scrollable. On either side of this div there is a sidebar. The only difference I want from how it is now, is that the sidebars should always stay on top (position: fixed;)
I've tried everything, but it doesn't work. If I put position: fixed; on the .fixed, the width is no longer 100 % but the width of the actual contents inside. If I put on width: 100% the width turns 100 % of the viewport.
Is this even possible with just CSS?
JSFiddle: http://jsfiddle.net/6yWNv/
Sidebar 1
<div id="wrapper">
<div class="contents">
<p>Lorem ipsum dolor sit amnet.</p>
</div>
</div>
<div class="sidebar">
<div class="contents">
<div class="fixed">
Sidebar 2
</div>
</div>
</div>
html, body {margin: 0; padding: 0;}
#wrapper {
width: 54%;
float: left;
background: #0FF;
}
.sidebar {
width: 23%;
float: left;
}
.sidebar .contents {
margin: auto;
background: #F00;
min-width: 100px;
width: 55%;
height: 100px;
}
.sidebar .contents .fixed {
background: #0F0;
}
The trick is to set position:fixed on the sidebar (with left:0 and right:0 respectively) and then add margin-left:23% to #wrapper:
#wrapper {
width: 54%;
margin-left: 23%;
background: #0FF;
}
.sidebar {
width: 23%;
position: fixed;
left:0; top: 0;
}
#wrapper + .sidebar { /* target second sidebar */
left: inherit; /* reset left */
right:0;
}
if you want the green sidebars to stay in place, but the red boxes to move away, then something like this should work:
.sidebar {
width: 23%;
float: left;
position: relative; /* so sub-containers are relative to sidebar */
}
.sidebar .contents {
margin: auto;
background: #F00;
min-width: 100px;
width: 100%; /* relative to sidebar */
height: 100px;
}
.sidebar .contents .fixed {
background: #0F0;
position: fixed; /* starts a new context... */
width: 23%; /* so this is not relative to sidebar *.
}
Not possible with just CSS. When you make an element fixed, it removes it from its "context" and makes its new "context" the document. That's why specifying width: 100% on the position: fixed element spans the page.
Edit: I'm assuming that you want the green sidebars to stay in place but the red boxes to move away as you scroll (I'm making this assumption because of the way you've named your classes on your page).
you need to fix the sidebar, not its contents.
Just remove the float and set the position fixed to top and right
.sidebar {
width: 30%;
position: fixed;
top:0;
right:0;
}
I need the following to happen in my website:
The counter and logo (top, bottom) should always have the same height and stay on the top and bottom even though the screen height will decrease/increase. BUT the 2 other divs in between should get smaller/bigger when the window changes. I hope with this example its easier to understand:
The logo will disappear when the screen height is too low, right now. Here is the css:
The section is 80% width and aside 20%, but that doesnt really matter here...
#countdown{
padding: 0.5em 0.5em 0.5em 3em;
margin: 0.5em;}
#addProject{
margin: 0.5em;
padding: 0 1em;
height: 44%;
overflow-y: auto;}
#Nye{
margin: 0.5em;
padding: 0 1em;
overflow-y: auto;
height: 40%;
}
#logo{
margin: 1em;
height: 5em;
}
#Rémi offered a good start, but I would recommend using position: fixed.
This will anchor your elements to the browser window, regardless of the amount of your content.
e.g.:
.counter, .middle1, .middle2, .logo {
position: fixed;
width: 20%;
min-width: 200px;
right:0;
}
.counter {
background: yellow;
top:0;
height: 50px;
}
.middle1 {
overflow: scroll;
background: blue;
top:50px;
bottom: 50%;
}
.middle2 {
overflow: scroll;
background: green;
top: 50%;
bottom:50px;
}
.logo {
background: pink;
bottom:0;
height: 50px;
}
See http://jsfiddle.net/uKPEn/1/
It's a little tricky but I discovered by doing it that it is actually doable without javascript. Here is a fiddle to illustrate it http://jsfiddle.net/2LyUy/3/
You have to do 3 things:
wrap your two middle divs in a new div, for example with id="wrap".
put a different position attribute on your aside (for example "relative", which will actually not move your div at all)
then have fixed size counter and logo
The css gives that (don't forget to wrap your 2 middle divs with a new one):
aside#test { position: relative; }
/* so that the "absolute" below work as expected */
/* any of "relative" "absolute" or "fixed" positioning would work here, depending on the needs */
#countdown {
position: absolute; left:0; right:0; /* could be factored out if preferred */
top:0; height: 150px;
}
#logo {
position: absolute; left:0; right:0;
bottom:0; height: 50px;
}
#wrap {
position: absolute; left:0; right:0;
top:150px; bottom: 50px;
}
#addProject {
position: absolute; left:0; right:0;
top:0; height:50%;
}
#Nye {
position: absolute; left:0; right:0;
bottom:0; height:50%;
}
Here is the div wrapping code extract:
</div></div>
<div id="wrap"> <!-- added -->
<div id="addProject"
....
<br>
</div>
</div> <!-- added -->
<div .... id="logo"></div>
I'm working with a twitter widget.
CSS for SITE
#site {
background-color: #FFFFFF;
width: 1000px;
height:100%;
position: relative;
margin: 0 auto;
top:-20px;
box-shadow: 2.5px 4.33px 29px 0px rgb( 0, 0, 0 );
}
Here's my CSS for DIV
#twitter-widget-0 {
position: absolute;
right: 10px;
width:220px;
height: auto;
top:50px;
bottom: 100px;
}
I would like the height to fill the area in between the bottom and top position.
For example if the webpage size was 800px by 2000px. Then the twitter div height would become 1850px, or if the height of the page was 1000px the div would be 850px.
#twitter-widget-0 {
position: absolute;
right: 10px;
width:220px;
height: auto;
margin-top:50px;
margin-bottom: 100px;
}
Does this help?
Where is problem?
For check problem needed see code for outer area.
I think for fix you should just add position:relative; to outer area style.
For example: http://jsfiddle.net/DYtBE/
I am trying to achieve a dashed (custom) bored along the left and right of a 1000px fixed width page.
The left one is fine, this works a treat:
#border-left{
position: absolute;
float:left;
top: 0px;
bottom: 0;
width: 5px;
background-image: url('../img/border.gif');
background-repeat:repeat-y;
}
However when I do it over on the right hand side, it wont quite work. I need it to relatively position to the right of the 1000px rather than of the window.
#border-right{
position: relative;
right: 0;
top: 0;
bottom: 0;
margin-top: -90px;
width: 5px;
background-image: url('../img/border.gif');
background-repeat:repeat-y;
}
Parent element:
#container{
width:1000px;
display: block;
margin:0px auto;
text-align:left;
padding-top:90px;
}
That does not work. Can I achieve this? I need it to essentially float: right (but then i cannot make the height 100% of the browser window). Thanks
Demo: http://jsfiddle.net/iambriansreed/sAhmc/
Removed the floats on absolute elements. Added absolute position to parent and centered using left and margin. Removed unneeded margin-top on right border. Replaced border id's with classes.
Borders sit outside the 1000px width.
#container>.border{
position: absolute;
top: 0;
bottom: 0;
width: 5px;
background-image: url('../img/border.gif');
background-repeat:repeat-y;
}
#container>.border.left{
left: -5px;
background-color: red; /* demo */
}
#container>.border.right{
right: -5px;
background-color: blue; /* demo */
}
#container{
position: absolute;
top: 0;
bottom: 0;
width: 100px; /* demo */
left: 50%;
margin-left: -50px; /* half of width */
text-align: left;
padding-top: 90px;
overflow: visible;
background: #eee; /* demo */
}
I think adding a "position: relative;" rule to the #container element should work for you.