Need some help with making the following layout work in IE:
Light gray is a browser window. Dark gray is the main content area, centered against the window. To its left is a fixed width yellow box, and to its right is a variable width green box. The yellow+blue+green triplet is then repeated down to the bottom (it's basically a simple blog layout).
I got this working in Firefox/Chrome by using negative margin-left and floating all three colored boxes. The IE does not understand it. Tried padding dark gray area on both sides by the width of the yellow box (and then do the overflow: visible, white-space: nowrap in the green box) - still no go.
Any ideas or pointers? What the hell does the IE understand?
Thanks
Alex, the trick here is pretty simple. Position those two *fixed_size* and *var_size* containers absolutely within #main. Give #main relative positioning. Then given the two absolutely positioned containers negative left and right margins, respectively.
Should certainly work in IE
Good luck and let me know if you need additional help
EDIT: this is the code that is also visible in the Fiddle:
<div id="main">
lorem ipsum
<div id="left">
</div>
<div id="right">
</div>
</div>
and the CSS:
#main {
margin: 0 auto; position: relative; height: 300px; width: 400px; background: gray;
}
#left {
position: absolute; width: 100px; height: 75px; left: -100px; background: red;
}
#right {
position: absolute; width: 100px; height: auto; right: -100px; background: blue;
}
Obviously, use the appropriate ways to center a div in IE with:
body {
text-align: center;
}
#main {
text-align: left; margin: 0 auto;
}
EDIT2: Check out the updated jsFiddle.. Hopefully that is something like what you wanted: http://www.jsfiddle.net/2avM7/3/
You should start with a master container, that is wide enough to visit all 3 containers from left to right, so like this:
<div id="container" style="margin: 0 auto;">
<div id="fixed_size>Content goes here</div>
<div id="main_content" style="margin: 0 auto;">Center content</div>
<div id="variable_size_container">Content for that goes here!<div>
</div>
margin: 0 auto; does the trick here, it centers a div in the center of its parent div.
Related
I working on a project and i have little problem with the div,
the scenario below:-
section.portfolio
.flex.flex--center
.col-1
.img-strip
.col-1.order-first
p.home-lead.outdented Lore ipsum
a(href="#").home-cta See More
http://codepen.io/alb_dev/pen/KaxMVv
I have put in codepen you can see the problem i have:
The pink div i want to put side to the div who have text and the button element
i want to put the file like this on the photo
but when i put the div pink in:-
.img-strip
position: absolute
background:pink
top: 0
margin: -50px 0
width: 100%
height:100%
and the div parent in :-
position:relative
the div in pink disappear you can see on codepen i have post.
Hope i have explained well my problem if not please let me know!
Use position: fixed instead of position:absolute
There are some basic problems with the structure of the code. Since you already have a grid-system in place using the method you are is not recommended. So from what I could understand of your problem, the following is the solution.
HTML old
<div class="col-1">
<div class="img-strip"></div>
</div>
HTML
new
<div class="col-1 img-strip">
CSS old
section.portfolio .img-strip {
position: absolute;
background: pink;
top: 0;
margin: -50px 0;
width: 100%;
height: calc(100% + 100px);
}
CSS new
section.portfolio .img-strip {
background: pink;
width: 320px; /* Depending on what width you want col-1 has a maximum width if 320px */
height: 200px;
}
Problem: When you make a certain div's position fixed (often used as a side bar, or side menu kind of stuff), and if you continue scrolling down, the div overlaps with the footer.
body {
margin: 0;
}
#header {
width: 100%;
height: 290px;
background-color: #07CB6F;
}
#body {
width: 100%;
height: 3450px;
background-color: #2FA3F7;
}
#body_inner {
width: 1280px;
height: 3450px;
margin: 0 auto;
}
#side_menu {
width: 220px;
height: 270px;
position: fixed;
background-color: #ffffff;
}
#footer {
width: 100%;
height: 200px;
background-color: #FF00AB;
}
<div id="header">
</div>
<div id="body">
<div id="body_inner">
<div id="side_menu"></div>
</div>
</div>
<div id="footer">
</div>
I did not use any jquery this time. With the codes given above, since the #side_menu is set as height: 270px, it seems to be okay with the overlapping, however, it still overlaps with the footer if you zoom up the browser (and sometimes depending on the types of browsers and computers).
I would like to know why it happens, and how can it be solved (or prevented).
Thanks in advance :)
Here's a fiddle with the solution
https://jsfiddle.net/stc0ogy2/1/
you need to start using the z-index, it works like the photoshop layers though the z-index will not work without the position so you have to add a position like absolute, relative and so on.
UPDATE
As #AndreiGheorghiu mentioned you should use some javascript for a better solution, choose one of the libraries from the list he gave you.
UPDATE 2
I found this easy-to-use library that I believe will help you with the fixed side menu, it's called tether. Hope it helps.
Your footer is looking to take up 100% of the width space at the bottom and a side bar that wants to take up 220px of the width. On a small screen your menu and footer are fighting for space because its not mathematically possible for one item to take up 100% of space and another item to sit next to it.
You won't notice a problem full screen on most desktops because your menu is too heightwise to be noticeable.
Ideally when declaring your width for the menu and footer you want to use calc() to enable resizing without causing overlap.
https://jsfiddle.net/nu8av25m/ a quick example I put together to demonstrate how it works.
<body>
<div class="navigation">menu</div>
<div class="main">main body</div>
<footer>footer</div>
</body>
.navigation {
Width:50px;
Height:100%;
Background-color: red;
Float:left
}
.main{
Width: calc(100% - 200px);
Height: calc(100% - 100px);
Background-color: blue;
Right:0;
}
Footer{
Width: calc(100% - 100px);
Height: 50px;
Background-color:green;
Bottom: 0
}
I've trying to get a layout where a a fixed-height table with two rows, the first scaling to the its content, and the second being the remaining height, and keeping its contents inside it. The height of the bottom part needs to be 'real' (not clipped by a parent or anything), such that it could have overflow: scroll, or children of height: 100%, etc.
This is what it should look like:
I got it working in Chrome, using an absolutely positioned div inside a relative table-cell:
http://jsfiddle.net/9FPqx/
The core of it:
html:
<div class="row">
<div class="cell">
<div class="absolute-fill">
Stuff
</div>
</div>
</div>
css:
.row
{
display: table-row;
}
.cell
{
display: table-cell;
position: relative;
}
.absolute-fill
{
position: absolute
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
overflow: hidden;
}
With another intermediary relative div between the table-cell and the content (rather than setting relative on the table-cell itself), it works in Firefox:
http://jsfiddle.net/sXHry/
It does not work in IE. I need IE >= 9.
It seems like IE thinks the relative element with absolute child has no content height, and so gives it 0 height.
I feel like I'm so close but so far. Is there a way of solving this with just html and css? Am I on the wrong track using display: table? Or should I give up and just throw some javascript at it?
Why does it need to be a table? Can't you just let the container hide the overflow?
html
<div class="container">
<div class="top">
Top, green area
</div>
<div class="bottom">
Bottom, blue area
</div>
</div>
css
.container {
width: 250px;
height: 162px;
overflow: hidden;
background: lightblue;
}
.top {
background: lightgreen;
}
http://jsfiddle.net/sXHry/1/ and http://jsfiddle.net/sXHry/2/ (less content)
I suspect i might be missing something, looking forward to being enlightened ;)
I want to align a div to the bottom of the PAGE, not to the bottom of the screen. When I do this:
#contact-block{
position: absolute;
bottom: 0; left: 0;
}
, the div is placed in the bottom area of the screen. When my page is long, I have to scroll down and the div which should have been at the bottom, floats somewhere in the middle.
There might be a simple solution to this, but I'm just not seeing it.
Here's my HTML:
<div id="left">
<div id="submenu"> <span class="menutitle">Services</span>
<ul>
</ul>
</div>
<div id="contact-block">
<span class="contacttitle">Contact</span></div>
</div>
<div id="content">
</div>
I've also added a little image to illustrate what I mean:
The red div is the contact div.
Edit:
I've found a solution with jQuery and CSS. This might not be the best solution, but hey, it works.
jQuery:
var offset= $(document).height()-$("#contact-block").height()- $("#footer").height()-60;
$("#contact-block").css("top", offset);
$("#contact-block").css("left", $("#wrapper").position().left);
CSS:
#contact-block {
position : absolute;
width:216px;
height:100px;
background:url(../img/contact-bg.jpg) repeat-x #5c5c5c;
}
You could absolute-position the your divs in place. This technique requires a #wrapper element, which I'm not a fan of, but hey, you gotta do watcha gotta do.
In this example I removed the #left div entirely as it was only required for layout purposed and is no longer necessary.
HTML:
<div id="wrapper">
<div id="submenu">This is services</div>
<div id="contact-block">This is contact</div>
<div id="content">This is content</div>
</div>
CSS:
#wrapper {
position: relative;
width: 960px;
}
#submenu {
position: absolute;
left: 0;
top: 0;
width: 320px;
height: 320px;
}
#contact-block {
position: absolute;
left: 0;
bottom: 0;
width: 320px;
height: 160px;
}
#content {
position: relative;
left: 320px;
right: 0;
top: 0;
width: 640px;
height: 640px;
}
//#content position is relative for the #wrapper to stretch.
//The left property is equal to the width of the #submenu or #contact-block element
A good point of this technique is that it gives you cleaner HTML. I believe it will be easier to make a mobile version of your version if the need arise.
The jsfiddle
Additional thought:
The #wrapper element could easily be removed in favor of you body element, which is a great step towards semantic HTML. Check this out!
The position of your absolute positioned element depends on the first ancestor-element, which is not positioned static ( which is the default, so you have to explicitely set it to relative(or absolute) ).
So, make sure, your enclosing #left container has 100% document-heigth and position:relative, and everything is well.
I would suggest putting the red div inside the right long div and at the end of it. Then use position: relative and negative left margins on the red div to push it out to the left. This way, as your right div expands, your red div always stays at the bottom of it.
I have a div that has a footer image taking up 26px of space. The CSS is set to display a vertical scrollbar when needed, however I need to make sure the scrollbar doesn't overlap into my footer area, so I use bottom:26px; to bring it up. When that happens though the scrollbar is shifted upwards and I can't see the top of the content or the top arrow of the scrollbar. I am not sure what to change for the css to fix it so the scrollbar is at the very top, and leaves a 26px spacing at the bottom for my image. Any help is appreciated.
HTML
<div id="channel-container">
<div id="channel">
</div></div>
CSS
#channel {
color: #FFFFFF;
text-align: left;
width: 100%;
height: 100%;
overflow-x: hidden;
overflow-y: auto;
position: absolute;
bottom: 26px;
}
#channel-container {
float: right;
width: 31%;
height: 100%;
}
Think about restructuring your html. If the div is supposed to scroll, but the footer is not then I wouldn't group them together. Set margin/padding to 0 on footer and same for bottom of scrollablediv. They should seamlessly mash together. Also obviates the need for using position absolute and a bottom value.
Here is a fiddle of what I think you are after. http://jsfiddle.net/vdZ6R/
<div id="container">
<div id="scrollablediv"></div>
<div id="footer"><img src="" /></div>
</div>