Solved

image resize on swap images

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How does this modal work? 3 33
Responsive Image Distorting 2 28
drop down menu blocks search boxes 4 23
CSS - display the same fonts throughout website. 4 25
This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

738 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