html - Why the content in the span elements can't be put in the div container? -


the content in p elements can put in div container following css codes.

    * {        margin: 0 0 0 0;        padding: 0 0 0 0      }      div.container {        width: 400px;        height: 121px;        border: 1px solid red;        position: absolute;        bottom: 0px;        left: 0px;        right: 0px;        top: 0px;        margin: auto;      }      div.box {        float: left;      }      div img {        margin: 0px;        padding: 0;        width: 121px;        height: 121px;        float: left;      }      div.description {        float: left;        border 1px solid red;        margin: 10px 50px;      }
<div class="container">    <div class="box">      <img src="images/set06.jpg" />    </div>    <div class="description">      <p>music mane: xxxxxxxx</p>      <p>author: yyyyyyyy</p>      <p>publication:20081001</p>      <p>language:english</p>    </div>  </div>

enter image description here

now replace p elements span elements.

    * {        margin: 0 0 0 0;        padding: 0 0 0 0      }      div.container {        width: 400px;        height: 121px;        border: 1px solid red;        position: absolute;        bottom: 0px;        left: 0px;        right: 0px;        top: 0px;        margin: auto;      }      div.box {        float: left;      }      div img {        margin: 0px;        padding: 0;        width: 121px;        height: 121px;        float: left;      }      div.description {        float: left;        border 1px solid red;        margin: 10px 50px;      }
<div class="container">    <div class="box">      <img src="images/set06.jpg" />    </div>    <div class="description">      <span>music mane:  xxxxxxxx</span>      <span>author:  yyyyyyyy</span>      <span>publication:20081001</span>      <span>language:english</span>    </div>  </div>

the displayed effect following. enter image description here

all contents in span out of div container,not same effect in p elements,how make contents in span elements within div container?

the reason works in first case , not second because <p> tags display: block default , <span> tags display: inline default. block paragraph elements display 1 per line within parent, , since parent floated, take width necessary.

but, inline span tags, display side side, taking width can, causing parent (the description div) wider space right of image. so, description div displays below image.

to fix this, can set display: block on span elements. like:

div.description span {     display: block; } 

here's working demo: https://jsfiddle.net/uy8x9z4v/. however, since <p> tags have block display feature need, recommend using them instead of spans, unless have reason not to.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -