catfish.css
#catfish {
position:fixed;
bottom:0;
background:transparent url(images/catfish-tile.gif) repeat-x left bottom;
padding:0;
height: 79px; /* includes transparent part */
cursor: pointer;
margin: 0;
width:100%;
}
html {
padding:0 0 58px 0; /* 58px = height of the opaque part of the Catfish */
}
The contents of ‘DIV#catfish’ are totally up to you. You could conceivably use it for navigation, site announcements, log-in panels or a multitude of things. Space is obviously limited, so keeping things relatively simple is recommended.
After demoing it with some of the guys here, we all agreed the idea had some legs. At this point the major issue became the small matter that it didn’t work at all in Internet Explorer. If you’re viewing the demo in IE you’ll see that the DIV is behaving exactly as if it were ‘position: static‘ (the default). Our big challenge was to make IE play ‘nice-like’ — and that’s what I’ll be concentrating on here.
There has already been plenty of good work on the ‘fixed’ problem from (amongst others) Stu Nicholls, Simon Jessey and Petr ‘Pixy’ Stanicek. Although each differed in the fine print, they generally seemed to agree on some main tenets — position the ‘wannabe fixed DIV’ using ‘position:absolute’ and then wrap everything else in a ‘position:relative’ DIV to keep them apart. Sounded like a good place to start.
We also made another decision at this point. Since FireFox, Opera and Safari do a dandy job with the W3C standard ‘position:fixed’, why throw extra markup at them? — only IE would be getting the extra markup.
In this ‘sandbox’ version, I’m going to attach our IE-specific styles and scripting using ‘conditional comments’, although we actually use ‘object sniffing’ to target IE on the live version. I think conditional comments are great way to go at the moment as they invoke a purpose-built function within IE, rather than relying on fixable and likely transient browser bugs. With IE7 on the horizon, relying on bugs is more dangerous occupation than ever before.
Conditional Comments
<!--[if IE]>
<link rel="stylesheet" href="IEhack.css" type="text/css" />
<![endif]-->
The above markup will allow us to deliver different styles to IE only. Other browsers will read it as a ‘bog standard’ HTML comment, which means that HTML validators will also find it wholesome and satisfying. If IE7 supports ‘position:fixed’, it will be trivial to change the comment to make it only target IE6 and older ( e.g. ‘<!--[if lt IE 7]> ...
‘ if less than IE7).
So, what extra CSS should we send IE ?
Not a great deal. We need to switch Catfish’s positioning to ‘absolute
‘, set it’s z-index to ‘100
‘ to keep it at the front, and set it’s overflow to ‘hidden
‘.
IEhack.css
#catfish {
position: absolute;
z-index: 100;
overflow: hidden;
}
Now we have our Catfish positioned correctly — that is, until we try to scroll, at which point it trundles off up the page. The problem is the browser calculates ‘bottom:0
‘ as the exact point where the bottom of the viewport overlaps the BODY — when the BODY scrolls, that point moves with it.
So, in theory, we can fix this problem by taking the rather drastic-sounding action of forcibly preventing our BODY
from scrolling under any circumstances. Using ‘overflow:hidden
‘ and ‘height:100%'
we can force the viewport, the HTML
element and the BODY
element to aquire exactly the same dimensions. No scrolling means the Catfish stays put.
IEhack.css
html, body {
height:100%;
overflow: hidden;
width:auto;
}
Of course, this minor victory has been regretably soured by the fact that we now have no way of accessing any content outside our viewport. It’s now that we call on that wrapper DIV mentioned in other methods. I’ve called it ‘#zip
‘ as we’re ‘zipping up’ all the non-catfish content up into it. In the markup it looks something like this.
catfish-ie.php
<body>
<div id="zip">
<div id="masthead...
...</div>...<!-- close zip -->
<div id="catfish">...
...</div><!-- close catfish-->
</body>
This new ‘div#zip
‘ is now bulging with most of the content on the page, so if we set it’s overflow to ‘auto
‘, it will only too happy to give us some nice new scrollbars. These scrollbars will be almost indistinguishable from BODY
‘s own default scrollbars. The CSS for this DIV is pretty unremarkable.
IEhack.css
div#zip {
width: 100%;
padding:0;
margin:0;
height: 100%;
overflow: auto;
position: relative;
}
Ok, so now IE is playing nice and giving a fine imitation of a browser who knows what fixed positioning is,… just as long as we give it that extra DIV to work with.
But, as I said above, why burden better browsers with stuff they don’t use? It’s a DIV that is more likely to hinder than help them, so let’s inject it only into IE using the DOM.
We’re going to add a new function called ‘wrapFish
‘. The script goes a little like this.
catfish.js
function wrapFish() {
var catfish = document.getElementById('catfish');
// pick the catfish out of the tree
var subelements = [];
for (var i = 0; i < document.body.childNodes.length; i++) {
subelements[i] = document.body.childNodes[i];
}
// write everything else to an array
var zip = document.createElement('div');
// Create the outer-most div (zip)
zip.id = 'zip';
// give it an ID of 'zip'
for (var i = 0; i < subelements.length; i++) {
zip.appendChild(subelements[i]);
// pop everything else inside the new DIV
}
document.body.appendChild(zip);
// add the major div back to the doc
document.body.appendChild(catfish);
// add the Catfish after the div#zip
}
window.onload = wrapFish;
// run that function!
The comments give you the blow-by-blow on what it’s doing, but, in short, it:
- takes the catfish out of the document,
- creates the new
DIV#zip
, - copies everything else into the new DIV,
- attaches that DIV to the document, and
- tacks the catfish back on the end
Conditional Comments
<!--[if IE]>
<link rel="stylesheet" href="IEhack.css" type="text/css" />
<script type="text/javascript" src="catfish.js">
<![endif]-->
So, there you have it. I’ve left a red dashed border on ‘div#zip
‘ to demonstrate that only IE is rendering that extra DIV. We’ve patched IE without messing with anyone else.
So, is that all you have to know to get a Catfish-like system running ?
Not quite. It’s more than likely you only want to run the Catfish on certain pages, at certain times, so we need an intelligent system that knows if and when to inject the Catfish via the DOM. It would also be nice to be able to select from a library of different banners.
Tom will take tackle these and other exciting problems in Part II — coming soon.
Frequently Asked Questions (FAQs) about Catfish Ads
What are Catfish Ads?
Catfish Ads are a type of online advertising format that appears at the bottom of a webpage. They are named ‘Catfish’ because they ‘swim’ at the bottom of the screen, much like a catfish does in water. These ads are typically interactive and can be a great way to engage users on a website. They can include various types of content, such as images, videos, and text.
How do Catfish Ads work?
Catfish Ads work by appearing at the bottom of a user’s screen as they browse a website. They remain visible even as the user scrolls down the page, ensuring constant visibility. This persistent visibility increases the chances of user engagement, making them a popular choice for advertisers looking to increase brand awareness and engagement.
What are the benefits of using Catfish Ads?
Catfish Ads offer several benefits. Firstly, their constant visibility ensures that your ad is always in view, increasing the chances of user engagement. Secondly, they can be highly interactive, allowing for a more engaging user experience. Lastly, they can be customized to match the look and feel of your website, ensuring a seamless user experience.
How can I create effective Catfish Ads?
Creating effective Catfish Ads involves a combination of compelling visuals, engaging content, and a clear call-to-action. The ad should be visually appealing to catch the user’s attention, and the content should be engaging enough to hold their interest. A clear call-to-action is also crucial to guide the user on what to do next.
Can I use Catfish Ads on mobile devices?
Yes, Catfish Ads can be used on mobile devices. They are designed to be responsive, meaning they will adjust to fit the screen size of the device they are being viewed on. This ensures a seamless user experience, regardless of the device used.
Are Catfish Ads intrusive?
While Catfish Ads are constantly visible, they are designed to be non-intrusive. They typically appear at the bottom of the screen and do not interfere with the user’s browsing experience. However, it’s important to ensure that your ads are not overly aggressive or annoying, as this can lead to a negative user experience.
How can I measure the success of my Catfish Ads?
The success of Catfish Ads can be measured using various metrics, such as click-through rates, conversion rates, and engagement rates. These metrics can provide valuable insights into how your ads are performing and can help guide future advertising strategies.
What industries can benefit from Catfish Ads?
Almost any industry can benefit from using Catfish Ads. They are particularly effective for industries that rely heavily on visual content, such as fashion, travel, and food. However, they can be adapted to suit any industry, making them a versatile advertising option.
Can I customize my Catfish Ads?
Yes, Catfish Ads can be fully customized to match your brand’s look and feel. This includes the color scheme, fonts, images, and overall design. This ensures a seamless user experience and can help increase brand recognition.
Are Catfish Ads expensive?
The cost of Catfish Ads can vary depending on several factors, such as the complexity of the ad, the platform used, and the duration of the ad campaign. However, they are generally considered to be a cost-effective advertising option due to their high visibility and engagement potential.
Alex has been doing cruel and unusual things to CSS since 2001. He is the lead front-end design and dev for SitePoint and one-time SitePoint's Design and UX editor with over 150+ newsletter written. Co-author of The Principles of Beautiful Web Design. Now Alex is involved in the planning, development, production, and marketing of a huge range of printed and online products and references. He has designed over 60+ of SitePoint's book covers.