Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-28-2012, 05:37 PM   PM User | #1
Saber
New Coder

 
Join Date: Sep 2012
Posts: 34
Thanks: 9
Thanked 0 Times in 0 Posts
Saber is an unknown quantity at this point
How to add small background behind the letters

Hello, here is an example of what i need:

Code:
<body>
<p>Hello stranger
<p>Welcome to the site
</body>
Now how to make tose 2 sentances with White collor and the background with blue ? like this on the screen i just made to show you what i need:
Attached Thumbnails
Click image for larger version

Name:	testtt.JPG
Views:	40
Size:	2.8 KB
ID:	11588  
Saber is offline   Reply With Quote
Old 09-28-2012, 06:07 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,335
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
fisrt you want to start with a valid example:

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
</head>

<body>
<p>Hello stranger
<p>Welcome to the site
</body>

</html>
then you need to close your paragraph elements properly

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
</head>

<body>
<p>Hello stranger</p>
<p>Welcome to the site</p>
</body>

</html>
then you apply a Class to the elements you want to style


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

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
</head>

<body>
<p class="myClass1>Hello stranger</p>
<p class="myClass1>Welcome to the site</p>
</body>

</html>
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Users who have thanked DanInMa for this post:
Saber (09-29-2012)
Old 09-28-2012, 06:08 PM   PM User | #3
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,335
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
then you embed CSS styling in your document

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
<style media="screen" type="text/css">

.myClass1 {
  color: white;
 background-color : blue;

}
</style>
</head>

<body>
<p class="myClass1>Hello stranger</p>
<p class="myClass1>Welcome to the site</p>
</body>

</html>
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Users who have thanked DanInMa for this post:
Saber (09-29-2012)
Old 09-28-2012, 06:10 PM   PM User | #4
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,335
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
here's a site to learn more : http://www.htmldog.com/guides/cssbeginner/
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 09-28-2012, 06:22 PM   PM User | #5
Saber
New Coder

 
Join Date: Sep 2012
Posts: 34
Thanks: 9
Thanked 0 Times in 0 Posts
Saber is an unknown quantity at this point
Quote:
Originally Posted by DanInMa View Post
then you embed CSS styling in your document

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
<style media="screen" type="text/css">

.myClass1 {
  color: white;
 background-color : blue;

}
</style>
</head>

<body>
<p class="myClass1>Hello stranger</p>
<p class="myClass1>Welcome to the site</p>
</body>

</html>
If i put this code on a test html page i only get white background with the black letters - Welcome to the site nothing more it's like typing this bellow, can you see if you have made a mistake ?

Code:
<!DOCTYPE html>
<html>
<body>


<p>My first paragraph.</p>

</body>
</html>
Saber is offline   Reply With Quote
Old 09-29-2012, 02:01 AM   PM User | #6
Saber
New Coder

 
Join Date: Sep 2012
Posts: 34
Thanks: 9
Thanked 0 Times in 0 Posts
Saber is an unknown quantity at this point
I got to here and it does the job.. there is only one problem. How to make the background color of the letters to the end of the given field...

<span style="background-color: #0099FF"><span style="color:white"><b><small>Hello site</small></b></span></span><br>

So now "hello site" is blue white on blue background, but i want the entire row after that, to be blue also even though there is no text in it and the next row to be as default white..
Saber is offline   Reply With Quote
Old 09-29-2012, 11:58 AM   PM User | #7
transybao
New to the CF scene

 
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
transybao is an unknown quantity at this point
You put it into a <div>...</div> tag and then set css <style type="text/css">
transybao is offline   Reply With Quote
Old 09-29-2012, 12:11 PM   PM User | #8
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,827
Thanks: 9
Thanked 685 Times in 679 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
There's just two missing closing quotes in DanInMa's code:

Code:
<p class="myClass1">Hello stranger</p>
<p class="myClass1">Welcome to the site</p>
That'll do what you want. Use the w3c validator to pick up these kind of typos.

Because p is a block element it will take up the widht of the page. span is an inline element and won't.
SB65 is offline   Reply With Quote
Users who have thanked SB65 for this post:
Saber (09-29-2012)
Old 09-29-2012, 10:47 PM   PM User | #9
Saber
New Coder

 
Join Date: Sep 2012
Posts: 34
Thanks: 9
Thanked 0 Times in 0 Posts
Saber is an unknown quantity at this point
I have problem.. so i'm using this now, but there is an extra row... The text in blue background is ok, but after that text there is empty row and after that is the regular text... there is no <br> or other.. how to remove this empty row... example:

Text in blue background:
(empty row that i need to remove)
My text on the page... so any ideas !?

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
<style media="screen" type="text/css">

.myClass1 {
  color: white;
 background-color : blue;

}
</style>
</head>

<body>
<p class="myClass1">Hello stranger</p>
<p class="myClass1">Welcome to the site</p>
</body>

</html>

Last edited by Saber; 09-29-2012 at 10:51 PM..
Saber is offline   Reply With Quote
Old 09-30-2012, 01:41 PM   PM User | #10
Saber
New Coder

 
Join Date: Sep 2012
Posts: 34
Thanks: 9
Thanked 0 Times in 0 Posts
Saber is an unknown quantity at this point
I found what i need, here it is :
<div style="background-color: #0099FF"><span style="color:white"><b><small>my site</small></b></span></div>
Saber is offline   Reply With Quote
Old 09-30-2012, 03:44 PM   PM User | #11
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,827
Thanks: 9
Thanked 685 Times in 679 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
Quote:
The text in blue background is ok, but after that text there is empty row
That's coming from the default bottom margin on p. Make your css:

Code:
.myClass1 {
  color: white;
 background-color : blue;
 margin:0

}
and the earlier code is fine, with no extra markup.
SB65 is offline   Reply With Quote
Old 10-02-2012, 02:37 PM   PM User | #12
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,335
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
Sorry, I missed a qoutation, merked in red.

Quote:
Originally Posted by DanInMa View Post
then you embed CSS styling in your document

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Title of document</title>
<style media="screen" type="text/css">

.myClass1 {
  color: white;
 background-color : blue;
margin: 0;
}
</style>
</head>

<body>
<p class="myClass1">Hello stranger</p>
<p class="myClass1">Welcome to the site</p>
</body>

</html>
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 10-02-2012, 02:40 PM   PM User | #13
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,335
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
Quote:
Originally Posted by Saber View Post
I found what i need, here it is :
<div style="background-color: #0099FF"><span style="color:white"><b><small>my site</small></b></span></div>
You really may want to look up more information on CSS, maybe jsut a beginners tutorial to get you started ( check out stickies in the CSS forum for suggestions) . If you style your pages like this, which is referred to as inline styling, it's going to make things more difficult for you in the long run.
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 10-02-2012, 02:41 PM   PM User | #14
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,335
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
oh also sorry for the slow reply. My home was burlgarized so I have no computers at the moment.
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:54 AM.


Advertisement
Log in to turn off these ads.