Solved

image resize on swap images

Posted on 2013-05-17
3
366 Views
Last Modified: 2013-05-22
I have code that has links in a row and swaps images.
This was an ordeal to say the least.

The images dont resize as i thought on browser resize so I had to use media queries to alter size of these images.

Can I get the images to resize without adding media queries?

here is what happens, see I get only past of the image displayed on resize?

http://www.mymrt.net/ComputerTraining/test4.html
 img, embed, object, video {

  max-width: 100%;
   
}

ul.nav
{
    list-style-type: none;
    padding: 0;
    margin: 0;
    float: left;
    
}


.nav li#welcome a {
	 background-image:url(images/ic1.png); 
  background-repeat: no-repeat; 
	 
	 }
.nav li#welcome a:hover {
	 background-image:url(images/ic1b.png); 
  background-repeat: no-repeat; 
 
  
   }

.nav li#welcome2 a {
	 background-image:url(images/ic1.png); 
  background-repeat: no-repeat; 
	 
	 }
.nav li#welcome2 a:hover {
	 background-image:url(images/ic1b.png); 
  background-repeat: no-repeat; 
  
   }
 .nav li#welcome3 a {
	 background-image:url(images/ic1.png); 
  background-repeat: no-repeat; 
	 
	 }
.nav li#welcome3 a:hover {
	 background-image:url(images/ic1b.png); 
  background-repeat: no-repeat; 
 
  
   }

.nav li#welcome4 a {
	 background-image:url(images/ic1.png); 
  background-repeat: no-repeat; 
	 
	 }
.nav li#welcome4 a:hover {
	 background-image:url(images/ic1b.png); 
  background-repeat: no-repeat; 
  
   }
 
   
#head ul li a
	{
	text-decoration: none;
	
	float:left;
	margin-right:40px;

	}

#head ul li 
{
     display: inline;
	 

 }
#head img
{
      max-width: 100%;

 }


#head ul
{
/*margin-left: 15%;*/
padding:0;

list-style-type: none;

border:none;

}	



@media screen and (min-width: 960px) 
{
	ul.nav a{  height: 100px; width: 100px;}
}

@media screen and (max-width: 959px) 
{
	ul.nav a{  height: 50px; width: 50px;}
}

</style>
</head>

<body>

lkjl
<div id="head">
  <ul class="nav">
    <li id="welcome"><a href="home.html"></a></a></li>
    <li id="welcome2"><a href="home.html"></a></a></li>
      <li id="welcome3"><a href="home.html"></a></a></li>
    <li id="welcome4"><a href="home.html"></a></a></li>
  </ul>
</div>

Open in new window

0
Comment
Question by:jagguy
3 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39176570
Yes you can using javascript/jquery or any other programming language but better one is using media queries.
http://blog.kurtschindler.net/post/flexible-dynamically-resizing-images-with-css
0
 

Author Comment

by:jagguy
ID: 39176601
No that doesnt work for a list of images with specific names as below.
I can do a basic example but it gets complicated for real examples.
The below gives me no output

	.nav li#welcome a {
	 background-image:url(images/ic1.png); /*todo  set %size here */
  background-repeat: no-repeat; 
   background-size:100% 100%;
	
	 }
.nav li#welcome a:hover {
	 background-image:url(images/ic1b.png); 
  background-repeat: no-repeat; 
 
  
   }

.nav li#welcome2 a {
	 background-image:url(images/ic1.png); 
  background-repeat: no-repeat; 
	background-size:100% 100%;
	 }
.nav li#welcome2 a:hover {
	 background-image:url(images/ic1b.png); 
  background-repeat: no-repeat; 
  
}

#head ul li a
	{
	text-decoration: none;
	float:left;
	margin-right:40px;

	}
#head ul li 
	{
	
max-width:100px;
	}	
#welcome{
	max-width:100px;
	
}
#welcome2{
	max-width:100px;
	
}
@media screen and (min-width: 960px) 
{

}

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

}

</style>
</head>

<body>

lkjl
<div id="head">
  <ul class="nav">
    <li id="welcome"><a href="home.html"></a></li>
    <li id="welcome2"><a href="home.html"></a></li>
      
  </ul>
</div>

Open in new window

0
 
LVL 6

Accepted Solution

by:
lightspeedvt earned 500 total points
ID: 39181651
You have to add this style to a tags and it's hovers:

background-size: 100%;

Open in new window

So you will have:

.nav li#welcome a {
	background-image:url(http://www.mymrt.net/ComputerTraining/images/ic1.png); 
	background-repeat: no-repeat; 
	background-size: 100%;	 
}

Open in new window


Forgot to add that you need to add it to all styles with images.

Here is demo:
http://jsfiddle.net/TxSrg/
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

830 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