I'm making a simple blog theme and I want to have a little box displaying the post date on left off-set of each post like so: http://s21.postimg.org/fjygwqw1z/timestamp_Mockup.png
However, the post's container has an overflow-y set to scroll and attaching the timestamp div to each post won't show as it's hidden by the overflow. I can get around this if I set the timestamp div to position: absolute but then it doesn't stay in-line with the post and instead stays fixed in one place.
Here's a simple example: http://jsfiddle.net/MeVwt/
<style>
#leftCol{
width: 100px;
height: 500px;
background: green;
float: left;
}
#rightCol{
width: 400px;
height: 500px;
background: orange;
overflow-y: scroll;
float: left;
}
.content{
height: 700px;
width: 100%;
background: red;
}
.box{
width: 100px;
height: 100px;
background: purple;
margin-left: -50px;
}
</style>
<div id="leftCol">
</div>
<div id="rightCol">
<div class="content">
<div class="box"></div>
Fish
</div>
</div>
What I'm trying to do is make the purple box (.box) show outside its container (.content) and appear in the green area without setting it to a fixed position so it still scrolls with the content.
If you overlap the #leftCol with the #rightCol (by positioning them absolute to left:0; of their parent container), set the left margin to the width of the left column, then set .content position to relative and box position to absolute, and adjust the positioning using left.
Here is the updated CSS:
#leftCol{
position:absolute;
width: 100px;
height: 500px;
background: green;
left:0;
}
#rightCol{
position:absolute;
padding-left:100px;
width: 400px;
height: 500px;
overflow-y: scroll;
left:0;
}
.content{
height: 700px;
width: 100%;
background: red;
position:relative;
}
.box{
width: 100px;
height: 100px;
background: purple;
position:absolute;
left:-100px;
}
and a DEMO
Hope this helps =)
You could just create another div around the actual content and then float it next to the box.
Like this http://jsfiddle.net/MeVwt/3/
Downside with this is that you have to specify the width of the content for it to fill out all the width.
<div id="rightCol">
<div class="content">
<div class="box"></div>
<div class="content_text">
Fish
</div>
</div>
</div>
Css:
.content_text{
height: 700px;
background: red;
width: 335px;
float:left;
}
.box{
width: 100px;
height: 100px;
background: purple;
margin-left: -50px;
float:left;
}
html {
overflow-x: hidden; }
body {
overflow-x: hidden; }
Related
I want to keep header height constant while box on the right side of the header should get expanded as a I keep adding multi line content. Please see attached image
My Code
.parent {
width: 100%;
height: 200px;
background: #fff;
position: relative;
background: #1c1d1f;
}
.rightbar {
position: absolute;
width: 40%;
height: 500px;
background: #efefef;
}
.content {
width: 40%;
height: auto;
}
.footer {
width: 100%;
}
<div class="header">
<div class="rightbar">content inside box</div>
<div class="content">
some content goes here
</div>
</div>
<div class="footer">
footer content goes here
</div>
If you want a scrollbar appear in your right-side bar then you should try to use overflow-y:auto;
Like below:
.rightbar {
position: absolute;
width: 40%;
height: 500px;
background:#efefef;
overflow-y:auto;
}
I have 2 divs with min-height . The first one has a top property of 470px. I want the second div to display staright underneath the first div without any space between. I have also tried display: block and putting the divs into a table, neither of which worked any better. Here is te css:
#content {
width: 100%;
position: absolute;
top: 470px;
background: #1C1C1C;
min-height: 100px;
overflow: hidden;
}
#content2 {
width: 100%;
position:;
top:;
background: #333333;
min-height: 100px;
overflow: hidden;
}
HTML:
<div id="content">
<p>texttexttexttexttexttexttexttexttexttexttexttexttext</p>
</div>
<div id="content2">
<p>texttexttexttexttext</p>
</div>
Once you absolutely position an element you take it out of the document flow so you can't really have something come right after it unless you absolutely position it as well. I changed it to just use a top margin to put it where you want it. If you need elements in that top 470px then you can absolutely position those elements.
And the borders I put in are for illustration only.
#content {
border: 1px solid red;
margin-top: 470px;
background: #1C1C1C;
min-height: 100px;
overflow: hidden;
}
#content2 {
border: 1px solid blue;
background: #333333;
min-height: 100px;
overflow: hidden;
}
<div id="content">First DIV</div>
<div id="content2">Second DIV</div>
Because #content is positioned absolutely, you cannot do this without changing the HTML structure.
You can add a container element to the divs which is positioned absolutely with the same top as of #content1 and add the two divs inside the container without position.
#container {
width: 100%;
position: absolute;
top: 470px;
}
#content {
border: 1px solid red;
background: #1C1C1C;
min-height: 100px;
overflow: hidden;
}
#content2 {
width: 100%;
background: #333333;
min-height: 100px;
overflow: hidden;
}
<div id="container">
<div id="content">
<p>texttexttexttexttexttexttexttexttexttexttexttexttext</p>
</div>
<div id="content2">
<p>texttexttexttexttext</p>
</div>
</div>
You haven't posted your HTML, but this is my wild guess.
Try this:
<style>
#content {
width: 100%;
position: relative;
background: yellow;
min-height: 100px;
overflow: hidden;
}
#content2 {
width: 100%;
position: relative;
background: blue;
min-height: 100px;
overflow: hidden;
}
</style>
<div id = "content">
<p> Content - 1 </p>
</div>
<div id = "content2">
<p> Content - 2 </p>
</div>
I have a 1100px-width div general container which I'd call (A) that resizes to 925px in my aplication. In addition, I have a div which has to more divs inside: one has a static width (200px) which I'd call (B) and the other doesn't but has an horizontal scrollbar which I'd call (C).
I want when general container resizes (A) , the div (C) resizes,too and keep its scroll bar.
I have came up with this jsfiddle so far but I can't figure it out what I am doing wrong.
Pd: I have used different metrics for simulation.
¿How can I make the div child(C) resizes with general container(A) width?
.
Its latest update
fiddle
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
.container{
height:100px;
}
.left{
width:100px;
height:100px;
background-color:green;
float: left;
}
.right{
overflow-x:auto;
background-color:red;
width: 100%;
min-height: 100px;
}
.content{
width:600px;
position :relative;
}
.wrap{
overflow: hidden;
padding-left: 10px;
}
<div class="container">
<div class="left">
</div>
<div class="wrap">
<div class="right">
<div class="content">
CONTENT
</div>
</div>
</div>
</div>
(C) should not resize, but have a certain width (more than 900px, to get the scrollbar.). The container (A) does the resizing and should have min-width:925px
update:
it turned out to be a bit more complex:
http://jsfiddle.net/p7perzc6/
.a {
border: 1px solid #aaa;
width : 800px;
height: 200px;
}
.b {
width: 100px;
background-color: green;
height: 200px;
float: left;
}
.c {
background-color: orange;
height: 200px;
margin-left: 101px;
float: left;
overflow-x: scroll;
width: 900px;
position: fixed;
}
I'm trying to set these divs to align like this:
but they end up either overlapping eachother (.title takes full width of container) or underneath eachother. Ideas?
.wrapper{
display: table;
float: left;
width: 1000px;
height: 200px;
}
.pic{
float: left;
width: 100%;
height: 20%;
}
.title{
width: 100%;
height: 20%;
}
.content{
width: 100%;
height: 20%;
}
.footer{
width: 100%;
height: 20%;
}
HTML:
<div class="wrapper">
<div class="pic"><img src="..."></div>
<div class="title"><p>title</p></div>
<div class="content"><p>lorem ipsum</p></div>
<div class="footer"></div>
</div>
JS FIDDLE: http://jsfiddle.net/mmb84836/
As per the Best Practice:
Put Pic in one Box and the other three Boxes on right in one Box and use "float:left or **display:inline-block**for those.
Here is the code for the same:
HTML
<div class="wrapper">
<div class="leftBox">
<div class="pic">pic</div>
</div>
<div class="rightBox">
<div class="title">title</div>
<div class="content">content</div>
<div class="footer">footer</div>
</div>
</div>
CSS
div {
border:1px solid #000;
}
.wrapper {
display: block; /*Default Property - You Can Remove Also*/
width: 1000px;
height: 200px;
}
.leftBox {
float:left;
width :20%;
height:100%
}
.rightBox {
width :79.5%;
float:left;
height:100%
}
.pic {
width: 100%;
height: 100%;
}
.title {
width: 100%;
height: 20%;
}
.content {
width: 100%;
height: 20%;
}
.footer {
width: 100%;
height: 20%;
}
Here is the Working Fiddle: http://jsfiddle.net/7xLyc3q1/
You've got a lot of answers here, but none of them explain what is actually happening here. When using float, there's something important you need to understand: floated elements are lifted out of the box model and have effectively zero width and height as far as other elements are concerned. There is a workaround for this: by specifying overflow:hidden in the parent element, floated elements will no longer "collapse".
Here's an example that demonstrates this. Notice that the title, content, and footer have a width:100%, and they're only filling the space that is remaining for them -- this is probably what you'd expect to happen. Notice also that there was no need to float them to the right... they take the space that's left.
Try adding float: right to .title, .content, and .footer.
Also it may be worth considering using Foundation or Twitter Bootstrap. Both have grid systems so this would guarantee the divs would resize to fit any size screen.
<div class="wrap">
<div class="pic">pic</div>
<div class="other">oth1</div>
<div class="other">oth2</div>
<div class="other">oth3</div>
</div>
.wrap { width:100; height:200px; }
.pic { float:left; width:29%; height:100%; margin-right:1%; background-color:red; }
.other { float:left; width:70%; height:32%; margin-bottom:0.5%; background-color:green; }
and jsfiddle http://jsfiddle.net/t85kz39a/
Here is one way of doing it if you can specify a width for the image. I assumed that the image would be 200px wide in this demo.
Try the following CSS:
.wrapper{
width: 600px;
height: 200px;
padding-left: 200px;
border: 1px dashed gray;
}
.pic{
float: left;
width: 190px;
margin-left: -200px;
border: 1px dashed blue;
}
.pic img {
display: block;
}
.title{
width: auto;
height: 20%;
border: 1px dotted blue;
}
.content{
width: auto;
height: 20%;
border: 1px dotted blue;
}
.footer{
width: auto;
height: 20%;
border: 1px dotted blue;
}
The trick is to open up a space to place the image. Add a 200px wide left padding to
the .wrapper.
The padding will force .title, .content and .footer to align 200px from the edge
of the wrapper.
For .pic, set the width to 200px (or smaller) and set the left margin to -200px to move
it into the padding area.
Finally, set the correct width for .wrapper, 600px. The overall width of .wrapper
will compute to 800px (600px width + 200px left padding - -200px left margin from the
float).
See demo: http://jsfiddle.net/audetwebdesign/mgg1stmc/
The main benefit of this approach is that you don't need to add any other wrapping
elements. (If you use floats, the extra wrappers are necessary.)
There's a much simpler css-only way without changing your HTML structure:
Demo http://jsfiddle.net/bfhng3a9/
All you need:
.wrapper {
overflow:auto;
text-align:center;
}
.pic {
float: left;
width:20%;
}
.title, .content, .footer {
width:80%;
float:right;
clear: right;
}
You can use this code and it is working according to your design.
Live Working Demo
HTML Code:
<div class="wrapper">
<div class="pic"><img src="..."/></div>
<div class="title"><p>Title</p></div>
<div class="content"><p>Content</p></div>
<div class="footer"><p>Footer</p></div>
</div>
CSS Code:
.wrapper{
position: relative;
float: left;
width: 1000px;
height: 200px;
border: 1px solid #000000;
}
.pic{
float: left;
width: 300px;
height: 200px;
background-color: red;
position: relative;
}
.title{
width: 650px;
height: 60px;
background-color: green;
position: relative;
left: 350px;
top:-16px;
}
.content{
width: 650px;
height: 60px;
background-color: blue;
position: relative;
left: 350px;
top: -22px;
}
.footer{
width: 650px;
height: 60px;
background-color: gold;
position: relative;
left: 350px;
top: -28px;
}
Result:
This is difficult for me to ask.
In short: my div overlaps (gets outside the table). I want the table to be sized according to the div.
When I'm trying to add a footer, the content overlaps it. Here is the code:
Here is the page: page
the .middle css class sets the height of the center content to 25px The footer is therefore positioned related to the menu table content on the left.
If you remove the 25px from the css class the div should work as you expect
Ok I will suggest you rewrite your site because it's total mess, use my template for starters:
<div class="wrap">
<div class="header"></div>
<div class="body">
<div class="left-side"></div>
<div class="center"></div>
<div class="right-side"></div>
</div>
<div class="footer"></div>
</div>
And css:
.wrap{
width: 400px;
height: 500px;
margin: 0 auto;
}
.header{
width: 100%;
height: 50px;
background-color: #dddddd;
}
.body{
width: 100%;
height: 350px;
}
.left-side{
position: relative;
float: left;
width: 20%;
height: 100%;
background-color: #eeeeee;
}
.center{
position: relative;
float: left;
width: 60%;
height: 100%;
background-color: #cccccc;
}
.right-side{
position: relative;
float: left;
width: 20%;
height: 100%;
background-color: #eeeeee;
}
.footer{
width: 100%;
height: 100px;
background-color: #dddddd;
}
Here is live example in jsFiddle
well, #Arturas.. I kinda agree with #skmasq for your website. I think it'll be better if you're not using table for the layout. but, if still want to use your current website source code, try to delete the .middle's height property. because you set it fixed 25px, but the content is overload, that's why it's overlapping.