Looking for a way to keep the mobile ad unit fixed at the bottom of the screen

I am currently working on incorporating a 320x50 mobile ad into the mobile version of my website. The goal is to have the ad fill the entire width of a mobile device. However, the issue I'm facing is that the ad appears small and does not stretch across the entire width of my iPhone; furthermore, it scrolls along with the content.

To implement the mobile CSS on my webpage, I am using the following code:

<link rel="stylesheet" type="text/css" media="only screen and (max-device-width: 480px)" href="mobile2.css" />

Upon inspecting the CSS, I tried the following code snippet:

div#mobilead {
    width:100%;
}

My objective is to ensure that the ad remains fixed at the bottom of the screen even when scrolling. If you have any suggestions or solutions, they would be greatly appreciated. Thank you!

As requested, here is the complete code:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
 <link rel="stylesheet" type="text/css" media="only screen and (max-device-width: 480px)" href="mobile2.css" />

</head>

<body>


 <div id="mobileB">  
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- TWF_mobile_banner_adsense -->
<ins class="adsbygoogle"
     style="display:inline-block;width:320px;height:50px"
     data-ad-client="ca-pub-xxxxxxxxx"
     data-ad-slot="6479374699"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>


</body>
</html>

Below is the relevant CSS section:

#mobileB {
    position: absolute; 
    bottom:0;
    left:0;
    z-index: 99; 
    width:100%; 
    height:50px
}
}

Answer №1

Have you confirmed that the CSS is being given the highest priority? What is the current size of the displayed advertisement?

If the height of the div is constant, consider setting a static height to ensure consistency.

Answer №2

It would be great if you could provide the HTML structure as well. Understanding the div structure is crucial because of property inheritance in CSS. When working with positioning, it's important to consider not only the specific object's properties but also its parent elements.

Based on what I see, there doesn't seem to be a reason why it shouldn't scroll with the content. One suggestion could be to use fixed positioning for the ad placement. Depending on where you want the ad to be displayed, you can set specific coordinates. For example, for a "sticky" div in the top right corner:

position: fixed; 
top: 0px; 
right: 0px; 
z-index: 99; 
width:100%; 
height:50px;

If you need the ad positioned at the bottom, you can try this approach:

position: fixed; 
bottom:0;
left:0;
z-index: 99; 
width:100%; 
height:50px

Regardless of your decision, adjusting the top/bottom/left/right values, using position:fixed, and setting z-index should help you achieve your desired layout. Good luck! :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Enhance Your HTA Webpage with a Hover Zoom Effect on CSS Tables

Greetings and thank you for taking the time to read my message. I am relatively new to this, so please bear with me if things seem a bit disorganized. I have constructed a table and am attempting to implement a hover effect to zoom in on a specific cell w ...

When hovering over the bootstrap dropdown, the main dropdown remains a clickable link

How can I create a bootstrap dropdown menu that activates on hover, while still allowing the main button to link to a different page when clicked? Below is the HTML code: <div class="body-wrap"> <div class="container"> <nav class="navbar n ...

Customize the layout of menu icon in HTML/CSS using FlexBox Grid

Recently, I have encountered an issue with the position of a menu icon on my website. The icon is displayed when the window reaches a certain size, but it is not aligned properly on the right side of the site. Ideally, I would like to use the "right" prope ...

Ways to stop a background image from repeating?

<div style="background-image: url('https://i.ibb.co/v1B855w/bg15.png'); color: #000000; background-color: #000000; background-attachment: fixed; text-align: center;"><img src="https://i.ibb.co/L6zQY0S/name6.png" /> ...

Please only choose the immediate children of the body element

<body> <div> <div class='container'></div> </div> <div class='container'></div> </body> Is there a way to use jQuery to specifically target the second container div dire ...

Behold the magic of a three-column layout with sticky scroll behavior and an absolute

I am struggling with a layout that involves 3 columns, each with its own independent scroll. The first column contains an absolute element that should overflow on the x-axis, but I am having trouble getting the overflow-x:visible property to work when comb ...

Animation of two divs stacked on top of each other

I am trying to replicate the animation seen on this website . I have two divs stacked on top of each other and I've written the following jQuery code: $('div.unternehmen-ahover').hover( function () { $('div.unternehmen-ahover' ...

Is there a way for me to utilize the Bootstrap carousel without it adjusting the height as the user transitions from slide 1 to slide 2?

body{ background-color: #CAF7E3; } .container-fluid{ padding: 3% 15%; } .navbar{ font-family: 'Montserrat'; font-weight: bold; } .navbar-brand{ font-size: 2.5rem; } .nav-item{ margin-right: 2rem; } #title{ padding: 8% 15%; backgr ...

Enhance your Material UI Button with Advanced Text Alignment Options for Compact Screens

As a beginner in React and Material-UI, I'm attempting to customize a set of buttons within my app bar with background images for a cleaner look. Drawing inspiration from various online examples, I've managed to style them to my liking on larger ...

Ways to display and conceal menu depending on initial view and scrolling

On my website, I have implemented two menus - one to be displayed when the page loads and another to show up when a scroll occurs. You can view my page here. The goal is to have the white part visible when the position is at the top, and switch to the blu ...

Display issue with positioning user name in navbar on Internet Explorer

The user name appears correctly in the navbar on Firefox and Chrome, but in IE it drops down due to a break tag issue. Is there a way to resolve this in IE so that it displays like in Firefox and Chrome? body { padding-top: 102px; background-colo ...

When incorporating CSS with Bootstrap, it may not always have a visible impact on the

As a newcomer to using Bootstrap, I recently created a webpage with Bootstrap3. However, I encountered an issue when trying to apply two classes to the same element, as the CSS was not being applied: Here is the HTML code snippet: <div class="col-md-4 ...

Is it possible to precisely position multiple children in a relative manner?

I am currently developing a custom dropdown menu where I want the parent element to be relatively positioned within the page. The goal is for all the child elements of the dropdown menu (the list items) to appear as if they are part of a select element and ...

Display movie details in a responsive column layout that condenses into a single column

I'm having trouble displaying movie information on a website due to CSS and HTML issues. My goal is to align the title (Director:, Cast:, etc) with the first item in the list, and have all subsequent items follow below. I initially tried using a defin ...

The tooltip function is not functioning properly on Internet Explorer when the button is disabled

I have been utilizing a similar solution found at http://jsfiddle.net/cSSUA/209/ to add tooltips to disabled buttons. However, I am encountering an issue specifically in Internet Explorer (IE11). The workaround involves wrapping the button within a span: ...

mysterious glitch within my code

Accidentally inserted the following code snippet <style type="text/css"> into my Top_menu.css file due to a copy and paste error, forgetting to remove it. Now trying to delete all the code will crash everything!!! Here is my Top_menu.css file: ...

Creating a fixed top bar button in Ionic and iOS along with a scrollable list

In my app using Ionic with the iOS platform, I am trying to achieve a specific layout: A header A fixed bar button A scrollable list Here is what I have attempted so far: <ion-view view-title="Account"> <div class="button-bar" style="margin ...

Utilize Vue.js to sort by price bracket and category

Hello, I am currently new to working with Vue.js and I am attempting to create two filters - one for price range and the other for genre. Any guidance or assistance would be greatly appreciated. Below is a snippet of my code: ul class="filter-wrapper"&g ...

What steps should we take to ensure that the container beside the fixed left navigation bar is responsive?

Currently, I am working on creating a user interface that features a fixed navigation bar on the left hand side and a responsive content window. Here is what I have implemented so far: <div style="width: 15%; float: left; display: inline;"> <na ...

Easy ways to align sprite images and text in the center

I am trying to utilize css sprites for my website. I have a basic image and some text that I would like to display together. My goal is to center the image on the page, and then vertically center the text next to it. As a newcomer to css, I am struggling t ...