Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

background image resize

Posted on 2013-05-15
8
Medium Priority
?
516 Views
Last Modified: 2013-05-21
Hi

I have a background image with small images on it.
I need to set the height someway as it is 240px but for a responsive website what do i do here?set %?

How do I get the background to resize
 #heading{
	  height:240px;
	background-image:url(images/head7.png);
 }

Open in new window

0
Comment
Question by:jagguy
[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
  • 4
  • 4
8 Comments
 
LVL 9

Expert Comment

by:Sar1973
ID: 39170893
In JS you can assign an ID and/or name to an image and then toggle its dimensions with its attributes (see http://www.w3schools.com/html/html_images.asp).
0
 

Author Comment

by:jagguy
ID: 39170909
This doesnt work .
I resize the browser and the background image doesnt also resize, it isnt responsive.
I read you cant do this  without css3 which I dont want.
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39170943
Try this code in W3 schools editor (modified from http://www.w3schools.com/html/html_images.asp) and click on the image:
<!DOCTYPE html>
<html>
<body>

<h2>Norwegian Mountain Trip</h2>
<img ID="myImage" border="0" src="/images/pulpit.jpg" alt="Pulpit rock" width="304" height="228" onclick="myFunction()">

<script>
function myFunction() {
myimg = document.getElementById("myImage");
myimg.style.height = "50%";
myimg.style.width = "50%";
}
</script>

</body>
</html>

Open in new window

Take a look also to http://stackoverflow.com/questions/170624/javascript-image-resize if you want to introduce absolute variable, scale variables, etc.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:jagguy
ID: 39171449
no this is not what I want and it wont work anyway with media query

Ok I have a background image (not an regular image on screen see below)
To resize this image or swap it over with another using  the below query what do i do?

@media screen and (max-width: 700px) {

}


#heading{
	  height:240px;
	background-image:url(images/head7.png); /////image is set this way
 }

 <div id="heading">
</div

Open in new window

0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39171684
To change the image you can use: document.getElementById("myImage").src="(path)\newImage.jpg"; or use this function using as argument the ID of the image and assigning also the lowsrc property to the alternative image:
function changeimage(myIMG) {
	myELM=document.getElementById(myIMG);
	myELMIMG=myELM.src;
	myELM.src=myELM.lowsrc;
	myELM.lowsrc=myELMIMG;
}

Open in new window

0
 

Accepted Solution

by:
jagguy earned 0 total points
ID: 39173336
Hi,

I solved it.
I can resize the image like this below. The browser resizes and so does the back image. The other option is setting a new image on media queries . The above solution uses another option of JS which looks to do what media queries does .


	 	 img, embed, object, video {

  max-width: 100%;
   
}

@media screen and (max-width: 980px) 
{

#heading{
	 height:240px;
	 /* width:980px;*/
	  background-size:100% 100%;
	  background-image:url(images/head7.png);
	  background-repeat:no-repeat;
 }

Open in new window

0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39174075
O.k. I guessed also a solution for your swap questions, hope both could fit.
0
 

Author Closing Comment

by:jagguy
ID: 39183813
I posted the solution for others
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
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…

609 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