say you are working without the <p>
element in HTML. How would you stylize a simple text with css? What HTML-Tag would you take? I always used <span>
, but now I saw that span should always be used to group inline-elements (for example <p>
). And thats not the case in my example.
Thanks, phpheini
Div tags are basically <span> tags for block elements instead of inline elements. So if I want for example a text to have a specific size I should use a div where my text is inside? Is this really a good way? Yep.
Span and div are both generic HTML elements that group together related parts of a web page. However, they serve different functions. A div element is used for block-level organization and styling of page elements, whereas a span element is used for inline organization and styling.
Well answer to your question is yes and no,What I mean by that is "p" is a block level tag for paragraphs. "span" is a line level tag that in and of itself doesn't do anything, but is useful for defining a specific style to a string. "span" can be used within "p", but "p" cannot be used within "span".
The val() method looks for for the an attribute named 'value' on the selector. eg. In a span element, you would typically not use value, but have text inside the element.
First you should look whether some tag matches semantically. For instance, you might have a text which requires emphasis, in which case em
is the best choice. Another case is if you have a heading, which you could style with h1
, ..., h6
. Always first consider this option!
If there really is no meaning to the text you want to style, or at least, not a meaning supported by css, you can use either span
(for inline text) or div
(for block elements).
You're free to use any tag you wish... (Within reason); Just make sure it's semantic.
Just a few you could use:
<div>
<em>
<strong>
<small>
<pre>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With