What is the difference between div with the property display:inline-block and span with display:inline-block?
What is the difference between div with the property display:inline-block and span with display:inline-block
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is two differences between
divandspanelements:divhasdisplay:blockas default, while span hasdisplay:inlineas default.divis a block element, and can contain block elements and inline elements, whilespanis an inline element and can only contain other inline elements.Once you have applied the
display:inline-blockthey behave the same.When the HTML code is parsed, the style is not considered. While you can change the
displaystyle to make the elements behave the same, you still have to follow the rules in the HTML code.This for example is valid:
This for example is invalid:
The browser will try to rearrange the elements in the invalid code, which usually means that it moves the
divelements outside thespanelements. As the HTML specification (prior to version 5) only told how correct code should be handled, each browser has its own way of dealing with incorrect code.