Solved

correct way use div tags

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
styling bootstrap grid system with CSS 2 37
Show Ruler in Outlook 2010 STILL NOT SHOWING! 4 23
Html Newline 7 20
How to create a table with buttons 3 21
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

790 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