Solved

Image Fit

Posted on 2013-01-30
2
260 Views
Last Modified: 2013-01-31
Hi, I have the following table with an image on the background, The problem is that I havent been able to make it Fit without resizing the Div "Shrink"

<!doctype html>
<html>
<head>
<style>
div.background
  {
  width:500px;
  height:250px;
  background-image:url("http://writing-jobs-uk.com/wp-content/uploads/2012/06/green-energy.jpg");
  border:2px solid black;
  }
div.transbox
  {
  width:400px;
  height:180px;
  margin:30px 50px;
  background-color:#ffffff;
  border:1px solid black;
  opacity:0.6;
  filter:alpha(opacity=60); /* For IE8 and earlier */
  }
div.transbox p
  {
  margin:30px 40px;
  font-weight:bold;
  color:#000000;
  }
</style>
</head>

<body>

<div class="background">
<div class="transbox">
<p>This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
This is some text that is placed in the transparent box.
</p>
</div>
</div>

</body>
</html>

Open in new window

0
Comment
Question by:jhonc66
  • 2
2 Comments
 
LVL 52

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 38838382
Your image is too large - you need to scale it to the size of your div. You can do this in CSS like so
line 5 of your html file change background-image to
  background:url("http://writing-jobs-uk.com/wp-content/uploads/2012/06/green-energy.jpg") no-repeat;
  background-size: 500px 250px;
  ...
}

Open in new window


Add the width and height to the background declaration

However, As Usual, this won't work in IE8 so alternatively resize your image or look here
http://stackoverflow.com/questions/4885145/ie-8-background-size-fix
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 38842629
Thanks but as a matter of interest - why the B rating?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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.
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 code hide show and toggles. 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…

910 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

26 Experts available now in Live!

Get 1:1 Help Now