?
Solved

correct way use div tags

Posted on 2013-01-02
2
Medium Priority
?
426 Views
Last Modified: 2013-01-03
I am using Dreamweaver and when applying CSS rules I see it doesnt use div tags.
For example applying css rules to some tags I can get

<span class="one">hello</span>
<img src="dd.jpg" class="two"/>

However I could also do the same with same effect
<div class="one">hello</div>

Should I only use div tags for containers?
0
Comment
Question by:jagguy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
hankknight earned 2000 total points
ID: 38738463
You need to learn the difference between inline-level and block-level elements:
http://www.htmlhelp.com/reference/html40/inline.html
http://www.htmlhelp.com/reference/html40/block.html

The div element is a block-level element while the span tag is an inline-level element.  That is the primary difference between the two.

You may ONLY place inline-level elements inside other inline elements.  

So you may place an image inside either a span or a div tag, because the image tag is an inline element.

You may never place block level elements, like a <p> tag, inside a <span> tag.

By the way, don't forget to add an alt attribute to your image tag.  It is required.
<img src="dd.jpg" class="two" alt=""/>

Don't forget to test your code here:
http://validator.w3.org/
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 38738505
It wl depend on what you are trying to do.  @hanknight summed it up except you can place your spans inside divs p's (block level).  Use spans to style code differently than you style your div.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question