By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,716 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,716 IT Pros & Developers. It's quick & easy.

How do I add to a Div element?

100+
P: 103
I have a div tag called container. I want to create two more elements, one for a image and another for text. The image container should be in the upper right corner and the text container should align next to the image container. So my question is how do I add independent elements to the #Container element so that when I use the image element or text element it only applies to those elements within the container element only?
Jun 7 '11 #1

✓ answered by drhowarddrfine

If you mean how do you apply css to the image element or text element only, then, assuming you use the img and p tags, it would be:
Expand|Select|Wrap|Line Numbers
  1. #container img {}
  2. #container p {}
and the html would be:
Expand|Select|Wrap|Line Numbers
  1. <div id="container">
  2. <img src="">
  3. <p>Some text</p>
  4. </div>
Though you could just include the image inside the p to keep it attached to the text.
Expand|Select|Wrap|Line Numbers
  1. <p><img src="">Some text</p>

Share this Question
Share on Google+
1 Reply


drhowarddrfine
Expert 5K+
P: 7,435
If you mean how do you apply css to the image element or text element only, then, assuming you use the img and p tags, it would be:
Expand|Select|Wrap|Line Numbers
  1. #container img {}
  2. #container p {}
and the html would be:
Expand|Select|Wrap|Line Numbers
  1. <div id="container">
  2. <img src="">
  3. <p>Some text</p>
  4. </div>
Though you could just include the image inside the p to keep it attached to the text.
Expand|Select|Wrap|Line Numbers
  1. <p><img src="">Some text</p>
Jun 7 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.