Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have tried overflow and using clear: both; but I can't get the child div heights to be equal, I don't want the heights to be static. Can someone help me achieve this?
Here is fiddle showing the problem.
Since you seem to have static widths, but you don't want static heights, you could fix it by setting the container div to position: relative; and then having one div float left, and positioning the other div's absolutely. Something like in this jsFiddle.
The one floating div will ensure the container div has a height, and the absolutely positioned div's will automatically resize to the same height as the floating div. You would then have to set overflow-y: auto on the absolutely positioned div's to ensure that scroll bars will appear inside of them if their height exceeds the height of the floating div. This should work in all browsers.
div.container {
position: relative;
width: 800px; // height will be determined by the content of div.left
}
div.left {
float: left;
width: 400px; // height will be determined by its content
}
div.middle, div.right {
position: absolute;
overflow-y: auto;
width: 200px;
bottom: 0px; // These two lines will ensure that this div's height
top: 0px; // is equal to the height of div.left and div.container
left: 400px; // Value should be equal to the width of div.left
}
div.right {
left: 600px; // Value is the sum of the width of div.left and div.middle.
}
P.S. If all you want is for the background-color to fill the whole container div (as your post title suggests), you could just set the background-color on the container div.
Well, the best way to achieve this without Javascript would be to use css3 flexible layouts
#newTask .body {
display: -webkit-flex;
-webkit-flex-direction: row;
}
Something like this, but prefix of the browser you are using.
You can use display: table; on #newtask .body and then display: table-cell; on all of its child divs (left, middle, right).
This would make it behave like a table and would ensure that all divs are of equal sizes.
#newtask .body {
display: table;
}
#newtask .body > div {
display: table-cell;
height:100%;
}
Fiddle: http://jsfiddle.net/mv46q/1/
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a problem with my school project. I want to make two columns on my page using css, but nothing is working...
Website : http://kitlab.pef.czu.cz/~wbdinfo141528/
CSS : http://kitlab.pef.czu.cz/~wbdinfo141528/css/style.css
I hope that there is some dumb mistake, but I can't figure out, where the problem is.
I want to place the right column next to the left one :
Your margin was taking up the entire row, that's why the second div was pushed down. You don't need margin, just set the width and display it as an inline-block. The inline-block means it'll still be a block, but will wrap like text - so if there's enough space for the second div to be in the same row as the first, it can be.
Replace CSS with this, comments for what was changed.
div.leva {
background: blueviolet;
/* float: left; */
/* margin: 5px 500px auto auto; */
width: 49%;
display: inline-block;
}
div.prava {
background: yellow;
/* float: left; */
/* margin: 5px auto auto 500px; */
display: inline-block;
width: 49%;
}
Alternatively, you can use a relative container div and set that to 100%, and have two absolute divs inside the container with 50% width.
HTML
<div class="container">
<div class="leftdiv"></div>
<div class="rightdiv"></div>
</div>
CSS
.container {
position: relative;
width: 100%;
}
.leftdiv, .rightdiv {
position: absolute;
width: 50%;
top: 0;
}
.leftdiv {
left: 0;
}
.rightdiv {
right: 0;
}
You must add margin:0 in div leva et prava http://jsfiddle.net/rvp5js2w/
At first glance your floats are incorrect.
The purple is floated right while the yellow is floated left.
Set a width (where width is less then total width of stranka/2) for each of these div's and then float them correctly and it should line up.
I have two elements, both with display: inline-block, and the parent has white-space: nowrap.
When the screen is resized, the div on the right side don't resize, like this.
I'm trying to make only the blue div resize.
Full source (jsfiddle)
The structure of the html is like this:
<div class="container">
<div class="header">...</div> <!-- red -->
<div class="aside">...</div> <!-- pink -->
<article>...</article> <!-- blue -->
</div>
Relevant css:
* {
box-sizing: border-box;
}
div.container {
margin: 0 auto;
max-width: 40em;
padding: 0;
white-space: nowrap;
}
div.container > * {
white-space: normal;
}
.aside {
display: inline-block;
max-width: 15em;
vertical-align: top;
}
.article {
display: inline-block;
max-width: 25em;
}
Old question, but for the sake of knowledge of anyone who reads this and also has the doubt:
What I've found is that setting position: relative on the .container
and position: absolute on the .article does what I want.
An absolute positioned element is positioned relative to the nearest positioned ancestor, where a positioned element means anything with a position property different to static, the default; if does not found any positioned element, uses the body element.
The absolute positioned elements, if has their width and heigth in auto, resizes to fit its content, and limits the maximun sizes by its positioned ancestor. You can check this putting a short string instead a large one: the element will shrink to the length of text. If you remove the positioning from div.container, the article (if still positioned absolute) will grow (depending on its content) to cover the space between previous element and body width.
And, related to the aforementioned and to add some utility to this delayed answer, a not-very-know bonus: if you define the right and left properties of a absoluted positioned element, and leave the width in auto, the element will cover the horizontal size between the right and left defined. This way you could put something like
article {
background-color: #a0f4ec;
display: inline-block;
position: absolute;
right: 0;
left: 30%;
}
div.aside {
background-color: #faf;
display: inline-block;
max-width: 15em;
width: 30%;
}
This trick also applies in a vertical sense, but with height, top and bottom properties.
There are a few ways to do it.
Method 1:
two divs the same line, one dynamic width, one fixed
Method 2 (negative margins)
http://alistapart.com/article/negativemargins
Unfortunately, Narxx's answers require the divs to be floated. I'm sure that's what you should do if you're building a real site, but in my case, I'm trying not to use it.
What I've found is that setting position: relative on the .container and position: absolute on the .article does what I want.
Simplified fiddle
If anyone can explain why, I'll mark it as an answer.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to createa a div, who has some links, and a logo image. The thing is that I don't want that the div to resize to the image size. I want that the image ovelap the div. I want something like the image. But when I add the image inside the div, the div size is increased to contain the image.
What you are saying is that you want to remove the image from normal flow. There are several ways to do that:
Float
img {
float: left;
margin: <position it with this>;
}
Floating is handy because it will remove the element from normal flow, while still giving you the option of clearing the float. It will also push the float: right navigation away when near. The only downside is that it's not as powerful as absolute.
Absolute
#nav {
position: relative; /* child positioned in relation to the first element with non-static position */
}
img {
position: absolute;
z-index: 1;
left: <position it with this>;
top: <position it with this>;
}
Absolute completely removes the element from flow, so it won't interfere with anything, including the right navigation (this could be a downside). You can position it accurately with left and top.
Negative Margin
img {
margin-bottom: <some negative number>;
}
This will pull the bottom of the container up, making it look like it's out of normal flow, without the consequences of that. I personally prefer this solution. It will work as long as you can calculate the correct margin-bottom for it to look right.
Plain, fixed height
#nav {
height: <some height>;
}
The simplest solution: just give your navigation a set height.
You can use absolute positioning:
HTML:
<div class="main">
<div class="image">Image Div</div>
</div>
CSS:
.main {
border: 1px solid green;
width: 50%;
height: 50px;
}
.image {
position: absolute;
top: 20px;
left: 20px;
width: 100px;
height: 100px;
border: 1px solid blue;
}
You can try it here.
My goal is to get a sidebar layout which should scale based on the browser window width. Some parts should have a scaled width, others should have a static width and some should scale but with a min/max-width. (It also would be great if some would expand based on the content within)
The html:
<div id="table">
<div id="row">
<div id="sidebar">at least 90px width<br/>not more than 130px width</div>
<div id="content">scale</div>
<div id="logo">should be static 60px</div>
<div id="sidebar2">at least 90px width</div>
</div>
</div>
and the css:
#table {
display: inline-table;
width: 100%;
}
#row {
display: table-row;
}
#table #row div {
display: table-cell;
}
#sidebar {
width: 10%;
min-width: 90px;
max-width: 130px;
}
#content {
width: 70%;
}
#logo {
min-width: 60px;
background-color: #FAB6B8;
}
#sidebar2 {
min-width: 90px;
width: 20%;
}
The issues:
It appears that max-width has no effect on dom-elements with display:table-cell assigned. (I guess)
I tried to work with another div, spans around the actual cell div.
This causes the problem, that the cell scales perfectly, but the left side of the content div will not stick to the first sidebar. (Same problem, if I put the "max-width div" inside the cell)
Working with a float: left layout doesn’t work either. (Float breaks if window gets too small; don’t scale, if I use a div to protect it)
Is there a way to work around this without using js?
Put in a div in #row with no further CSS will work for a div, which expand based on content. Sadly if there is just text in it breaks after every word. How can I prevent this and be able to set a max width and hide the overflow?
I found the Answer by myself:
The key is to apply absolute width to the elements, which should get a max width.
It's not perfect, because the divs with an absolute width don’t scale, until the one with a relative width reach their min-widths but I guess it’s the only way.
So simple.
Sorry for the trouble...
How can I vertically align a table in the middle of the screen with css?
Generally something along the lines of this works pretty well in any block element with a defined height.
table {
position: absolute;
top: 50%;
margin-top: -50%;
}
Centering on the page is harder since you don't have a defined height, but I think this works.
html {
height: 100%;
}
You may encounter some browser differences, act accordingly.
Shortly said, just make your body a table, because vertical-align does work on table-cells:
body, html {
height: 100%;
}
body {
display: table;
}
#wrapper {
display: table-cell;
vertical-align: middle;
height: 80%;
}
This will vertical align your pagewrapper to middle and let it be fluid 80%
If you can give the table a fixed height, then feel free to adapt the CSS from this site I've just done.
Bit complicated to explain, but basically you set a 1 pixel high 'horizon' at 50% height of the screen around your content, then offset the top of the element to be centred (i.e. your table) by 50% of its height.
EDIT: Here's the article I originally made my solution from, with explanation & everything.