Solved

Resizing background image

Posted on 2011-03-23
4
625 Views
Last Modified: 2012-05-11
I have a footer  image I want to use but I want the width to resize to the screen width. I have the resizing working but in order to resize it as an image I had to put it in an <img> tag so I could give it an id which then made it a control... and now I can't put text on top of it.

What am I doing wrong here??

Thanks!

    <div id="footerdiv" class="footer" >
        <img src="/Images/footer.png" width="100%" alt="background image" id="bg" onload="resizeImg(this)"  />
        <p>
           <asp:Label ID="Label1" runat="server" Text="Corporate Information" Font-Underline="false"
                    Font-Size="Small" ForeColor="#4e5766" />
            </a>&nbsp | &nbsp
            <asp:HyperLink runat="server" ID="hlTOS" Style="text-decoration: none" NavigateUrl="~/TOS.aspx"
                ForeColor="#4e5766" Text="Terms of Service" />
            &nbsp | &nbsp
            <asp:LinkButton runat="server" ID="lnkLogout" Style="text-decoration: none" OnClick="Logout"
                Text="Logout" ForeColor="#4e5766" />
        </p>
        
    </div>

Open in new window


<script type="text/javascript">

        window.onload = function () {
            window.onresize = function () { resizeImg(document.getElementById('bg')); }
        }
        var availWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
        function resizeImg(img) {
            img.style.width = availWidth + "px";
        }


    </script>

Open in new window

0
Comment
Question by:md0333
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
Akenathon earned 500 total points
ID: 35202749
Throw it behind the rest of the page if you want to put text over it:

<img src="/Images/footer.png" width="100%" alt="background image" id="bg" onload="resizeImg(this)" style="position:relative; z-index:-1" />

See http://www.w3schools.com/Css/pr_pos_z-index.asp and http://www.w3schools.com/Css/css_positioning.asp
0
 

Author Comment

by:md0333
ID: 35202858
didn't work for my use... I have my footer stuck to the bottom of the viewable area. Your example worked in that it put the image at the bottom of the page but then the user had to scroll down. I have it right now so that the header and footer <div> stay where they are and the rest of the page scrolls (if needed). If I use your code inside the <div> tag I get no change in usability.

I tried putting the image as a background image of the <div> but then, while I can get the <div> to resize, I can't get the image to resize because I don't have an ID for the image.
0
 

Author Comment

by:md0333
ID: 35202890
I got it! I just created a second <div> tag for the image using the same css class as the footer. Having the z-index="-1" pushedi it behind.

Perfect!

Thank you!
0
 
LVL 11

Expert Comment

by:Akenathon
ID: 35203003
Cool! Glad it worked :-)
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question