I'm having an issue using display: table and display: table-cell.
Fiddley: http://jsfiddle.net/5q51sbqb/1/
I have a div with a display:table; and within that two divs with display:table-cell;
The left div (.t1) is a fixed width and the right div(.t2) should take up the rest of the space to the edge of the container.
My issues lies with adding a long div (2000px) to the right div(.t2). I basically need the content-window to stay the same width as its parent without pushing out further than the confines of the container, as to allow the content within to be scrolled.
Keep in mind this needs to be without using a fixed width, as the container and t2 are both responsive. And I also have to use table and table-cell display properties :(
So basically the children of the .t2 div are flowing beyond the container when I need them to fit within the container width ( without setting a fixed width on the content-window ... and on the .t2 div)
I'm stumped.
HTML
</div>
</div>
<div class="table-cell t2">
<div id="content-window">
<div id="content"></div>
</div>
</div>
</div>
</div>
CSS
#container{
width: 600px;
height: 600px;
margin: 0px auto;
background-color:green;
padding: 2px;
}
#table{
display:table;
width:100%;
}
.table-cell{
display:table-cell;
height: 300px;
padding:2px;
}
.t1{
width: 100px;
background-color: red;
}
.t2{
width:auto;
background-color: blue;
}
#content-window{
width:100%;
overflow:scroll;
}
#content{
width: 2000px;
height: 50px;
background-color:yellow;
}
Since you smartly created a #content-window, set it to be a position: absolute; so it won't mess up the cell's auto width. Just remember to set the .t2 to be a position: relative, so the #content-window might fill it in width and height, using the contained space of the right table cell.
tip: Use overflow-x if you want it to scroll only horizontally.
#container{
width: 600px;
height: 600px;
margin: 0px auto;
background-color:green;
padding: 2px;
}
#table {
display:table;
width:100%;
}
.table-cell{
display:table-cell;
height: 300px;
padding:2px;
}
.t1 {
width: 100px;
background-color: red;
}
.t2 {
position: relative;
background-color: blue;
}
#content-window{
position: absolute;
width:100%;
height: 100%;
overflow: hidden;
overflow-x: scroll;
height:50px;
}
#content{
width: 2000px;
height: 50px;
background-color:yellow;
}
Check it here: http://jsfiddle.net/5q51sbqb/4/
Related
I have been looking for an answer to this question but have not found anything. I have searched stack overflow and other resources. The question has been asked before and I have tried each of them the answers.
How can I get the div's to take up 100% of the vertical distance between the header and footer?
Here's my code:
HTML
<div class="page-wrap">
<header>This is the header</header>
<div id="container">
<div id="left">Left</div>
<div id="right">Right</div>
<div id="main">Main</div>
</div>
</div>
<footer class="site-footer">
I'm the Sticky Footer.
</footer>
CSS
/* * {
margin: 0;
} */
html, body {
width: 100%;
height: 100%;
margin:0;
}
.page-wrap {
min-height: 100%;
/* equal to footer height */
margin-bottom: -80px;
}
.page-wrap:after {
content: "";
display: block;
}
.site-footer, .page-wrap:after {
height: 80px;
}
.site-footer {
background: #265a88;
}
#left{
text-align:center;
color:white;
background-color: black;
height: auto !important;
height: 100%;
border: black dash;
float: left;
width: 20%;
min-height:100%;
overflow: scroll;
}
#right{
min-height:100%;
text-align:center;
color:white;
background-color: black;
height: 100%;
float: right;
width: 20%;
}
#main{
text-align:center;
color:white;
background-color: blue;
height: 100%;
border: black dash;
float: right;
width: 60%;
max-height:100%;
overflow: scroll;
}
header{
background-color: #265a88;
color:white;
text-align:center;
padding:5px;
}
You need to set the dimensions of container as such:
#container{
height: 100%
width: 100%
position: absolute;
}
However, in your case, you will have to set the height of the container so that it does not overflow and go over the footer.
In order for a child element to take 100% of the parent's height, the parent must have a set height (ie can't be a percent). This applies to all child elements besides the body tag, who's parent is html, and html set to 100% does provide a set pixel height for child elements. The easiest workaround for this is to use some javascript to calculate the height of a given parent element, and then set the child element accordingly. I am not aware of any pure css solution, that doesn't require some fiddling with properties such as line-height. As far as I know, this is a very common issue for web developers, and one which really depends on your flexibility of technology used and how hacked you want your css to look.
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;
}
Just tired up with the problem with 2 div aligning vertically. I tried horizontal scroll is appear in browsers, how to get rid of scroll?
I have this html:
<div id="responsive-admin-menu"></div>
<div id="content-wrapper"></div>
The css code is
#responsive-admin-menu {
width: 200px;
left:0px;
background-color: #404040;
height: 100%;
position: absolute;
min-height: 500px;
}
#content-wrapper {
position:absolute;
overflow:auto;
width:100%;
margin-left: 200px;
right:200px;
background-color: #fff;
padding: 15px;
}
I assume you want to create a two columns fluid layout, where you have your #responsive-admin-menu to the left and #content-wrapper to the right, and they fill the entire browser window.
In this case I suggest to define the width of both divs in percent and let them float one to the left and the other to the right:
#responsive-admin-menu {
width: 30%;
float:left;
}
#content-wrapper {
width: 70%;
float:right;
}
take a look here where I edited your code.
My Codepen
Use left/top/right/bottom for to give "anonymous" width and height.
Your CSS
#responsive-admin-menu {
position: absolute;
width: 200px;
left:0px;
top:0px;
bottom:0px;
background-color: #404040;
min-height:500px;
}
#content-wrapper {
position:absolute;
overflow:auto;
top:0px;
left:200px;
right:0px;
background-color: green;
padding: 15px;
}
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; }
I want to align a left div vertically in middle of right div. I am able to do that by using display:table-cell; but then I cannot use the float:left
Here's what I'm trying:
HTML:
<div class="wrapper">
<div class="left"><h1><img src ="img.png" /></h1></div>
<div class="right">Right</div>
</div>
CSS:
.wrapper{
overflow: hidden;
border: 1px solid blue;
width: 400px;
}
.left{
border: 1px solid red;
max-width: 200px;
max-height: 50px;
float: left;
overflow: hidden;
display:table-cell;
vertical-align:middle;
}
img{
display: block;
}
.right{
width: 200px;
height: 200px;
float: right;
border: 1px solid green;
}
Demo:
http://jsfiddle.net/fmpLt/
Though I am not clear about what you are expecting, I have tried the below code. check if it can help you
Add display:table to .wrapper then table-cell to .left
DEMO
Another solution with position:absolute
.wrapper{
overflow: hidden;
border: 1px solid blue;
width: 400px;
position:relative; background:yellow
}
.left{
border: 1px solid red;
max-width: 200px;
max-height: 50px;
overflow: hidden;
position:absolute;
top:50%; margin-top:-25px
}
DEMO 2
If you know the left div height (eg.50px), you could set a position:relative to the wrapper container and the left div, then set a top position of 50% to the left div, with a margin-top equal to minus 50% of height.
Eg.
.wrapper{
...
position:relative;
}
.left{
...
position:relative;
height:50px;
top:50%;
margin-top:-25px;
}
You could use margin-top set to half the height of .right less half the height of the image. In this case, that would be margin-top: 68px.