The Catfish – Part 1

Share this article

If you’ve visited the site at all in the last 2 months you would have most likely noticed our new Catfish book banners hugging the page bottom from time-to-time. Since they launched, we’ve been receiving around 3-4 comments/email per week asking how it’s done. So, rather than answering each email individually, we thought this is might be a good place to walk you through the finer points — for those interested. The Catfish waits.. Of course, the code has always been there in public view, but if you have ever trawled through it you’ll know that SitePoint has a lot of deeply interwoven CSS and scripting, so we’re going to break out a streamlined version of the Catfish into a holding tank. Firstly, some basics. Yes, the Catfish is ‘nought but a ‘garden-variety’ DIV with some CSS and a bit of JavaScript to make it shimmey — no crazy technology required. The first ‘proof of concept’ was hacked together with no animation and pure CSS. At that stage the idea was just get a sense of how it looked on the page, so we set it up quickly using the ‘position:fixed’ CSS property and a little JavaScript to make it go away when asked. The DIV was slotted in at the end, just before the closing BODY tag. We also padded the bottom of the HTML element to make sure the footer could never be obscured by the Catfish.

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
Now all we need to do is call this script from inside our conditional comment. IE now has the extra ‘leg-up’ it needs and all the other little browsers will be none the wiser.
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 WalkerAlex Walker
View Author

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.

Share this article
Read Next
Powerful React Form Builders to Consider in 2024
Powerful React Form Builders to Consider in 2024
Femi Akinyemi
Quick Tip: How to Animate Text Gradients and Patterns in CSS
Quick Tip: How to Animate Text Gradients and Patterns in CSS
Ralph Mason
Sending Email Using Node.js
Sending Email Using Node.js
Craig Buckler
Creating a Navbar in React
Creating a Navbar in React
Vidura Senevirathne
A Complete Guide to CSS Logical Properties, with Cheat Sheet
A Complete Guide to CSS Logical Properties, with Cheat Sheet
Ralph Mason
Using JSON Web Tokens with Node.js
Using JSON Web Tokens with Node.js
Lakindu Hewawasam
How to Build a Simple Web Server with Node.js
How to Build a Simple Web Server with Node.js
Chameera Dulanga
Building a Digital Fortress: How to Strengthen DNS Against DDoS Attacks?
Building a Digital Fortress: How to Strengthen DNS Against DDoS Attacks?
Beloslava Petrova
Crafting Interactive Scatter Plots with Plotly
Crafting Interactive Scatter Plots with Plotly
Binara Prabhanga
GenAI: How to Reduce Cost with Prompt Compression Techniques
GenAI: How to Reduce Cost with Prompt Compression Techniques
Suvoraj Biswas
How to Use jQuery’s ajax() Function for Asynchronous HTTP Requests
How to Use jQuery’s ajax() Function for Asynchronous HTTP Requests
Aurelio De RosaMaria Antonietta Perna
Quick Tip: How to Align Column Rows with CSS Subgrid
Quick Tip: How to Align Column Rows with CSS Subgrid
Ralph Mason
15 Top Web Design Tools & Resources To Try in 2024
15 Top Web Design Tools & Resources To Try in 2024
SitePoint Sponsors
7 Simple Rules for Better Data Visualization
7 Simple Rules for Better Data Visualization
Mariia Merkulova
Cloudways Autonomous: Fully-Managed Scalable WordPress Hosting
Cloudways Autonomous: Fully-Managed Scalable WordPress Hosting
SitePoint Team
Best Programming Language for AI
Best Programming Language for AI
Lucero del Alba
Quick Tip: How to Add Gradient Effects and Patterns to Text
Quick Tip: How to Add Gradient Effects and Patterns to Text
Ralph Mason
Logging Made Easy: A Beginner’s Guide to Winston in Node.js
Logging Made Easy: A Beginner’s Guide to Winston in Node.js
Vultr
How to Optimize Website Content for Featured Snippets
How to Optimize Website Content for Featured Snippets
Dipen Visavadiya
Psychology and UX: Decoding the Science Behind User Clicks
Psychology and UX: Decoding the Science Behind User Clicks
Tanya Kumari
Build a Full-stack App with Node.js and htmx
Build a Full-stack App with Node.js and htmx
James Hibbard
Digital Transformation with AI: The Benefits and Challenges
Digital Transformation with AI: The Benefits and Challenges
Priyanka Prajapat
Quick Tip: Creating a Date Picker in React
Quick Tip: Creating a Date Picker in React
Dianne Pena
How to Create Interactive Animations Using React Spring
How to Create Interactive Animations Using React Spring
Yemi Ojedapo
10 Reasons to Love Google Docs
10 Reasons to Love Google Docs
Joshua KrausZain Zaidi
How to Use Magento 2 for International Ecommerce Success
How to Use Magento 2 for International Ecommerce Success
Mitul Patel
5 Exciting New JavaScript Features in 2024
5 Exciting New JavaScript Features in 2024
Olivia GibsonDarren Jones
Tools and Strategies for Efficient Web Project Management
Tools and Strategies for Efficient Web Project Management
Juliet Ofoegbu
Choosing the Best WordPress CRM Plugin for Your Business
Choosing the Best WordPress CRM Plugin for Your Business
Neve Wilkinson
ChatGPT Plugins for Marketing Success
ChatGPT Plugins for Marketing Success
Neil Jordan
Managing Static Files in Django: A Comprehensive Guide
Managing Static Files in Django: A Comprehensive Guide
Kabaki Antony
The Ultimate Guide to Choosing the Best React Website Builder
The Ultimate Guide to Choosing the Best React Website Builder
Dianne Pena
Exploring the Creative Power of CSS Filters and Blending
Exploring the Creative Power of CSS Filters and Blending
Joan Ayebola
How to Use WebSockets in Node.js to Create Real-time Apps
How to Use WebSockets in Node.js to Create Real-time Apps
Craig Buckler
Best Node.js Framework Choices for Modern App Development
Best Node.js Framework Choices for Modern App Development
Dianne Pena
SaaS Boilerplates: What They Are, And 10 of the Best
SaaS Boilerplates: What They Are, And 10 of the Best
Zain Zaidi
Understanding Cookies and Sessions in React
Understanding Cookies and Sessions in React
Blessing Ene Anyebe
Enhanced Internationalization (i18n) in Next.js 14
Enhanced Internationalization (i18n) in Next.js 14
Emmanuel Onyeyaforo
Essential React Native Performance Tips and Tricks
Essential React Native Performance Tips and Tricks
Shaik Mukthahar
How to Use Server-sent Events in Node.js
How to Use Server-sent Events in Node.js
Craig Buckler
Five Simple Ways to Boost a WooCommerce Site’s Performance
Five Simple Ways to Boost a WooCommerce Site’s Performance
Palash Ghosh
Elevate Your Online Store with Top WooCommerce Plugins
Elevate Your Online Store with Top WooCommerce Plugins
Dianne Pena
Unleash Your Website’s Potential: Top 5 SEO Tools of 2024
Unleash Your Website’s Potential: Top 5 SEO Tools of 2024
Dianne Pena
How to Build a Chat Interface using Gradio & Vultr Cloud GPU
How to Build a Chat Interface using Gradio & Vultr Cloud GPU
Vultr
Enhance Your React Apps with ShadCn Utilities and Components
Enhance Your React Apps with ShadCn Utilities and Components
David Jaja
10 Best Create React App Alternatives for Different Use Cases
10 Best Create React App Alternatives for Different Use Cases
Zain Zaidi
Control Lazy Load, Infinite Scroll and Animations in React
Control Lazy Load, Infinite Scroll and Animations in React
Blessing Ene Anyebe
Building a Research Assistant Tool with AI and JavaScript
Building a Research Assistant Tool with AI and JavaScript
Mahmud Adeleye
Understanding React useEffect
Understanding React useEffect
Dianne Pena
Web Design Trends to Watch in 2024
Web Design Trends to Watch in 2024
Juliet Ofoegbu
Building a 3D Card Flip Animation with CSS Houdini
Building a 3D Card Flip Animation with CSS Houdini
Fred Zugs
How to Use ChatGPT in an Unavailable Country
How to Use ChatGPT in an Unavailable Country
Dianne Pena
An Introduction to Node.js Multithreading
An Introduction to Node.js Multithreading
Craig Buckler
How to Boost WordPress Security and Protect Your SEO Ranking
How to Boost WordPress Security and Protect Your SEO Ranking
Jaya Iyer
Understanding How ChatGPT Maintains Context
Understanding How ChatGPT Maintains Context
Dianne Pena
Building Interactive Data Visualizations with D3.js and React
Building Interactive Data Visualizations with D3.js and React
Oluwabusayo Jacobs
JavaScript vs Python: Which One Should You Learn First?
JavaScript vs Python: Which One Should You Learn First?
Olivia GibsonDarren Jones
13 Best Books, Courses and Communities for Learning React
13 Best Books, Courses and Communities for Learning React
Zain Zaidi
5 jQuery.each() Function Examples
5 jQuery.each() Function Examples
Florian RapplJames Hibbard
Implementing User Authentication in React Apps with Appwrite
Implementing User Authentication in React Apps with Appwrite
Yemi Ojedapo
AI-Powered Search Engine With Milvus Vector Database on Vultr
AI-Powered Search Engine With Milvus Vector Database on Vultr
Vultr
Understanding Signals in Django
Understanding Signals in Django
Kabaki Antony
Why React Icons May Be the Only Icon Library You Need
Why React Icons May Be the Only Icon Library You Need
Zain Zaidi
View Transitions in Astro
View Transitions in Astro
Tamas Piros
Getting Started with Content Collections in Astro
Getting Started with Content Collections in Astro
Tamas Piros
What Does the Java Virtual Machine Do All Day?
What Does the Java Virtual Machine Do All Day?
Peter Kessler
Become a Freelance Web Developer on Fiverr: Ultimate Guide
Become a Freelance Web Developer on Fiverr: Ultimate Guide
Mayank Singh
Layouts in Astro
Layouts in Astro
Tamas Piros
.NET 8: Blazor Render Modes Explained
.NET 8: Blazor Render Modes Explained
Peter De Tender
Mastering Node CSV
Mastering Node CSV
Dianne Pena
A Beginner’s Guide to SvelteKit
A Beginner’s Guide to SvelteKit
Erik KückelheimSimon Holthausen
Brighten Up Your Astro Site with KwesForms and Rive
Brighten Up Your Astro Site with KwesForms and Rive
Paul Scanlon
Which Programming Language Should I Learn First in 2024?
Which Programming Language Should I Learn First in 2024?
Joel Falconer
Managing PHP Versions with Laravel Herd
Managing PHP Versions with Laravel Herd
Dianne Pena
Accelerating the Cloud: The Final Steps
Accelerating the Cloud: The Final Steps
Dave Neary
An Alphebetized List of MIME Types
An Alphebetized List of MIME Types
Dianne Pena
The Best PHP Frameworks for 2024
The Best PHP Frameworks for 2024
Claudio Ribeiro
11 Best WordPress Themes for Developers & Designers in 2024
11 Best WordPress Themes for Developers & Designers in 2024
SitePoint Sponsors
Top 10 Best WordPress AI Plugins of 2024
Top 10 Best WordPress AI Plugins of 2024
Dianne Pena
20+ Tools for Node.js Development in 2024
20+ Tools for Node.js Development in 2024
Dianne Pena
The Best Figma Plugins to Enhance Your Design Workflow in 2024
The Best Figma Plugins to Enhance Your Design Workflow in 2024
Dianne Pena
Harnessing the Power of Zenserp for Advanced Search Engine Parsing
Harnessing the Power of Zenserp for Advanced Search Engine Parsing
Christopher Collins
Build Your Own AI Tools in Python Using the OpenAI API
Build Your Own AI Tools in Python Using the OpenAI API
Zain Zaidi
The Best React Chart Libraries for Data Visualization in 2024
The Best React Chart Libraries for Data Visualization in 2024
Dianne Pena
7 Free AI Logo Generators to Get Started
7 Free AI Logo Generators to Get Started
Zain Zaidi
Turn Your Vue App into an Offline-ready Progressive Web App
Turn Your Vue App into an Offline-ready Progressive Web App
Imran Alam
Clean Architecture: Theming with Tailwind and CSS Variables
Clean Architecture: Theming with Tailwind and CSS Variables
Emmanuel Onyeyaforo
How to Analyze Large Text Datasets with LangChain and Python
How to Analyze Large Text Datasets with LangChain and Python
Matt Nikonorov
6 Techniques for Conditional Rendering in React, with Examples
6 Techniques for Conditional Rendering in React, with Examples
Yemi Ojedapo
Introducing STRICH: Barcode Scanning for Web Apps
Introducing STRICH: Barcode Scanning for Web Apps
Alex Suzuki
Using Nodemon and Watch in Node.js for Live Restarts
Using Nodemon and Watch in Node.js for Live Restarts
Craig Buckler
Task Automation and Debugging with AI-Powered Tools
Task Automation and Debugging with AI-Powered Tools
Timi Omoyeni
Quick Tip: Understanding React Tooltip
Quick Tip: Understanding React Tooltip
Dianne Pena
12 Outstanding AI Tools that Enhance Efficiency & Productivity
12 Outstanding AI Tools that Enhance Efficiency & Productivity
Ilija Sekulov
React Performance Optimization
React Performance Optimization
Blessing Ene Anyebe
Introducing Chatbots and Large Language Models (LLMs)
Introducing Chatbots and Large Language Models (LLMs)
Timi Omoyeni
Migrate to Ampere on OCI with Heterogeneous Kubernetes Clusters
Migrate to Ampere on OCI with Heterogeneous Kubernetes Clusters
Ampere Computing
Scale Your React App with Storybook and Chromatic
Scale Your React App with Storybook and Chromatic
Daine Mawer
10 Tips for Implementing Webflow On-page SEO
10 Tips for Implementing Webflow On-page SEO
Milan Vracar
Create Dynamic Web Experiences with Interactive SVG Animations
Create Dynamic Web Experiences with Interactive SVG Animations
Patricia Egyed
Get the freshest news and resources for developers, designers and digital creators in your inbox each week