Jump to content

Div Class Body

- - - - -

  • Please log in to reply
5 replies to this topic

#1
Blimp

Blimp

    Programmer

  • Members
  • PipPipPipPip
  • 154 posts
Hi Guys,

Well i'v been creating a site for a few hours now and have got to a bit where im stuck; Iv made a class called "error" and have set it all out correctly. However, I want to define the body (with an image) in the Style settings. Here's the code so far...

.error{border: 2px solid #FF0000;padding:15px;margin:10px;background:#f8f8f8;HERE

}

Where the text "HERE" is located is where I would like to add the body. The body needs to be:

<img src="error.gif">There is an error



Can anybody whip us up a quick code for this?

Thanks a bunch!

#2
Vladimir

Vladimir

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
You need something like this (I did not check the code, so consider it as pseudo code).
.error{border: 2px solid #FF0000;padding:15px;margin:10px;background:#f8f8f8;}
.error-img {background-image: url('error.gif')}
HTML:
<div class="error"><span class="error-image"></span> There is an error</div>


#3
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
There is a kinda tricky (dirty) workaround for it like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html>

<head>

<style type="text/css">

	.error[B][COLOR="red"]:after[/COLOR][/B]{

		border: 2px solid #FF0000;

		padding:15px;margin:10px;

		background:#f8f8f8;

		[B][COLOR="red"]content:url(error.gif)'There is an error';[/COLOR][/B]

	}

  </style>

</head>

<body>

	<span class="error"/>

</body>

</html>
You'll notice that the div doesn't resize itself to the image's height. So i was trying to manually set the height of the div:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html>

<head>

<style type="text/css">

	.error:after{

		border: 2px solid #FF0000;

		[B][COLOR="red"]position: absolute;

		height:100px%;[/COLOR][/B]

		padding:15px;margin:10px;

		background:#f8f8f8;

		content:url(error.gif)'There is an error';

	}

  </style>

</head>

<body>

	<span class="error"/>

</body>

</html>

I gave as height 100px%. That actually was a typo, the "px%", but it seems to be the only notation that works :D 100% is the whole page, 100px isn't relative to the image.. 100px% seems to work for some weird reason.
(Note that for the content attribute to work in IE a doctype must be provided (as my first line))

Edited by wim DC, 28 November 2010 - 10:20 AM.


#4
Blimp

Blimp

    Programmer

  • Members
  • PipPipPipPip
  • 154 posts
Thanks for this amazing reply!

I'v just added this now, with a few of my own little edits. It's looking great!

Thanks again:)

#5
Blimp

Blimp

    Programmer

  • Members
  • PipPipPipPip
  • 154 posts

Vladimir said:

You need something like this (I did not check the code, so consider it as pseudo code).
.error{border: 2px solid #FF0000;padding:15px;margin:10px;background:#f8f8f8;}
.error-img {background-image: url('error.gif')}
HTML:
<div class="error"><span class="error-image"></span> There is an error</div>



This helped alot as well, thanks mate. Rep+

#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Lol, i just realised why the 100px% was working, and 100px or 100% wasn't good enough. "px%" just makes the rule invalid and css ignores it. It's only the position: absolute that was needed :D




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users