Solution
Move the closing </p>
tag and replace div
elements by span
, which are displayed inline
instead of block
(explanation):
HTML
<span id="whatido"><button onclick="whatIDo()">What do I do?</button></span>
<button onclick="displayResult()">Madlib</button>
<span id="madlib"></span></p>
You can also set the display
property of your buttons to block
in your css to ensure they're not inline with your text.
CSS
button{
display:block;
}
JSFiddle
Explanation
div
elements will not stack horizontally, they have the property display:block
set by default which makes them take a whole space and clear their sides. To fix this issue, replace div
elements by span
elements. The span
elements are in display:inline
by default which makes them line up instead of taking a whole block of space
NOTE: a div
element is not considered valid inside a p
tag.
W3Schools' definitions
The <span>
tag is used to group inline-elements in a document.
The <div>
tag defines a division or a section in an HTML document.
The <div>
tag is used to group block-elements to format them with CSS.
Sources:
http://www.w3schools.com/tags/tag_div.asp
http://www.w3schools.com/tags/tag_span.asp