Log In · Register

 
 
Closed TopicStart new topic
DIV IMAGE!, I can't get it to work.
Select
post Jun 21 2008, 05:36 PM
Post #1


Senior Member
***

Group: Member
Posts: 74
Joined: Oct 2006
Member No: 472,652



Well, I'm trying to put a simple image in my DIV.
This is my first time making one, and this is bringing down my hopes.
Could you help I don't know what I'm doing wrong.

CODE
<div class="bg" style="position: absolute; left:50%; top:50%; width:640px; height:480px; overflow: hidden;">
<img src="http://i31.tinypic.com/2f07hiu.jpg">
</div>
 
fixtatik
post Jun 22 2008, 10:23 PM
Post #2


Senior Member
******

Group: Member
Posts: 1,237
Joined: May 2008
Member No: 648,123



that should work fine. do you have any other codes in your profile that might be breaking it?

a couple quick notes, as well. if you're going to put styles within an HTML tag itself, then you don't need to assign it a class. classes are used to call a style from a style sheet.

for example, you can do something like the following:
CODE
<style type="text/css">
.bg {
  background:url(LINK TO YOUR IMAGE);
  position:absolute;
  left:50%; top:50%;
  width:640px; height:480px;
  overflow:hidden; }
</style>

<div class="bg">
  Any text you want would go here.
</div>

in your case, you're trying to define a class and give it a style at the same time, which is unnecessary. it's not necessarily wrong per se, although someone who strictly follows web standards would call it wrong.

in the div you're building, are you trying to put it in the exact center of your page? if you are, try adding in margin:-240px 0 0 -320px;. with what you're doing, the top:50%; and left:50%; move the top of the div to the middle of the page, and the left side of the div to the middle of the page. the margins will move them up and to the left to put the entire div in the middle (half the width and height).
 

Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: