Solved

correct way use div tags

Posted on 2013-01-02
2
405 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
2 Comments
 
LVL 16

Accepted Solution

by:
hankknight earned 500 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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now