Positioning of appended nodes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    Positioning of appended nodes

    I would like for the two child nodes in the code below to appear side by side. But in all my attempts they are stacked on top of each other.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
    
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    // Create a div to hold the control.
    var controlDiv = document.createElement('DIV');
    
    // Set CSS styles for the DIV containing the control
    // Setting padding to 5 px will offset the control
    // from the edge of the map
    controlDiv.style.padding = '5px';
    controlDiv.style.borderStyle = 'ridge';
    controlDiv.style.width = '500px';
    
    // Set CSS for the control border
    var controlMC = document.createElement('DIV');
    controlMC.style.position = 'relative';
    controlMC.style.width = '20%';
    controlMC.style.backgroundColor = 'white';
    controlMC.style.borderStyle = 'solid';
    controlMC.style.borderWidth = '2px';
    controlMC.style.cursor = 'pointer';
    controlMC.style.textAlign = 'center';
    controlMC.title = 'Click to set the map to Home';
    controlDiv.appendChild(controlMC);
    
    // Set CSS for the control interior
    var controlText = document.createElement('DIV');
    controlText.style.fontFamily = 'Arial,sans-serif';
    controlText.style.fontSize = '12px';
    controlText.style.paddingLeft = '4px';
    controlText.style.paddingRight = '4px';
    controlText.innerHTML = 'Center';
    controlMC.appendChild(controlText);
    
    //////////////////////////////////////////////////////////////
    // Set CSS for the control border
    var controlUI = document.createElement('DIV');
    controlUI.style.position = 'relative';
    controlUI.style.width = '20%';
    controlUI.style.backgroundColor = 'white';
    controlUI.style.borderStyle = 'solid';
    controlUI.style.borderWidth = '2px';
    controlUI.style.cursor = 'pointer';
    controlUI.style.textAlign = 'center';
    controlUI.title = 'Click to set the map to RoadMap';
    controlDiv.appendChild(controlUI);
    
    // Set CSS for the control interior
    var controlText = document.createElement('DIV');
    controlText.style.fontFamily = 'Arial,sans-serif';
    controlText.style.fontSize = '12px';
    controlText.style.paddingLeft = '4px';
    controlText.style.paddingRight = '4px';
    controlText.innerHTML = 'Map';
    controlUI.appendChild(controlText);
    
    function myload() {
    document.getElementById('myDiv').appendChild(controlDiv); 
    }
    //-->
    </SCRIPT> 
    </HEAD>
     <BODY onload="myload()">
    <div id="myDiv">
    </div>
     </BODY>
    </HTML>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    <div>s always appear below each other unless you position them absolutely or cast them to inline elements (both is a CSS setting).

    Comment

    • Claus Mygind
      Contributor
      • Mar 2008
      • 571

      #3
      Originally posted by Dormilich
      <div>s always appear below each other unless you position them absolutely or cast them to inline elements (both is a CSS setting).
      Can you give a simple example of "casting inline"?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Code:
        display: inline;
        mind that an inline element behaves differently from a block element in the text flow.

        Comment

        • Claus Mygind
          Contributor
          • Mar 2008
          • 571

          #5
          Originally posted by Dormilich
          Code:
          display: inline;
          mind that an inline element behaves differently from a block element in the text flow.
          Just what I needed thanks. They are just buttons I want to add to the page.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            why not using <button> or <span>, they’re already inline elements.

            Comment

            • Claus Mygind
              Contributor
              • Mar 2008
              • 571

              #7
              Originally posted by Dormilich
              why not using <button> or <span>, they’re already inline elements.
              I am playing around with google maps and following one of their examples for creating custom controls.

              You example worked great in my html editor "editPlus" but not when I ran the code in FireFox. I suppose that is what you meant by "text behaves differently"?

              Comment

              Working...