Solved

correct way use div tags

Posted on 2013-01-02
2
408 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

776 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