Solved

image resize on swap images

Posted on 2013-05-17
3
353 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
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 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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

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

15 Experts available now in Live!

Get 1:1 Help Now