Solved

image resize on swap images

Posted on 2013-05-17
3
371 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
[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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Suggested Courses

623 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