Fixing a column width in Zurb Foundation 3? - css

I have a layout where one of my columns holds an ad. See image 1:
The ad image is in a four-column div. The ad is an MREC which is 300px wide. However, on the iPad, since the columns reduce, the ad goes down to 236px which is a no-no. See image 2 below, of course it looks the same here but it is smaller:
I need it to stay at 300px. Also, sometimes the ad server may serve an iframe-based ad (also 300px).
So that div needs to not shrink width.
I tried adding a class to that did and setting css to min-width:300px, but then on the iPad it sticks out the right edge; the other div does not shrink accordingly enough. See image 3:
So, how do I ensure the divs with my ads are not re-sized on the iPad?
EDIT: Also, the problem seems compounded when I reverse the column order with push-pull. I am doing this since I need the ad to come first on the phone but second on other platforms:
<div class="row">
<div class="four columns ad push-eight">
<img src="http://placehold.it/300x300">
</div>
<div class="eight columns pull-four">
<h1>Bacon ipsum dolor sit amet tri-tip shankle chicken leberkas beef pork</h1>
</div>

In order to get this to work, I had to step outside of Foundation a bit. Here's what you'll need.
Example: http://cdpn.io/Kypen
Explained:
I created an ad wrapper .ad and a .container element.
The .ad is 300px wide and floated to the right; while the .container element is given a 320px wide margin. Since Foundation is using border-box sizing the margin is factored in to the width of the overall .container element. As a result, the .ad sits inside the "false margin" (the 20 extra px is for white space). This is an old trick and it works inside Foundation's .row & .column elements just fine, in addition it doesn't affect nested rows from being created either.
I also added a media query, use can use this to change the behavior at low resolution.
.ad
{
float:right;
width:300px;
}
.container
{
position:relative;
margin-right:320px;
}
#media only screen and (max-width: 767px)
{
.ad
{float:none;}
.container
{margin:0;}
}

When I needed to fix the width of my sidebar I ended up doing it with calc(). I wanted to have my sidebar below the main content on smaller devices and this way it was really easy.
My layout in haml
.row
.content.column.large-9
= yield
.sidebar.column.large-3
= render 'sidebar'
Styles
.sidebar{
width: 100%;
}
.content {
width: 100%;
}
#media #{$small} {
.sidebar {
width: 225px !important;
}
.content {
width: 70.2% !important; /* Fallback for older browsers */
width: calc(100% - 240px) !important;
}
}
The media query parameter $small is really confusing as it actually means "larger than small".

Related

css #media not re-rendering after going back to the original windows size

I have a normal, general CSS for a website.
After creating some #media queries to make my elements have different colors, sizes and etc on mobile and different resolutions, everything is fine.
The problem is when I resize the windows from a normal size to a small one, the effects are applied, but when I resize back to the normal one, the css is not refreshed, some "mobile" rules stay there.
How can I re-render the css without the #media rules, not refreshing the page.
This is an example of my HTML:
<div class="item">
<span class="item-foo">FOO </span>
<span class="item-bar">BAR </span>
</div>
With the following css:
.item-bar{
float: right;
}
#media only screen and (max-width: 992px){
.item-foo, .item-bar{
display: block;
float: none !important;
}
}
Here is a codepen of it:
Codepen
If you resize the view area to a small size until they turn in one span each line and go back to a bigger size, the "bar" element won't be in the right place.
As #JesseKernaghan pointed out in the comments, this is a chrome bug.
The easy-fix would be increasing the specificity for the button fixes this, as suggested by #SeanKeating.
In this question's case, adding this style fixed the problem:
.item .item-bar{
float: right;
display: inline;
}
Here is the codepen updated with the easy-fix
http://codepen.io/matheusbaumgart/pen/yyzXpp

display: inline-block with alternate flows at low media width

inline-block is the awesomest CSS tag ever. (That mean I only learned how it works last night. But then I threw away dozens of lines of HTML in preference to it.) It lets blocks reflow!
How do we write a banner that collapses into a different order when the screen is too small?
Big screen
[ A ][ B ][ C ]
Small screen?
[ C ]
[ B ]
[ A ]
You'll need some HTML and CSS trickery for the order switching, and then you could simply use media queries, with e.g.:
Demo Fiddle
HTML
<div>D</div>
<div>C</div>
<div>B</div>
<div>A</div>
CSS
div{
display:inline-block;
width:50px;
box-sizing:border-box;
height:50px;
width:25%;
border:1px solid black;
float:right;
}
#media (max-width: 700px) {
div {
display:block;
width:100%;
}
}
By having the elements in reverse order, then using float:right in your CSS, it places them in the order you anticipate- which is then ignored when they are given 100% width on screen resize- so they appear in the DOM (reverse) order.
Tx to whoever first mentioned 'flex'. I still like my previous float: solution, and SW4's will also work - IF you can find a way to float the divs together. But it's flex that allows you to re-order things.
Furtherless, #media & similar systems (such as 50%), reference the current page size (probably A4), not the current window size. I want to be so responsive that we behave like the mobile app, even if we're just a generic browser that someone scrunched up. So we need JS - the arch-nemesis of CSS - to trigger the changes.
The trick is display: flex; enables order:N;. That means switching the container to display: inline-block; will turn on document-order:
<script>
function resizeMe(win) {
var size = $(window).width();
var display = size > 600 ? 'inline-flex' : 'inline-block';
$('#flexMe').css({ display: display });
}
$(window).bind('resize', resizeMe);
$(window).bind('load', resizeMe);
</script>
<div id="flexMe" style="display: flex; width: 100%;" >
<div id="hdrLogo" class="hdrLogo hdrNv" style="order: 3; width: 375px;" >
Logo goes here
</div>
<div id="hdrAuth" class="hdrNv" style="order: 2; width: 375px;">
Login stuff goes here
</div>
<div id="hdrNavBar" class="hdrNv" style="order: 1; width: 375px;">
Record navigator goes here
</div>
</div>
That way the Record Navigator is either upper left, or closest to the records, and the Logo is either upper right, or farthest from the records.

two divs with display:inline-block - second div with iframe ad being pushed down a few pixels

Background: working on a responsive redesign. normalize.css used for reset.
DFP Ads inserted into div's using this technique. The ad container div's are hidden depending on window size and the ad iframe's are only inserted once into the non-hidden div. I also have a site logo div, .brand, that is hidden or not depending on width. Both the ad div container, .ta, and the logo container, .brand, are contained within a div called .secondnav. All three divs are 90 px tall. .brand, #ldr and .ta are all display:inline-block.
When .brand is display:none, the iframe ad in #ldr div contained by .ta sits perfectly within the height of 90px.
When the window is a bit bigger and .brand becomes display:inline-block, .ta suddenly gets pushed down about 4-5 pixels. They're still side by side but suddenly the ad is a few pixels lower.
I can't see what could be pushing it down. I thought it could be how the div is interacting with the ad's iframe, but why is it only happening when it's next to another inline-block div?
Here's the CSS:
.brand {
width:200px;height:90px;
background:#660000 url('/dh5.svg') no-repeat left top;
display:inline-block
}
.multiplebgs .brand {
width:200px;height:90px;
background-color:#fff;
background-image:url(/dh5.svg),url(/dhw.svg);
background-position:0 0,30px 0;
background-size:30px,170px;
background-repeat:repeat-y,repeat-y;
display:inline-block
}
.ta {
height:90px;
display:inline-block
}
.secondnav {
height:90px;
background:url('/fs.jpg') 0 0 repeat
}
#ldr {
background:blue;
width:728px;height:90px;
display:inline-block
}
#mldr {
background:yellow;
width:320px;height:50px;
display:inline-block
}
#smallban {
background:green;
width:468px;height:60px;
display:inline-block
}
Here's the html:
<div class="secondnav">
<div class="brand"></div>
<div class="ta">
<div id="ldr" class=
"adslot hidden-phone hidden-tablet visible-desktop" data-dfp=
"728x90"></div>
<div id="mldr" class=
"adslot hidden-desktop hidden-tablet visible-phone" data-dfp=
"320x50"></div>
<div id="smallban" class=
"adslot visible-tablet hidden-phone hidden-desktop" data-dfp=
"Smallbanner"></div>
</div>
</div>
Wasn't sure if I could include an URL to my test page so you could see this in action. Will edit it and include one if it's kosher. Will Google more on iframe alignment but thought I'd ask here. Thanks.
My test is here: http://www.digitalhit.com/bptest/index.shtml The issue appears at any size where there is an ad next to the .brand. e.g. at 480px, 600px, 1024px or higher. Please ignore the garish colours, just there for seeing the divs clearly as I test the design.
Try this in the iFrame:
style="border: 0px; top:0px;"
Despite Sergio's great suggestions, I couldn't get it to work for me, probably as I had no control over the HTML in the iframe ad from Google. Going back to floating the .brand div to the left and centering a width-defined div containing .brand and the ad divs worked for me and everything was vertically aligned.

How to implement fluid design to fit 1024x768 size monitor or higher?

Simply, I want the body of the site to occupy 100% of the browser in 1024x768 monitors, and for monitors with higher resolution (1024x768 and higher) to display the body in the middle (center aligned) leaving equal amounts of space on the left and right.
This is very common in many websites but I don't know how to implement it. Can anybody show me how, please, and finish up the CSS code I started? Thank you very much.
HTML
<div class="header">content</div>
<div class="side-bar">content</div>
<div class="container">content</div>
CSS
html body{
margin:0;
background:#fff;
}
.container{float:left}
.side-bar{float:left}
"Today, most visitors are using a screen resolution higher than 1024x768 pixels" - http://www.w3schools.com/browsers/browsers_display.asp
so if you need to have a 1024 pixels width website you just make your container to be 1024 pixels fat :) and margin:auto;
http://jsfiddle.net/kx2nE/3/
I used a smaller size one so you can see better the result in jsfiddle, but you can replace those values in your css.
#container
{
width:300px !important;
height:500px !important;
border:1px solid red;
margin:auto;
}
<div id="container">
container with equal margins on window resize<br />
<br /><br /><br />
<b>
width and height values set to yours 1024x768
</b>
</div>
Check out the Fluid 960 Grid System - http://www.designinfluences.com/fluid960gs/
It lets you nicely organize content divs in a horizontal grid that takes up 100% of the browser's width.
Typically this type of question is not encouraged on stack overflow due to the fact that you didnt actually present a problem. However there is a very good css coder who has solved this for you. Here is a link the download for you to try.
http://matthewjamestaylor.com/blog/ultimate-1-column-full-page-pixels.htm
Set width to a percentage and min-width for fixed size on 1024 monitors:
#main {
width: 95%;
min-width: 990px; /* I suggest a number around 990, due to scroll bar width, experiment at will or use javascript to apply dynamically */
To align the site centered, use an automatic horizontal margin:
margin: 0 auto;
}
Note: You need to apply these to a div directly beneath the body (The body itself cannot change size)
<body>
<div id=main>
<div class="header">content</div>
<div class="side-bar">content</div>
<div class="container">content</div>
</div>
</body>
Edit: Ah I see what you mean, fluid with maximum width, most of the aforementioned stands, change 95% to 100% and min to max:
#main {
width: 100%;
max-width: 990px;
margin: 0 auto;
}

How Do I Make a "Trickless", Cross-Platform CSS-Based Same Column Height?

I tried this with DIVs. The problem occurs in both. I can't get the right border to be equal heights as the longest DIV. And I need this to work across the current desktop browsers from the days of IE7 and up.
This is a common problem, but it's 2011 now when I write this. Is there finally a way to do this with pure cross-platform CSS without resorting to funky tricks like pretending to make it work (such as a column cutoff)? Or, must I resort to jQuery to make it work in the least amount of fuss?
EDIT: My bad. When I wrote this originally, I included TABLE TDs having the problem as well as DIVs. But I didn't realize that I had taken my test code and switched from DIV to TD, but my CSS still said float:left;clear:right. When I eliminated that with the TDs, the border extended to full height of the longest column. However, still, it would be good to find out how to do this with DIVs, but cross-platform from desktop browsers starting with the year IE7 came out and upwards.
A quick way to get the effect is having a background image with a segment of your border on your container div that repeats down the page. This will make the border extend as far as the parent container which should be the tallest column.
Hope this helps.
This approach is relatively "trickless" -- and it's the only approach I've found that works correctly, and doesn't involve any big-time hacks. (also, no tables - only divs and css).
You can see the following example in action: here (jsFiddle)
HTML:
<div class="colwrap">
<div class="col1 content">
<div class="col1 bg"></div>
unde omnis iste natus error
sit voluptatem accusantium
doloremque laudantium
</div>
<div class="col2 content">
<div class="col2 bg"></div>
abcdefg hijklmnop
</div>
</div>
CSS:
.colwrap {
position: relative;
overflow: hidden;
}
.colwrap .content {
float:left;
overflow: hidden;
}
.colwrap .bg {
position: absolute;
height: 100%;
z-index: -1;
}
.colwrap .col1 { width: 50px; }
.colwrap .col1.bg { background: blue; }
.colwrap .col2 { width: 50px; }
.colwrap .col2.bg { background: red; }
Notes
The only trick here, is that you have to split your background (or border) -- whatever visual element you want to fill the column with--into a separate div from the content.
Your columns must be fixed-width. percentage widths usually won't work out very well.
The content divs float within the wrapper, which is set to overflow:hidden. This way the content divs "push out" the wrapper to the full height of the largest content.
Then the background divs are position:absolute; height:100%;. They automatically inherit the position (top,left) of their floating parents, but the height is computed based on the next positioned parent (not the floating content div, but the wrapper, with position:relative;). So the background divs end up right where we want.
The bg divs also use z-index:-1; to force them behind the content. This works in webkit, and FF, but may not work correctly in IE (esp. older versions). If it doesn't work, the problem is likely the negative number. To fix it all you have to do, is add an additional wrapper around the text within the content div, then set z-index on bg and on your content wrapper, so that things stack the way you want. (of course, you should test it -- because it may not be a problem at all).
Finally, I'll note that this same approach will work for as many columns as you want -- just add more (.col3, .col4, and so on.), just like col1 and col2 shown above.
Could you provide a URL for your page? BG images would work if your markup was a certain way. I'd love to take a look at your page to see what you're trying to do.

Resources