placing button tag inside span tag is right way of placement
You can of course use CSS to render the span as a block element, or even an inline-block if that is what you need.
.yourSpanClass {
display: block;
}
.yourSpanClass {
display: inline-block;
}
Though, i'd advice you to simply use a div if you have access to the HTML.
Supported browsers: http://caniuse.com/inline-block
Should button contain nested DOM element or not?
I tested your code in W3C Validator & the error shown is
Element div not allowed as child of element button in this context. (Suppressing further errors from this subtree.)
Is it bad practice to use spans as buttons ? W3Schools is doing that
Is it bad practice to use spans as “buttons”?
Yes. They are, by default:
- Not announced as being interactive by screen readers
- Not in the tab order so are inaccessible to keyboard users
It's possible to hack around that by use of tabindex
and ARIA, but using a real <button>
is much simpler and better supported.
You can get a much deeper dive into this subject from Inclusive Components by Heydon Pickering.
W3C is doing that
No, they aren't.
W3Schools is a low-quality advert-ridden tutorial site that happens to have good SEO because they've been around forever.
They've picked a name which lets them be confused with the W3 Consortium. Note, however, that "Consortium" and "Schools" are not the same word!
Weird div in button behaviour
You can't use <div>
inside a <button>
. W3 HTML docs says that a <button>
must contain only phrasing content. Phrasing content is defined as including <span>
but not <div>
.
It is also incorrect when validated: http://validator.w3.org/#validate_by_input+with_options
SOURCE: Is it semantically incorrect to put a <div> or <span> inside of a <button>?
Sidenote: You should also clean up your code. For example linear-gradient
can't be used as background-color
, but should be used as background-image
div not staying inside button
Per the comment of isherwood:
A block-level element has no business in a button. What's its
purpose here? Use a span instead and set it to inline-block if
necessary.
Related Topics
How to Horizontally Center an Unordered List of Unknown Width
How to Embed a Google Drive Folder in a Website
Is Cross-Origin Postmessage Broken in Ie10
What Is the ::Content/::Slotted Pseudo-Element and How Does It Work
How to Disable the Resize Grabber of <Textarea>
How to Change the Opacity (Alpha, Transparency) of an Element in a Canvas Element
Why Cannot Change Checkbox Color Whatever I Do
Using HTML in Jquery UI Autocomplete
Is It Correct to Use Alt Tag for an Anchor Link
Workaround for Href="File://///..." in Firefox
CSS Transition - Eases in But Doesn't Ease Out
Can a Span Be Closed Using <Span />
Highlight the Navigation Menu for the Current Page
Get Rid of Space Underneath Inline-Block Image
Internet Explorer 11 Disable "Display Intranet Sites in Compatibility View" via Meta Tag Not Working
How to Embed a Swf File in an HTML Page
Which Is More Correct: <H1><A>...</A></H1> or <A><H1>...</H1></A>