When I set width: 100%
to a input element it stretches to the whole width of its parent, but then I do the same with a span
tag, it doesn't stretch, but only stays as it was, having the same width as without setting width: 100%
. Span
and input
tags are both inline, so I can't understand why they work differently.
Can you please explain why it works in this way?
Here's the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
input {
width: 100%;
margin-bottom: 10px;
}
span {
width: 100%;
}
</style>
<title>Document</title>
</head>
<form action="#">
<input type="text">
<input type="text">
<input type="text">
</form>
<div class="spanBlock">
<span>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Qui aut obcaecati quod error ipsa. Mollitia,
officiis excepturi. Accusamus distinctio unde deserunt nobis animi ut nemo quia quidem culpa, voluptas
temporibus?</span>
</div>
</body>
</html>