how can one prevent a horizontal list from breaking?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crippletoe
    New Member
    • Jun 2010
    • 9

    how can one prevent a horizontal list from breaking?

    Hi all, i am looking for a way to prevent a horizontal, inline unordered list from breaking into seperate lines once contained inside a element with specific width (shorter than the list). the element has "overflow" set to "hidden".

    the only way i found to create that effect is by giving a specific width to the "UL" element but now, i have to create that effect for a list with unknown width!! (user can add items to list). is there any other way? it would help me so much!!

    thank you all
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Can you give an example of some (shortened) code of you current HTML and CSS? Also a screenshot if you think it would help.

    Comment

    • crippletoe
      New Member
      • Jun 2010
      • 9

      #3
      i will try to post a link to an example page but consider this code in the meanwhile:
      HTML:
      Code:
      <div id="container">
      <ul id="list">
      <li>item1</li>
      <li>item2</li>
      <li>item3</li>
      <li>item4</li>
      <li>item5</li>
      <li>item6</li>
      <li>item7</li>
      </ul>
      </div>
      CSS:
      Code:
      #container{
      width: 200px;
      overflow: hidden;
      }
      #list{
      display: inline;
      }
      
      #list li{
      float: left;
      }
      the list is horizontal and if it is wider than the width of the <div> it will break and continue on a new line.
      i would like it to go on on the same line beyond the border of the #container DIV.

      Comment

      • zorgi
        Recognized Expert Contributor
        • Mar 2008
        • 431

        #4
        If you give #container a height and overflow will be hidden.

        Comment

        • crippletoe
          New Member
          • Jun 2010
          • 9

          #5
          i am afraid this does not prevent the UL from breaking it will simply hide the vertical overflow caused by the line breaking.

          Comment

          • zorgi
            Recognized Expert Contributor
            • Mar 2008
            • 431

            #6
            Thats how I understood your problem. What exactly are you trying to achive if not to hide overflow?

            Comment

            • crippletoe
              New Member
              • Jun 2010
              • 9

              #7
              i am trying to create a horizontal scroller on the container div. overflow will be set to auto than but i cannot even get to that stage because the list keeps breaking to a new line when it reaches the border of the div and so there is no need for the horizontal scroller..

              Comment

              • JKing
                Recognized Expert Top Contributor
                • Jun 2007
                • 1206

                #8
                Code:
                #container{
                width: 200px;
                overflow-y:hidden;
                overflow-x:scroll;
                white-space:nowrap;
                }
                #list{
                
                
                
                }
                 
                #list li{
                display: inline;
                
                }
                Is this what you are looking for?

                Comment

                • zorgi
                  Recognized Expert Contributor
                  • Mar 2008
                  • 431

                  #9
                  similar :


                  Code:
                  #container{
                  	width: 200px;
                  	overflow: auto;		
                  }
                  #list{
                  	white-space:nowrap;
                  	padding: 0;
                  	margin: 0;
                  }
                  #list li{
                  	display: inline;
                  }

                  Comment

                  • crippletoe
                    New Member
                    • Jun 2010
                    • 9

                    #10
                    Originally posted by JKing
                    Code:
                    #container{
                    width: 200px;
                    overflow-y:hidden;
                    overflow-x;scroll;
                    white-space:nowrap;
                    }
                    #list{
                    
                    
                    
                    }
                     
                    #list li{
                    display: inline;
                    
                    }
                    Is this what you are looking for?
                    doesnt work. still breaks to a new line.

                    Comment

                    • JKing
                      Recognized Expert Top Contributor
                      • Jun 2007
                      • 1206

                      #11
                      Originally posted by crippletoe
                      doesnt work. still breaks to a new line.
                      I tested it and it works fine in Firefox and IE8.

                      Make sure you moved display:inline from #list to #list li.

                      Comment

                      Working...