Why does an inline element take width and height when floated?

Now I have a span element that I give it a width and height, for example 500px I know its an inline element, so it doesn't accept width and height, but why is it applied when I float?

span.first {
  width: 500px;
  height: 500px;
  border: 1px solid #000;
  float: right;
}

span.second {
  width: 500px;
  height: 500px;
  border: 1px solid #000;
}
      

<span class="first">with float</span>
<span class="second">without float</span>
      

Run codeHide result


https://codepen.io/kemozzz/pen/KvVrXj

+3


source to share


2 answers


As per CSS rules, when you float an element, in most cases it becomes a block element. Elements that are inline and inline blocks will be evaluated to block.



From MDN: enter image description here

+3


source


When you float an element, it automatically becomes display: block

.

From the specification:



enter image description here

https://www.w3.org/TR/CSS22/visuren.html#dis-pos-flo

0


source







All Articles