is float property depend on being block level element or inline level element?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sedigh mohseni
    New Member
    • Feb 2011
    • 64

    is float property depend on being block level element or inline level element?

    Hi
    I want to float first letter of the paragraph and give diffrent styles to that.
    I use below code that work correctly but i think there is a problem because background-color property of the p element is not affected .
    Code:
    <html>
    <head>
    <style type="text/css">
    div { float: left; width: 50px; font-size: 400%; color: red; line-height: 80%; margin: 0; padding: 0;}
    p { border: 1px solid maroon; background-color: aqua; }
    </style>
    </head>
    <body>
    <p>
    <div>T</div>his is some text.This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.
    This is some text. This is some text. This is some text.This is some text. This is some text. This is some text. In the paragraph above, the first letter of the text is embedded in a span element.The span element has a width that is 0.7 times the size of the current font.In the paragraph above, the first letter of the text is embedded in a span element.
    The span element has a width that is 0.7 times the size of the current font.
    </p>
    </body>
    </html>
    So i change div tag to span tag and change div selector to span selector , then all things work correctlly ,second code is as follow:
    Code:
    <html>
    <head>
    <style type="text/css">
    span { float: left; width: 50px; font-size: 400%; color: red; line-height: 80%; margin: 0; padding: 0;}
    p { border: 1px solid maroon; background-color: aqua; }
    </style>
    </head>
    <body>
    <p>
    <span>T</span>his is some text.This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.This is some text. This is some text. This is some text.
    This is some text. This is some text. This is some text.This is some text. This is some text. This is some text. In the paragraph above, the first letter of the text is embedded in a span element.The span element has a width that is 0.7 times the size of the current font.In the paragraph above, the first letter of the text is embedded in a span element.
    The span element has a width that is 0.7 times the size of the current font.
    </p>
    </body>
    </html>
    and I wonder what is diffrence between using span or div element in this example ? would you please describe me what happend in each state and what is diffrence for?
    thanks alot in advance.
  • drhowarddrfine
    Recognized Expert Expert
    • Sep 2006
    • 7434

    #2
    Your first example is invalid. Block level elements cannot exist inside an inline one. You could look into 'inline-block', though. Also, google for the css property 'first-letter'.

    Comment

    • sedigh mohseni
      New Member
      • Feb 2011
      • 64

      #3
      okay , you're right i can use first-letter property but i want to use float property , and about your answer in my first example i use div element inside p element and i think both of them are block level elements , are'nt they?

      Comment

      • hellodipak
        New Member
        • Jun 2010
        • 26

        #4
        You can use 'p' element inside 'div', but div inside p is kinda unacceptable. Read more on inline-block - http://dipaksblogonline.blogspot.com...ine-block.html

        Comment

        Working...