IE7 container of floated elements not expanding, clear and zoom not working - internet-explorer-7

Edited; see bottom of post
I have a layout that works perfectly in everything except Internet Explorer 7.
I have a container div that has a width and hasLayout (I've tried zoom and various other things that ought to set this, but nothing changes). Inside are three floated elements, one left and two right. Below them is an element that is clear: both and it actually is doing that, but the container is ending at the shorter float even when I set a height for it including a height taller than the originally/naturally taller one.
Here's what it looks like: http://tinypic.com/r/ea3vpy/8
It should look exactly like that, except with the two elements that are awkwardly not in the layout inside the content area.
I've tried adding empty divs with clear: both, I've tried clearfixes, I've tried floating the container. I even added a container around the two right floating divs and floated that instead of them, but it didn't change anything. Overflow is not really an option because then I have to either cut off the content or have scroll bars inside the layout.
Here's the relevant CSS:
#content {
width: 669px;
height: 100%;
padding: 20px;
padding-top: 0;
position: relative;
display: table-cell;
vertical-align: top;
background-color: #F7F8F7;
text-align: left;
}
#content { /* To make it play nice with the sidebar */
_width: 709px;
*display: inline;
*position: absolute;
*left: 0;
*zoom: 1;
}
p#indexwelcome {
max-width: 330px;
min-height: 440px;
float: left;
}
#dogimg {
width: 323px;
max-width: 100%;
height: 246px;
margin-left: 10px;
float: right;
}
#loginbox {
max-width: 323px;
margin: 20px 0;
padding: 10px;
position: relative;
float: right;
}
#itemsbox { /* the one with the bananas */
width: 644px;
height: 142px;
margin-top: 20px;
position: relative;
clear: both;
}
And the HTML:
<div id="content">
<h1>Heading</h1>
<p id="indexwelcome">Text paragraphs here</p>
<img src="images/dog.jpg" id="dogimg" alt="dog" />
<div id="loginbox">
<p>Login box stuff</p>
</div> <!-- loginbox div -->
<div id="itemsbox">
<!-- banana images here -->
</div> <!-- itemsbox div -->
</div> <!-- content div -->
EDIT: So I fixed the issue although it's not quite ideal. Setting the content and sidebar to height: auto (as opposed to height: 100%) made them expand for their content.
However that page container (the green space) still won't expand even with height: auto. I have to set a specific min-height or height, which isn't great because the page content is dynamic, so other pages have extra space if their content is shorter than what it's set for and it'll be the same original problem if the content is larger. And then of course the content and sidebar boxes still aren't the same length (but that's a whole other issue).
Here's the page CSS:
#page {
width: 1025px;
height: 100%;
min-height: 650px;
margin: 15px auto;
padding: 10px 0;
position: relative;
background-color: #7B9F73;
*min-height: 990px;
}

Related

White-space: nowrap did not work well, what did i do wrong?

I make a responsive web page where at max width of 768px (via media query) the div inside the main container suppose to change to inline-block so that the page would scroll horizontally to the div's id when user click on link. The page is set up with overflow: hidden, so it navigate using id/anchor alone.
The problem is, when I did a preview in mobile, the container just spread out and I can totally swipe the page. Even the menu button that suppose to be in the center of the view port went to the center of the container. And leaving a huge white space below it. It did good however in desktop browser. So I presume it has everything to do with the nowrap function.
It worked in Firefox both mobile and desktop. It worked in I.E desktop. It did not worked in Chrome mobile but seems to be working in desktop. And failed in Safari mobile, haven't tested yet in desktop.
I tried to remove white-space: nowrap function only to find out the div did not stacks inline-block like it suppose to. I tried specified container's width and min-width with no luck. I tried float: left, position values and a bunch of things i don't recall them all. Nothing's change.
HTML
<div id="container">
<div id="company" class="company">
<iframe src="main.html">
</iframe>
</div>
<div id="content" class="content">
<iframe src="content.html">
</iframe>
</div>
<div id="system" class="system">
<iframe src="system.html">
</iframe>
</div>
</div>
css
body{
overflow: hidden;
}
#container {
height: 100vh !important;
min-height: 100vh !important;
}
#container .company, #container .content, #container .system {
display: block;
height: 100vh !important;
min-height: 100vh !important;
}
#media screen and (max-width:768px) {
#container {
display: block;
white-space: nowrap;
}
#container .company, #container .content, #container .system {
display: inline-block;
}
}
iframe {
width: 100vw !important;
min-width: 100vw !important;
height: 100vh !important;
min-height: 100vh !important;
border: none;
}
What I expected (Chrome desktop)
https://kamalmasrun.files.wordpress.com/2019/01/desktop.jpg
But only comes to this in mobile
https://kamalmasrun.files.wordpress.com/2019/01/screenshot_20190122-120510.png
Your help is much appreciated and I first address a thank you to all for the help =).
Basically, you have a few problems here:
Setting overflow: hidden won't prevent browser on mobile from scrolling (on Firefox it might, but on Chrome or iOS Safari it will not). Blocking scrolling is a hard thing to do on mobile to be honest, and it always is a little bit hacky, so I would not go that way.
To achieve scrolling (or jumping) using links with #content etc, body has to be expanded and browser has to see where this element is. Expanding body will result in ability for user to scroll left/right, which is hard to block as I mentioned before. You have to scroll #container to show new element. You can do this using javascript.
Also, don't forget to add overflow: hidden to #container (this will work on mobile).
If something is still unclear, feel free to ask in comments below this answer :)
The idea of algorithm to achieve your goal:
Listen to hashchange event
Read current hash from window.location
Find element with given hash using document.querySelector
Read element's position inside container
Set scrollLeft property of container to be equal element's position
Some useful links to get you started:
https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onhashchange
https://developer.mozilla.org/en-US/docs/Web/API/Window/location
https://developer.mozilla.org/pl/docs/Web/API/Document/querySelector
https://developer.mozilla.org/pl/docs/Web/API/Element/getBoundingClientRect
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft
And updated CSS:
body {
overflow: hidden;
margin: 0;
}
#button {
position: fixed;
vertical-align: center;
}
#button .btn1,
.btn2,
.btn3 {
padding: 10px;
display: inline-block;
}
#container .company,
.content,
.system {
display: block;
height: 100vh;
min-height: 100vh;
width: 100vw;
}
#media screen and (max-width:768px) {
#container {
display: flex;
flex-flow: row nowrap;
}
#container .company,
.content,
.system {
display: block;
}
}
iframe {
border: none;
height: 100vh;
min-height: 100vh;
width: 100vw;
}
It's possible that setting min/max width to #container will do the trick.
#container {
min-width: 100vw;
max-width: 100vw;
}
Also, I'd suggest using flex here, as it would suit well and is more modern.

Scaling all content in a div as if one element

I have two images placed on top of each other in a div with a caption underneath. I would like all of these elements to scale proportionally and together as the browser window shrinks.
Currently, the position of the two images shifts and does not look the same on mobile.
.highlightimg {
max-width: 700px;
height: auto;
width: 100%;
display: block;
position: relative;
z-index: 1;
padding-top: 10vh;
margin-right: 0;
}
.showcase {
max-width: 750px;
margin:auto;
position: relative;
margin-top: 8vh;
margin-bottom: 8vh;
}
.logo {
left:0;
max-width: 400px;
width: 100%;
height: auto;
position: absolute;
z-index: 3;
left: 0px;
}
.caption {
margin-top: 10px;
margin-bottom: 0;
padding: 0;
text-align: right;
}
<div class="showcase">
<img src="logo.png" class="logo">
<img src="highlight.jpg" class="highlightimg">
<p class="caption">Caption text here.</p>
</div>
The best analogy for the product I'm trying to receive is grouping multiple layers in Photoshop which allows you to scale all the layers together as if it was one single image. I am new to HTML/CSS, so I hope this makes sense and is not asked too often. Thanks for your help.
The position of the logo relative to the image under it will definitely shift. One of the reason for this is that you use vh unit for some properties, including the padding-top of the .highlightimg. 10vh in desktop and in mobile is different (they both have different viewport sizes). If you want both elements to stay the same, anchor both of them to the left and top by setting at least constant padding-top, margin-top, or the top properties (including the left padding and margin).
Maybe adding top: 18vh; to .logo could help. Using top: 10vh; instead of 18vh while also removing margin-top: 8vh from .showcase could also help. This is to ensure the top offset of the .highlightimg provided by its padding-top property scales proportionally with the top offset of the .logo. These solutions assume that there are no other elements in the page that will surely alter the location of these elements especially the ones without absolute position.
position: absolute; anchors your element to the screen. While position: relative; keep the element original rendered position and move the element itself relative to its original rendered position. Both have radically different impacts on where your elements get rendered on the screen. If you want both element to be exactly at the same location, use absolute for both and use same top and left properties.
Point is, don't rely on CSS properties to determine the exact location of your objects. If you want behavior like the one you describe in your Photoshop analogy you could find a way by using canvas.

Re-order containers using media queries

I'm wanting to re-order a number of containers when the webpage is being viewed on a particular device.
I currently have three divs floated left. Two smaller divs either side of a larger div. However, when the media query kicks in a would like the middle of the three to sit above the other two. In theory changing its position from 2nd to 1st.
Is this possible with pure CSS? Or would I need to get jQuery involved? I've set up a test fiddle here for anybody who can help with my initial attempts, but I'm having no joy so far... http://jsfiddle.net/r8qZ2/
Example HTML:
<div class="panels">
<div class="panel-one">Panel 1</div>
<div class="panel-two">Panel 2</div>
<div class="panel-three">Panel 3 </div>
</div>
Example CSS:
.panels {
width: 100%;
max-width: 1280px;
margin: 0 auto;
}
.panel-one, .panel-three {
width: 24.0625%;
height: 400px;
float: left;
background: red;
}
.panel-three {
margin: 0 0 0 1.25%;
}
.panel-two {
width: 49.375%;
height: 400px;
float: left;
margin: 0 0 0 1.25%;
background: blue;
}
#media only screen and (max-width: 800px) {
.panel-one, .panel-three {
width: 49%;
height: 400px;
}
.panel-three {
margin: 0 0 0 2%;
}
.panel-two {
width: 100%;
float: none;
clear: left;
margin: 0;
}
}
Any help would be gratefully received!
Re-order responsive containers with CSS? With float based layouts, no. In cases with just one floated sidebar it's possible, but not with two.
If you adjust your layout not to use floats then it's most certainly possible.
Note: I highly recommend a mobile first-approach to your CSS, using min-width media queries. However since you're using max-width in your example I will also do so in mine:
Using position: absolute:
Place the element you want to be at the top as the first element in your HTML markup, and position the sidebars to the sides with position: absolute. Give the parent element position: relative, and give it a padding value equal to the width of the sidebars.
Then, with media queries, remove the padding and position: absolute you set.
Example:
HTML:
<div class="panels">
<div class="panel-two">Panel 2</div>
<div class="panel-one">Panel 1</div>
<div class="panel-three">Panel 3</div>
</div>
CSS:
.panels {
position: relative;
padding: 0 25%;
}
.panel-one,
.panel-three {
position: absolute;
top: 0;
bottom: 0;
width: 25%;
}
.panel-one { left: 0; }
.panel-three { right: 0; }
#media only screen and (max-width: 800px) {
.panels {
padding: 0;
}
.panel-one,
.panel-three {
position: static;
width: auto;
}
}
Here's a pen with your markup adjusted to this.
A major drawback to this is that the sidebars are taken out of the content flow with position: absolute, so depending on your layout this may not be a possible solution.

bootstrap 3.0 full length body sidebar

I'm trying to get bootstrap divs to be full body length.
This is what I've tried so far: http://jsfiddle.net/bKsad/315/
html, body {
min-height: 100%
}
.wrap {
height: 100%
}
.sidebar {
background-color:#eee;
background-repeat: repeat;
padding:0;
min-height:100% !important;
position:relative;
}
.sidebar .sidebar-content {
height:100%;
width:100%;
padding: 5px;
margin:0;
position:relative;
}
As the right column grows longer, I want the sidebar to do the same.
The key is to understand the "col-md-x" and "col-md-offset-x" styles provided by Bootstrap 3:
<div class="container-fluid">
<div class="row">
<div class="col-md-3 sidebar">
Sidebar Content
</div>
<div class="col-md-9 col-md-offset-3 content">
Main Content
</div>
</div>
</div>
Then use CSS to make sure the breakpoints line-up. You'll need to fine-tune padding/margin for your particular needs, but the offset and #media breakpoints handle the overall layout pretty well:
html, body, .container-fluid, .row {
height: 100%;
}
.sidebar {
background-color: #CCCCCC;
}
#media (min-width: 992px) {
.sidebar {
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 1000;
display: block;
background-color: #CCCCCC;
}
}
Working solution: http://www.bootply.com/111837
If you use "col-sm-x" or "col-lg-x" you just change the #media CSS to the corresponding min-width (768px for sm and 1200px for lg). Bootstrap handles the rest.
I solved this by using an absolutely positioned div and a bit of jQuery. I have a Bootstrap navbar with a fixed height of 50px, so that is why you're seeing the 50's in the code. You can remove this if you don't have a top navbar.
This solution works dynamically with any height.
The CSS:
.sidebar {
background-color: #333333;
position: absolute;
min-height: calc(100% - 50px);
}
The jQuery:
var document_height = $(document).height();
var sidebar = $('.sidebar');
var sidebar_height = sidebar.height();
if (document_height > sidebar_height) {
sidebar.css('height', document_height - 50);
}
The neat thing about this is there will be no flickering of the background because its using CSS to adjust the min-height, so that the jQuery resizing that normally causes a flickering of the background will be hidden on page load.
approach 1: added empty div with style="clear:both" at the end of wrap div.
http://jsfiddle.net/34Fc5/1/
approch 2: http://jsfiddle.net/34Fc5/ :
html, body {
height: 100%;
}
.wrap {
height: 100%;
overflow: hidden;
}
.sidebar {
background-color:#eee;
background-repeat: repeat;
padding:0;
height:100% !important;
position:relative;
}
.sidebar .sidebar-content {
height:100%;
width:100%;
padding: 5px;
margin:0;
position:relative;
}
added "overflow: hidden;" to .wrap
changed height: 100% to html, body
changed height: 100% to .sidebar
using css way, the height of the sidebar will only match the view port of the browser. so if you look at approach 1, when you scroll you will notice the background stop at viewport. to fix it js is required.
The only thing that got it working for me (after many hours of trying everything) was
HTML
<nav class="col-sm-3 sidebar">
CSS
padding-bottom: 100%;
The padding in percent did it for me. Now it goes all the way to the bottom of the page.

Height calculation differences between IE7 and Firefox/Safari

this is driving me crazy...might be something very simple and I just need another set of eyes to look at it...
I have this in my CSS:
#recipient {
width: 31%;
text-align: center;
min-height: 335px;
float: right;
background-color: #fff;
color: #000;
border: 2px solid black;
margin: 20px 0 0 0;
padding: 11px 0;
font-size: 0.875em;
}
and call it here in my HTML:
<div id="recipient">
<h3>Meet the 2010 Recipient!</h3>
<img src="images/2010_headshot.jpg" alt="foo" />
</div>
Pretty simple, right? In Firefox it renders about 20px longer in height than IE7 (I can tell by where the bottom of this div hits next to other elements on the page). I am running in standards mode, and have looked at the Firefox version in Firebug and the IE version with Firebug Light and the IE Dev Toolbar -- don't see anything weird in either... the top of the div starts in the right spot, so it doesn't look like the margin collapsing...
If I manually add padding/height to the CSS, I can get IE7 to line it up at the right height, but then the div in Firefox is too long! It's not a critical part of the design, but it's bugging the sh!t out of me!!
Thanks in advance...
It's IE and the different way it's handling the default h3 margins inside a floated element
usually this can be fixed by giving the offending element (any element which has default margins!) explicit margins, but in this case it's not working because of the top padding of the container ?
The best fix I can come up with is to remove the top padding from the #recipient div and explicit;y make the top/bottom margins on the h3 11px, this makes for nice even spaces through the effect (btw this extra bit only happens if the div is taller than the min height) - here's some working code - I also put a background color on the h3 which if you do in your code will show the 15px or so extra gap..
CSS:
#recipient {
width: 31%;
text-align: center;
min-height: 335px;
float: right;
background-color: #fff;
color: #000;
border: 2px solid black;
margin: 20px 0 0 0;
margin: 0;
font-size: 0.875em;
padding-bottom: 11px; /* bottom padding only */
}
h3 {
margin: 11px 0; /* explicitly set these */
background: #fcf;
}
HTML: (with placeholder image for testing)
<div id="recipient">
<h3>Meet the 2010 Recipient!</h3>
<img src="http://placekitten.com/350/200/" alt="foo" />
</div>

Resources