Need Help Using 2 Images In CSS

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #12) by vujsa on Jun 16 2006, 02:37 PM. (Line Breaks Removed)
Keep in mind that if you use an image in the background, then there has to be something in the foreground to hold the place usually.Try placing a space " " inside of the <div> tags to hold it open so to speak. That may be all you need.Another topic you might be interested in if you don't like having to edit every page you own all of the time just for one or two changes is the ... read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Free Web Hosting > Computers & Tech > Programming > Scripting > Miscellaneous Scripting Languages & Ideas

Need Help Using 2 Images In CSS

lonebyrd
Im trying to use a blue textured background image on my website using CSS. That would be all well and good if I didn't want to also use a picture with the name of my site that I made in photoshop in CSS also. I just don't know how to get the two to work using CSS without one canceling the other out. Is it possible to use two images with CSS? If so, can someone tell me how? I can't find a tutorial on it.

Reply

vujsa
Not entirely sure what you are asking here but I think this is it.

You have background_x.jpg that you have tiled or repeated on your website as the MAIN background. You also have a site banner (banner_y.jpg) that you want to have displayed say in the top left corner of your website. Now for some reason, you don't want to simply use an <IMG> tag in the correct spot for banner_y.jpg.

Am I following you so far?

If so, then you need only use a <DIV> tag where ever you want banner_y.jpg and set the background-image as banner_y.jpg.

So for <BODY>, background-image is background_x.jpg and <DIV>, the background-image is banner_y.jpg.

If your HTML is as follows:
CODE

<html>
    ...
    <body>
        <div class="banner"><!-- Banner Area --></div>
        ...
    </body>
</html>


Then your CSS should be like so:
CODE

body
{
    background-image: url(background_x.jpg);
    background-repeat: repeat;
}

.banner
{
    background-image: url(banner_y.jpg);
    background-repeat: no-repeat;
}

Now of course you'll need to fill in the rest of your CSS and HTML data.
For .banner, you'll need to add size and position information as well.

I hope this answers your question. cool.gif

vujsa

 

 

 


Reply

yordan
Nice, vujsa, I had the same problem but I didn't dare ask the question. I'll try your method for the next pages I will have to write.

Reply

lonebyrd
Ok, I'm having a problem getting this to work. So I have a question. Do I add the URL for the banner and background where you put 'URL' or where it says '_x.jpg'? And another question I have is, I put the part about <DIV> in my regular script along with my link for my CSS page right? But why would I put a <DIV> when it isn't listed as a division, just a .banner?

Reply

vujsa
QUOTE(lonebyrd @ Jun 14 2006, 10:28 AM) *

Ok, I'm having a problem getting this to work. So I have a question. Do I add the URL for the banner and background where you put 'URL' or where it says '_x.jpg'? And another question I have is, I put the part about <DIV> in my regular script along with my link for my CSS page right? But why would I put a <DIV> when it isn't listed as a division, just a .banner?


CODE
.banner
{
    background-image: url(banner_y.jpg);
    background-repeat: no-repeat;
}


Okay, last things first and first things last. wacko.gif
I used the .banner class deffinition without the tag information so that you could actually use the banner information in any HTML element that has a class named "banner".
You can if you want change .banner to div.banner.
For the url of the background-image you place the address of theimage inside of the parenthesis like this:
background-image: url(http://www.somedomain.com/images/banner_y.jpg);
or the short (relative) form:
background-image: url(/images/banner_y.jpg);

So the new and improved .banner entry in you CSS would look like this:
CODE
div.banner
{
    background-image: url(http://www.somedomain.com/images/banner_y.jpg);
    background-repeat: no-repeat;
}


Where banner_y.jpg will be replace with the actual image filename.

Hope this helps. cool.gif

vujsa

Reply

Vyoma
Hey vujsa , I have one more question. I had a similar problem that was faced by lonebyrd, and I solved it (rather, did a trial-and-error), and for doing that I used IDs instead of classes.

For illustration, I used the following CSS:
CODE

#banner {
    background-image: url(banner_y.jpg);
    background-repeat: no-repeat;
}


and then later used it in the HTML as follows:
CODE

<div id="banner"></div>


I just wanted to know what are the differences between using a class or an ID. I am sorry if this sounds dumb, but I have not gone about studying CSS in detail. I used it just to get some work done instead of relying on tables.

Could you please clear the two concepts of classes and ids?

Reply

vujsa
To the best of my knowledge, defining a style based on either class or id will work the same. I have never had any problems in that respect.

For the sake of good and standardized coding, a class is a general style rule whereas id is a specific style rule.

No 2 items in your HTML should have the same ID. One ID per item only. If you want to use <div id="banner"> then you should not use the "banner" id for any other tags, items, atrributes, etc... It is THAT items id only.

A class is a group of items which should be treated the same or similarly. This is where you should define your styles for a group of items like similar table cells: <td class="header"> where this would denote a table cell at the top of the table used as a header. Maybe the font and color are different than the other cells on the same table.

Think of it like this:
A class is like a group of students in school. CSS is the teacher and it teaches its class which is made up of several students each with their own id. The teacher may have a few classes to teach but has many students to teach. Some students need extra instruction that are different from the rest of the class.

You should do a search on the internet for CSS ID and CSS class which should point you to a few websites that are dedicated to explaining CSS.

Hope this helps. cool.gif

vujsa

Reply

vizskywalker
Vujsa is 100% correct, although he did not get at the main reason for the difference. The reason why both exist comes down to the DOM and XML requirements. To properly parse and navigate an XML document for more than simple stylistic ends, which is one of the plusses of XML, sometimes information about the items must be stored in the element itself, hence the purpose of the id and class attributes. The id attribute, as vujsa explained, identifies one specific entity. This is useful because instead of having to define a person as such in XML:
CODE
<person>
<name>
  vizskywalker
</name>
<personaldata>
  data
</personaldata>
</person>

You can create it like so:
CODE
<person id="vizskywalker">
<personaldata>
  data
</personaldata>
</person>

In this oversimplified example, it doesn't seem to make much difference, but when writing scripts such as javascripts to handle the XML document, being able to easily find and identify one entity without having to go through the whole tree it is connected to can be very important.

Other than stylistic purposes, the class attribute also has other uses in XML used for non-XHTML type XML documents:
CODE
<animal class="person" id="vizskywalker">
<communication>
  english
</communication>
</animal>

<animal class="person" id="vujsa">
<communication>
  english
</communication>
</animal>

<animal class="dog">
<communication>
  bark
</communication>
</animal>

As you can see, one type of element, the animal element, has many subgroups. Rather than define a new element to determine the type of animal, you can use the class attribute. You can even mix and match id and class attributes to determine the type of animal and which specific animal of that type.

~Viz

Reply

lonebyrd
I was re-reading the posts because for some reason I can't get this to work. Now I have what may be a stupid question. Vusja wrote originally and said:
QUOTE
Now for some reason, you don't want to simply use an <IMG> tag in the correct spot for banner_y.jpg.


Is there a way to put just images in CSS, not background images? Because every tutorial I've seen on CSS is all about background images, I've never seen anything with just an <IMG> tag before. If that's all I have to do, and it's that simple, I will do that. I just never knew that it was an option.

Reply

vujsa
Since you r request was for using CSS to display the image, I only gave that way. You can not use CSS to directly display and image. CSS adds styling to HTML like background information. SO you can show an image as a background only using the CSS.

You can always display an image in HTML using the <IMG> tag. You can even modify the appearence of the image with CSS.
CODE

<img src="http://www.somedomain.com/images/banner_y.jpg>


That's all of the required information needed. If you add an ID or class to the tag, you can control border, size, position, background and other information for the image. You can also you the default HTML commands to do many of the same functions.

CODE

<img src="http://www.somedomain.com/images/banner_y.jpg" width="100" height="20">


Since this is very basic HTML, I didn't think to include it in my answer.

There was a time before we had CSS that everything was done only using HTML and HTML is still capible of doing these functions but it makes it much easier to edit and customize the esign of your website using CSS. There are many webmasters still only using basic HTML to build their websites.

Let me know if you need more assistance. In the meantime, maybe you should take a look at these:
- http://www.astahost.com/html-101-web-desig...ners-t2998.html
- http://www.astahost.com/html-102-web-desig...ners-t3087.html

Hope this helps. cool.gif

vujsa

Reply

Latest Entries

vujsa
Keep in mind that if you use an image in the background, then there has to be something in the foreground to hold the place usually.

Try placing a space " " inside of the <div> tags to hold it open so to speak. That may be all you need.

Another topic you might be interested in if you don't like having to edit every page you own all of the time just for one or two changes is the CMS101 - Content Management System topic. It's a basic tutorial to using a simple template driven system to maintain your website that most people can easily do. Then when update or additions come to your site maybe only one or two files need to be changed.

Hope This Helps. cool.gif

vujsa

Reply

lonebyrd
Thanks, but I did know how to do it in HTML. I was just wondering if there was a seperate way to do it using CSS. I knew that was very basic, but what I was trying to avoid was having to put it on every page. But I shall figure out what I am doing wrong.

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Recent Queries:-
  1. display image xml document css - 52.51 hr back. (1)
  2. how to add image to xml document using css - 55.88 hr back. (1)
  3. background of a picture and the foreground of a picture, the deffinition - 98.32 hr back. (1)
  4. putting 2 images in css - 208.63 hr back. (1)
  5. how to put image in css - 226.02 hr back. (1)
  6. put a regular image in css - 227.08 hr back. (1)
  7. can you mix a class and id in the same tag - 231.54 hr back. (1)
  8. how to two images in css - 243.18 hr back. (1)
  9. query css pictures images - 252.23 hr back. (1)
  10. adding two images to the body in css - 264.20 hr back. (1)
  11. css background with texture and no image css - 287.83 hr back. (1)
  12. image in xml using css - 290.02 hr back. (1)
  13. two images css - 295.91 hr back. (1)
  14. how to display two image tags in css - 297.55 hr back. (1)
Similar Topics

Keywords : images css

  1. Images In XML - Help? - (3)



Looking for 2, images, css

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for 2, images, css
advertisement




Need Help Using 2 Images In CSS



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE