Spill overflow text to another DIV

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Poulos

    Spill overflow text to another DIV

    Say I have a text area. When the user clicks a button the entered text
    displays in a DIV. If there's too much text to fit in that DIV then the
    overflow text (the text that doesn't fit in the first DIV) displays in
    an adjacent DIV.

    Is there a way to know if there's "overflowin g" text and, if there is,
    if there a way to know what that text is?

    Andrew Poulos
  • RobG

    #2
    Re: Spill overflow text to another DIV

    Andrew Poulos wrote:[color=blue]
    > Say I have a text area. When the user clicks a button the entered text
    > displays in a DIV. If there's too much text to fit in that DIV then the
    > overflow text (the text that doesn't fit in the first DIV) displays in
    > an adjacent DIV.
    >
    > Is there a way to know if there's "overflowin g" text and, if there is,
    > if there a way to know what that text is?
    >
    > Andrew Poulos[/color]

    You could look at the innerHTML of the second div or look for text
    nodes with values other than empty strings.

    But there is likely some other way related to however you are doing
    the overflow.

    --
    Rob

    Comment

    • Andrew Poulos

      #3
      Re: Spill overflow text to another DIV

      RobG wrote:[color=blue]
      > Andrew Poulos wrote:
      >[color=green]
      >> Say I have a text area. When the user clicks a button the entered text
      >> displays in a DIV. If there's too much text to fit in that DIV then the
      >> overflow text (the text that doesn't fit in the first DIV) displays in
      >> an adjacent DIV.
      >>
      >> Is there a way to know if there's "overflowin g" text and, if there is,
      >> if there a way to know what that text is?
      >>
      >> Andrew Poulos[/color]
      >
      >
      > You could look at the innerHTML of the second div or look for text nodes
      > with values other than empty strings.
      >
      > But there is likely some other way related to however you are doing the
      > overflow.[/color]

      Sorry, I think I've not explained it correctly. Text will only go into
      the second DIV if it doesn't fit in the first. So my question is
      reworded to, given a DIV of a known size and how can I know how much
      text will fit in it before it overflows?

      I'm happy enough to count lines and words per line but I don't know
      where the overflow occurs.

      Andrew Poulos

      Comment

      • Dag Sunde

        #4
        Re: Spill overflow text to another DIV

        "Andrew Poulos" <ap_prog@hotmai l.com> wrote in message
        news:42f7142d$0 $16471$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...[color=blue]
        > RobG wrote:[color=green]
        >> Andrew Poulos wrote:
        >>[color=darkred]
        >>> Say I have a text area. When the user clicks a button the entered text
        >>> displays in a DIV. If there's too much text to fit in that DIV then the
        >>> overflow text (the text that doesn't fit in the first DIV) displays in
        >>> an adjacent DIV.
        >>>
        >>> Is there a way to know if there's "overflowin g" text and, if there is,
        >>> if there a way to know what that text is?
        >>>
        >>> Andrew Poulos[/color]
        >>
        >>
        >> You could look at the innerHTML of the second div or look for text nodes
        >> with values other than empty strings.
        >>
        >> But there is likely some other way related to however you are doing the
        >> overflow.[/color]
        >
        > Sorry, I think I've not explained it correctly. Text will only go into
        > the second DIV if it doesn't fit in the first. So my question is
        > reworded to, given a DIV of a known size and how can I know how much
        > text will fit in it before it overflows?
        >
        > I'm happy enough to count lines and words per line but I don't know
        > where the overflow occurs.[/color]

        You can't, unless you hardcode the font size, *and* use a mono-spaced font
        (i.e. Courier). And then only if you examine the exact pixel height and
        width for that particular size up front.

        Can't you solve this another way instead? Autoscroll? Grow the div
        vertically?

        This is a problem generated by a UI design requirement, so what about
        looking
        into the design?

        --
        Dag.


        Comment

        • Andrew Poulos

          #5
          Re: Spill overflow text to another DIV

          Dag Sunde wrote:[color=blue]
          > "Andrew Poulos" <ap_prog@hotmai l.com> wrote in message
          > news:42f7142d$0 $16471$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...
          >[color=green]
          >>RobG wrote:
          >>[color=darkred]
          >>>Andrew Poulos wrote:
          >>>
          >>>
          >>>>Say I have a text area. When the user clicks a button the entered text
          >>>>displays in a DIV. If there's too much text to fit in that DIV then the
          >>>>overflow text (the text that doesn't fit in the first DIV) displays in
          >>>>an adjacent DIV.
          >>>>
          >>>>Is there a way to know if there's "overflowin g" text and, if there is,
          >>>>if there a way to know what that text is?
          >>>>
          >>>>Andrew Poulos
          >>>
          >>>
          >>>You could look at the innerHTML of the second div or look for text nodes
          >>>with values other than empty strings.
          >>>
          >>>But there is likely some other way related to however you are doing the
          >>>overflow.[/color]
          >>
          >>Sorry, I think I've not explained it correctly. Text will only go into
          >>the second DIV if it doesn't fit in the first. So my question is
          >>reworded to, given a DIV of a known size and how can I know how much
          >>text will fit in it before it overflows?
          >>
          >>I'm happy enough to count lines and words per line but I don't know
          >>where the overflow occurs.[/color]
          >
          >
          > You can't, unless you hardcode the font size, *and* use a mono-spaced font
          > (i.e. Courier). And then only if you examine the exact pixel height and
          > width for that particular size up front.
          >
          > Can't you solve this another way instead? Autoscroll? Grow the div
          > vertically?
          >
          > This is a problem generated by a UI design requirement, so what about
          > looking into the design?[/color]

          I understand but I was kind of hoping that as a DIV set to overflow:auto
          "knows" when its contents overflow that there might be a way for
          javascript to detect it.

          Andrew Poulos

          Comment

          • Martin Honnen

            #6
            Re: Spill overflow text to another DIV



            Andrew Poulos wrote:

            [color=blue]
            > I understand but I was kind of hoping that as a DIV set to overflow:auto
            > "knows" when its contents overflow that there might be a way for
            > javascript to detect it.[/color]

            I would think that
            divElement.scro llHeight
            is larger than
            divElement.offs etHeight
            if content overflows so detecting that content overflows should be
            possible. But identifying and moving the contents that overflows is
            another story.


            --

            Martin Honnen

            Comment

            • Danny@Kendal

              #7
              Re: Spill overflow text to another DIV

              "Andrew Poulos" <ap_prog@hotmai l.com> wrote in message
              news:42f6f76c$0 $16467$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...[color=blue]
              > Say I have a text area. When the user clicks a button the entered text
              > displays in a DIV. If there's too much text to fit in that DIV then the
              > overflow text (the text that doesn't fit in the first DIV) displays in
              > an adjacent DIV.
              >
              > Is there a way to know if there's "overflowin g" text and, if there is,
              > if there a way to know what that text is?[/color]

              Not really, at least none that I've heard of, but there are various ways to
              hack it.

              One way would be to have two or more copies of the text inside clipping
              elements.
              The 1st element has the text positioned at the top, the 2nd has the text
              positioned above the top of the clipping element by the same value as the
              height of the 1st element.

              I've used 'px' for the size and position rather than 'em' so you can change
              the font size and see the apparent reflowing of text into the 2nd box. It's
              a quick lash-up but seems to work.

              eg:
              <!-- FIRST BOX -->
              <div style="overflow :hidden; width:200px; height:400px; position:absolu te;
              top:0; left:0">
              <p style="position :relative; top:0"> --- placeholder text --- </p>
              </div>

              <!-- OVERFLOW BOX -->
              <div style="overflow :hidden; width:200px; height:400px; position:absolu te;
              top:0; left:200px">
              <p style="position :relative; top:-400px"> --- placeholder text --- </p>
              </div>


              Comment

              Working...