SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Using CSS "inline" attribute for <div> tags, how to make <p> tags stay inside them

    .

    Hello;

    I need to display <div> tags side-by-side or inline. This style sheet code will do what I need:

    PHP Code:
    div.display_inline
    {
    displayinline;

    Using just the <div> tags the text displays inline just fine.
    PHP Code:
    <div class="display_inline">
        
    one two three
    </div>

    <
    div class="display_inline">
        
    four five six
    </div
    The above will display "one two three four five six" on one line.

    However, if I try to enclose the text within each <div> tag with a <p> tag like this:

    PHP Code:
    <div class="display_inline">
    <
    p>one two three</p>
    </
    div>

    <
    div class="display_inline">
    <
    p>four five six</p>
    </
    div
    The text ends up on two lines like this:

    "one two three
    four five six"

    Can somebody tell me how to make the text within each <p> tag stay inside of the <div> tags?

    Thanks.
    .

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,331
    Mentioned
    463 Post(s)
    Tagged
    8 Thread(s)
    I would recommend you use float: left on those divs and give them a width (either in pixels or something approaching 50%).

    But you could also just set a width on the divs, but as I say, I think floats are better for this.

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    The p element's default display's value is block. You have to set the inline display's value for them too:

    Code CSS:
    div.display_inline,.display_inline p  {
       display: inline;
    }

  4. #4
    SitePoint Addict Volitics's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ralph.m, Candygirl;

    Thank you for responding to my question. I just got through trying the solutions. They both work really good.

    Thanks again.
    .


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •