How To Align A Button Inside A Div
I'm sure this will be ridiculously simple, but whatever... I'm trying to display a text area with a button to its right, similar to how StackOverflow displays a comment field with
Solution 1:
The reason why it is not adjacent to the textarea is because the div encompassing the text area is too large. If you inspect element on Chrome, you will notice where all the elements are.
I'd suggest you do not put them in separate divs if you want them stuck together.
<style>.newComment {
position: relative;
width: 475px;
background-color: white;
}
</style><divclass='newComment'><textareastyle='border:1px solid #888; overflow:auto'rows='3'cols='40'>comments</textarea><inputtype='submit'value='Add Comment' /></div>
Solution 2:
You've set the width
s of the container div
s but you haven't specified the height
, so your padding is not taking. I've provided a sample below so you can visually see what is happening...
Below is a possible solution with the button aligned to the vertical center:
Solution 3:
try this
.newComment {
position: relative;
width:475px;
background-color:WHITE;
}
<divclass='newComment'><divstyle='float:left;width:375px;'><textareastyle='border:1px solid #888;overflow:auto'rows='3'cols='40'>comments </textarea></div><divstyle='float:left;width:75px;'><inputstyle="float: left; margin-top: 20px;"type='submit'value='Add Comment'/></div></div>
Post a Comment for "How To Align A Button Inside A Div"