?
Solved

Resizing background image

Posted on 2011-03-23
4
Medium Priority
?
627 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Suggested Courses

762 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