Align left and right on a single line

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Craig Thomson

    Align left and right on a single line


    How can I have some text aligned to the left of the page and some more
    text aligned to the right using only CSS without a table?

    SPAN doesn't have any alignment, and there is only a single DIV block
    per line, and so only one alignment.

    TIA

    Craig
  • Barry Pearson

    #2
    Re: Align left and right on a single line

    Craig Thomson wrote:[color=blue]
    > How can I have some text aligned to the left of the page and some more
    > text aligned to the right using only CSS without a table?
    >
    > SPAN doesn't have any alignment, and there is only a single DIV block
    > per line, and so only one alignment.[/color]

    The following is a crude example of what can be done. But it obviously won't
    work right at narrow viewport widths, because the bits of text overlap. You
    need to work out what you want to happen under various circumstances, because
    that will tell you which of many options to use.

    HTML:

    <div class="line">
    <span class="left">Le ft hand text</span><span class="centre"> Centre text
    </span><span class="right">R ight hand text </span>
    </div>

    CSS:

    span.left {
    position: absolute;
    left: 0;
    }
    span.right {
    position: absolute;
    right: 0;
    }
    div.line {
    position: relative;
    text-align: center;
    width: 100%;
    }

    --
    Barry Pearson


    This site provides information & analysis of child support & the Child Support Agency in the UK, mainly for lobbyists, politicians, academics & media.



    Comment

    • Barry Pearson

      #3
      Re: Align left and right on a single line

      Craig Thomson wrote:[color=blue]
      > How can I have some text aligned to the left of the page and some more
      > text aligned to the right using only CSS without a table?
      >
      > SPAN doesn't have any alignment, and there is only a single DIV block
      > per line, and so only one alignment.[/color]

      The following is a crude example of what can be done. But it obviously won't
      work right at narrow viewport widths, because the bits of text overlap. You
      need to work out what you want to happen under various circumstances, because
      that will tell you which of many options to use.

      HTML:

      <div class="line">
      <span class="left">Le ft hand text</span><span class="centre"> Centre text
      </span><span class="right">R ight hand text </span>
      </div>

      CSS:

      span.left {
      position: absolute;
      left: 0;
      }
      span.right {
      position: absolute;
      right: 0;
      }
      div.line {
      position: relative;
      text-align: center;
      width: 100%;
      }

      --
      Barry Pearson


      This site provides information & analysis of child support & the Child Support Agency in the UK, mainly for lobbyists, politicians, academics & media.



      Comment

      • Spartanicus

        #4
        Re: Align left and right on a single line

        Craig Thomson <craig@spam.fre e> wrote:
        [color=blue]
        >How can I have some text aligned to the left of the page and some more
        >text aligned to the right using only CSS without a table?[/color]

        By using a css table and a hack to supply poor old IE with a float
        replacement.

        --
        Spartanicus

        Comment

        • Spartanicus

          #5
          Re: Align left and right on a single line

          Craig Thomson <craig@spam.fre e> wrote:
          [color=blue]
          >How can I have some text aligned to the left of the page and some more
          >text aligned to the right using only CSS without a table?[/color]

          By using a css table and a hack to supply poor old IE with a float
          replacement.

          --
          Spartanicus

          Comment

          • Spartanicus

            #6
            Re: Align left and right on a single line

            Spartanicus <me@privacy.net > wrote:
            [color=blue][color=green]
            >>How can I have some text aligned to the left of the page and some more
            >>text aligned to the right using only CSS without a table?[/color]
            >
            >By using a css table and a hack to supply poor old IE with a float
            >replacement.[/color]

            Example:


            --
            Spartanicus

            Comment

            • Spartanicus

              #7
              Re: Align left and right on a single line

              Spartanicus <me@privacy.net > wrote:
              [color=blue][color=green]
              >>How can I have some text aligned to the left of the page and some more
              >>text aligned to the right using only CSS without a table?[/color]
              >
              >By using a css table and a hack to supply poor old IE with a float
              >replacement.[/color]

              Example:


              --
              Spartanicus

              Comment

              Working...