Solved

correct way use div tags

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
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.
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
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 …

760 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

17 Experts available now in Live!

Get 1:1 Help Now