difference between div and span tag

前端 未结 10 1448
眼角桃花
眼角桃花 2020-12-29 04:33

Can anyone give me the difference between div and span tags?

相关标签:
10条回答
  • 2020-12-29 04:49

    The difference between span and div is that a span element is in-line and usually used for a small chunk of in-line HTML whereas a div (division) element is block-line (which is basically equivalent to having a line-break before and after it) and used to group larger chunks of code.

    <div id="scissors">
        <p>This is <span class="paper">crazy</span></p>
    </div>
    

    div and especially span shouldn't actually be used that often. Whenever there is a sensible alternative that should be used instead. For example, if you want to emphasize the word 'crazy' and the class 'paper' is bold, then the code might look like this:

    <div id="scissors"> 
        <p>This is <strong class="paper">crazy</strong></p>
    </div>
    
    0 讨论(0)
  • 2020-12-29 04:52

    div - it is a dom element with display property as a block that is element will take the whole row that is with the line-break.

    <div>Your website name?</div>
    <div>http://www.array151.com</div>
    

    will be displayed in two different rows. and each div will be considered as an individual block.

    Your website name?
    http://www.array151.com
    

    span - dom element with display property inline that is without line-break.

    <span>Your website name?</span>
    <span>http://www.array151.com</span>
    

    the result will be on the same line because of the span

    Your website name?http://www.array151.com
    
    0 讨论(0)
  • 2020-12-29 05:03

    Div is a block element; span - inline, so

    • Div's places in separate lines; span's in one line
    • Div's has width, span's haven't
    0 讨论(0)
  • 2020-12-29 05:03

    Div: It is working like as a Block, equivalent to having a line-break. Span: It is working like as an inline. For Example :

    ** Div and Span Difference
    Div Example

    What is Your Name?

    My Name is Aruna Thakur

    Span Example What is Your Name : My Name is Aruna Thakur **`End Code'

    0 讨论(0)
提交回复
热议问题