Solved

background image resize

Posted on 2013-05-15
8
493 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
  • 4
  • 4
8 Comments
 
LVL 9

Expert Comment

by:Sar1973
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:jagguy
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 9

Expert Comment

by:Sar1973
Comment Utility
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
Comment Utility
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
Comment Utility
O.k. I guessed also a solution for your swap questions, hope both could fit.
0
 

Author Closing Comment

by:jagguy
Comment Utility
I posted the solution for others
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now