A <td> element can legally contain "flow content" meaning a <div> is perfectly legal inside a <td>. This means your above example is in fact valid HTML markup.
As far as the question goes if it is content and to be displayed inline such as a portion of text within a <p> you wish to make stand out, be differrent or what not than the rest of the text within the <p> element then a <span> is the way to go. If it is
a separate block of content say a title to be displayed over a paragraph or if it is a block of text a <div> would be the correct solution.
Simple definitions of inline and block elements: block: an element which forms a separate block inline: an element which stays inline with the rest of the content
spans are used for like two to three words while you need to color or style only some text but the div is used for whole one element like a whole table.
It can be used for some text too.
Depending on you work. You need a class or id not a div or span. You can use any of them but div is better.
Please "Marks As Answer" if any answer helped you out!
~~! FIREWALL !~~
baodt
Member
130 Points
165 Posts
Span or div.
Jan 10, 2013 02:55 AM|LINK
Hi all !!!
I have a table :
<table><tr><td>
Example
</td></tr></table>
I want to padding example text but i dont want use padding td.
I want to wrap span or div.
My question is what should i use, span or div, why ??? In mind , i think use span.
alankarp
Contributor
2042 Points
345 Posts
Re: Span or div.
Jan 10, 2013 03:42 AM|LINK
<span> is an inline element and <div> is a block element.but you can't put block elements inside inline elements so
is invalid and
is valid, according to me you should use span
Profile
Sujeet Saste
Contributor
2998 Points
572 Posts
Re: Span or div.
Jan 10, 2013 03:52 AM|LINK
Hi try below markup :
<table> <tr> <td> <span style="padding:10px">Example</span> </td> </tr> </table>If you any other query feel free to ask.
Do FEAR (Face Everything And Rise)
Please mark as Answer if my post helps you..!
My Blog
baodt
Member
130 Points
165 Posts
Re: Span or div.
Jan 10, 2013 06:04 AM|LINK
Yes thank you but i want to ask if html and css is invalid in a website, how does it cause harm ???
roopeshreddy
All-Star
20155 Points
3328 Posts
Re: Span or div.
Jan 10, 2013 11:18 AM|LINK
Hi,
No harm! May be the display will be distorted if it's not placed correctly!
<SPAN> or <DIV> will go find inside <TD>!
If you wish to use Inline, then go with <SPAN> tag - ie., Some test <SPAN> Some test</SPAN>
If you wish to use NewLine or block, go with <DIV>!
Hope it helps u...
Roopesh Reddy C
Roopesh's Space
jprochazka
Contributor
4886 Points
740 Posts
Re: Span or div.
Jan 10, 2013 11:42 AM|LINK
A <td> element can legally contain "flow content" meaning a <div> is perfectly legal inside a <td>. This means your above example is in fact valid HTML markup.
The content model for a <td> includes flow content:
http://www.w3.org/TR/html5/tabular-data.html#the-td-element
Elements making up flow content which is basically anything that can used within a <body> tag.
http://www.w3.org/TR/html5/dom.html#flow-content-1
Anyways...
As far as the question goes if it is content and to be displayed inline such as a portion of text within a <p> you wish to make stand out, be differrent or what not than the rest of the text within the <p> element then a <span> is the way to go. If it is a separate block of content say a title to be displayed over a paragraph or if it is a block of text a <div> would be the correct solution.
Simple definitions of inline and block elements:
block: an element which forms a separate block
inline: an element which stays inline with the rest of the content
ramramesh
Member
458 Points
158 Posts
Re: Span or div.
Jan 10, 2013 11:52 AM|LINK
Use
Afzaal.Ahmad...
Contributor
2661 Points
1040 Posts
Re: Span or div.
Jan 10, 2013 05:28 PM|LINK
Ok, first learn what they actually are.
spans are used for like two to three words while you need to color or style only some text but the div is used for whole one element like a whole table.
It can be used for some text too.
Depending on you work. You need a class or id not a div or span. You can use any of them but div is better.
~~! FIREWALL !~~