Why doesn't my div inside a span work properly?

前端 未结 7 1784
猫巷女王i
猫巷女王i 2020-12-18 23:46

I\'m writing the following HTML markup:

 Some Text
    
татата

and s

相关标签:
7条回答
  • 2020-12-18 23:49

    span display:inline you must set it display:inline-block
    but this not standard you must use div span always use for text your fiddle demo

    0 讨论(0)
  • 2020-12-18 23:51

    span is an inline-element, while div ist not. you should consider swapping them..

    0 讨论(0)
  • 2020-12-18 23:53

    By default div's is a block element and span is an inline element. Block elements always flow vertically and inline elements always flow next to each other from top left to the bottom right depends on screen width. We can use inline elements under the block element, not vice versa. If we override we expect to see some issues like this on responsive layout.

    0 讨论(0)
  • 2020-12-18 23:55

    span is an inline element so it will not take notice of your height and width. For this you need to give it either:

    display:block; or display: inline-block

    0 讨论(0)
  • 2020-12-18 23:57

    Your markup is incorrect ( plus missing semi-colon as quoted by Steini, mentioning this for sake of completeness of answer )

    Answer 1 : span is an inline element, so having a div inside span is a bad idea, also, it would be better, if you nest span inside span and give inner span display:block property!

    Answer 2 : add display:block to span to change the default behavior

    working fiddle with correct markup

    fiddle with the layout you wanted

    0 讨论(0)
  • 2020-12-19 00:12

    First answer: You forgot the semi-colon after height style, that's why it is not rendered.

    Second answer: If you look closely, the border appears after the div. This is because you are inserting block level element inside inline element. So, block level element takes it to the next line and then it takes the whole line. On the very next line you can see the right border for the span.

    It is bad practice to put block level element inside inline element. In fact, I do not see any practical use of this kind of structure. Please, correct it if you are learning.

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