Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

CSS element positioning

  1. Jan 4, 2017 #1
    Let's say we have 3 elements a,b, and c.
    a is right above b and b is right above c.
    Their heights change. What code would I use to position them since exact heights are not known and each elements must be relatively positioned to the previous element except "a" which is set at the top.
     
  2. jcsd
  3. Jan 4, 2017 #2
    What are these elements? Text, image, div, span etc? Your last comment is confusing.
     
  4. Jan 4, 2017 #3
    Mostly text or images either one, just anything that has a variable height and cannot be positioned manually.
     
  5. Jan 4, 2017 #4
    How do you want them positioned? I mean if you have 3 block divs they will naturally stack.
     
  6. Jan 4, 2017 #5
    The first one should be positioned out of place in a non static position, for example 20 pixels down and 20 pixels to the right.
     
  7. Jan 4, 2017 #6
    For box A use absolute positioning and the two other boxes use relative positioning to each other
     
  8. Jan 4, 2017 #7
    How would I get the value of another elements height?
     
  9. Jan 4, 2017 #8
    If using relative positioning why does it matter?
     
  10. Jan 4, 2017 #9
    The heights would change so you could not use a specific number
     
  11. Jan 4, 2017 #10
    Do you want overlapping elements? The specific number will be relative to the parent element.
     
  12. Jan 4, 2017 #11
    No overlapping, I need them to be right up against each other. Just seems like there's an easier way instead of having to manually put in values
     
  13. Jan 4, 2017 #12
    Side to side or top to bottom? You don't need any positioning, the divs boxes will stack if set to block automatically or set a float for side to side.
     
  14. Jan 4, 2017 #13
    Thanks, I'll try more coding and see if it works
     
  15. Jan 4, 2017 #14
    It's still not working.
    HTML:
    .container {
      position: relative;
    width: 500px;
      margin: 20px auto;
      padding: 500px;
      border: solid grey 10px;
      -webkit-box-sizing: border-box;
         -moz-box-sizing: border-box;
              box-sizing: border-box;
    }

    #content {
    position: absolute;
    display: block;
    margin: 0 auto;
      padding: 50px;
      border: solid blue 10px;
    }


    <div class="container">
        <p id="content" style="font-size: 48pt; display:block; width:600px; word-wrap: break-word;">hellooooooooooooooooooooooo</p>
        <p id="content" style="font-size: 48pt; display:block;" >hello again</p>
    </div>
     

    Attached Files:

    Last edited by a moderator: Jan 4, 2017
  16. Jan 4, 2017 #15
    Several problems, but I need to leave for a few hours. I'll be back to work it out unless others chip in.
     
  17. Jan 4, 2017 #16
    Sure no problem, thanks for your help either way!
     
  18. Jan 4, 2017 #17
    Is this what you want?

    HTML:
    <!DOCTYPE html>
    <html>
    <head>
    <style>


    .container2 {
    display:block;
    overflow:auto;
    border: solid grey 10px;
    }

    #content {
    width:50%;
    display: block;
    float:right;
    border: solid blue 4px;
    box-sizing: border-box;
    }

    #content2 {
    width:50%;
    display: block;
    float:left;
    border: solid blue 4px;
    box-sizing: border-box;
    }
    </style>
    </head>
    <body>


    <div class="container2">
      <div id="content">hellooooooooooooooooooooooo</div>
      <div id="content2">hello again</div>
    </div>


    </body>
    </html>
     
  19. Jan 6, 2017 #18
    Thanks that seems to work!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: CSS element positioning
  1. Inline css (Replies: 1)

Loading...