How to text-align an svg element inside a div












0














I would just like to know why text-align: right is not moving the svg to the right? It is moving the button to the right. I need the svg to sit above the button on the right.






svg {
display: block
}

polygon {
fill: red;
}

.main {
width: 100%;
background-color: green;
text-align: right;
}

<div class="main">
<svg height="20" width="20">
<polygon points="10,0 20,20 0,20"/>
</svg>
<button>Test</button>
</div>












share|improve this question





























    0














    I would just like to know why text-align: right is not moving the svg to the right? It is moving the button to the right. I need the svg to sit above the button on the right.






    svg {
    display: block
    }

    polygon {
    fill: red;
    }

    .main {
    width: 100%;
    background-color: green;
    text-align: right;
    }

    <div class="main">
    <svg height="20" width="20">
    <polygon points="10,0 20,20 0,20"/>
    </svg>
    <button>Test</button>
    </div>












    share|improve this question



























      0












      0








      0







      I would just like to know why text-align: right is not moving the svg to the right? It is moving the button to the right. I need the svg to sit above the button on the right.






      svg {
      display: block
      }

      polygon {
      fill: red;
      }

      .main {
      width: 100%;
      background-color: green;
      text-align: right;
      }

      <div class="main">
      <svg height="20" width="20">
      <polygon points="10,0 20,20 0,20"/>
      </svg>
      <button>Test</button>
      </div>












      share|improve this question















      I would just like to know why text-align: right is not moving the svg to the right? It is moving the button to the right. I need the svg to sit above the button on the right.






      svg {
      display: block
      }

      polygon {
      fill: red;
      }

      .main {
      width: 100%;
      background-color: green;
      text-align: right;
      }

      <div class="main">
      <svg height="20" width="20">
      <polygon points="10,0 20,20 0,20"/>
      </svg>
      <button>Test</button>
      </div>








      svg {
      display: block
      }

      polygon {
      fill: red;
      }

      .main {
      width: 100%;
      background-color: green;
      text-align: right;
      }

      <div class="main">
      <svg height="20" width="20">
      <polygon points="10,0 20,20 0,20"/>
      </svg>
      <button>Test</button>
      </div>





      svg {
      display: block
      }

      polygon {
      fill: red;
      }

      .main {
      width: 100%;
      background-color: green;
      text-align: right;
      }

      <div class="main">
      <svg height="20" width="20">
      <polygon points="10,0 20,20 0,20"/>
      </svg>
      <button>Test</button>
      </div>






      html css






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 12:35

























      asked Nov 14 '18 at 12:19









      Freddy Bonda

      11110




      11110
























          4 Answers
          4






          active

          oldest

          votes


















          1














          It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.






          svg {
          display: inline-block
          }

          polygon {
          fill: red;
          }

          .main {
          width: 100%;
          background-color: green;
          text-align: right;
          }

          <div class="main">
          <svg height="20" width="20">
          <polygon points="10,0 20,20 0,20"/>
          </svg>
          <div>
          <button>Test</button>
          </div>
          </div>





          Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.






          share|improve this answer























          • I need the arrow to be ABOVE the button on the right side hey
            – Freddy Bonda
            Nov 14 '18 at 12:30










          • Edited the answer.
            – Eric
            Nov 14 '18 at 12:38



















          0














          svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;



          try:



          float: right;


          on the svg.






          share|improve this answer





















          • I need the arrow to be ABOVE the button on the right side hey
            – Freddy Bonda
            Nov 14 '18 at 12:32



















          0














          As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right; which means that it'll be positioned to the right side of the page.



          Everything in the div will just position under each other.






          .right-section { float:right; }

          svg { margin-left:10px; display:block; }

          polygon {
          fill: red;
          }

          .main {
          width: 100%;
          background-color: green;
          text-align: right;
          }

          <div class="main">
          <div class="right-section">
          <svg height="20" width="20">
          <polygon points="10,0 20,20 0,20"/>
          </svg>
          <button>Test</button>
          </div>
          </div>





          I have also added margin-left:10px; to the svg { } to make sure the arrow is in the center of the button.






          share|improve this answer































            0














            @Eric has explained you well why SVG is not moving to the right.
            Another solution to resolve your problem is to use flexbox.



            /*svg {
            display: block
            }*/

            polygon {
            fill: red;
            }

            .main {
            width: 100%;
            background-color: green;

            /* I added only these rules */
            display: flex;
            flex-direction: column;
            align-items: flex-end;
            }





            /*svg {
            display: block
            }*/

            polygon {
            fill: red;
            }

            .main {
            width: 100%;
            background-color: green;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
            }

            <div class="main">
            <svg height="20" width="20">
            <polygon points="10,0 20,20 0,20"/>
            </svg>
            <button>Test</button>
            </div>








            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300114%2fhow-to-text-align-an-svg-element-inside-a-div%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.






              svg {
              display: inline-block
              }

              polygon {
              fill: red;
              }

              .main {
              width: 100%;
              background-color: green;
              text-align: right;
              }

              <div class="main">
              <svg height="20" width="20">
              <polygon points="10,0 20,20 0,20"/>
              </svg>
              <div>
              <button>Test</button>
              </div>
              </div>





              Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.






              share|improve this answer























              • I need the arrow to be ABOVE the button on the right side hey
                – Freddy Bonda
                Nov 14 '18 at 12:30










              • Edited the answer.
                – Eric
                Nov 14 '18 at 12:38
















              1














              It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.






              svg {
              display: inline-block
              }

              polygon {
              fill: red;
              }

              .main {
              width: 100%;
              background-color: green;
              text-align: right;
              }

              <div class="main">
              <svg height="20" width="20">
              <polygon points="10,0 20,20 0,20"/>
              </svg>
              <div>
              <button>Test</button>
              </div>
              </div>





              Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.






              share|improve this answer























              • I need the arrow to be ABOVE the button on the right side hey
                – Freddy Bonda
                Nov 14 '18 at 12:30










              • Edited the answer.
                – Eric
                Nov 14 '18 at 12:38














              1












              1








              1






              It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.






              svg {
              display: inline-block
              }

              polygon {
              fill: red;
              }

              .main {
              width: 100%;
              background-color: green;
              text-align: right;
              }

              <div class="main">
              <svg height="20" width="20">
              <polygon points="10,0 20,20 0,20"/>
              </svg>
              <div>
              <button>Test</button>
              </div>
              </div>





              Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.






              share|improve this answer














              It's because you have the SVG as a block level element. Block's don't text-align. You could float it right, or just simply give it display: inline-block. See below.






              svg {
              display: inline-block
              }

              polygon {
              fill: red;
              }

              .main {
              width: 100%;
              background-color: green;
              text-align: right;
              }

              <div class="main">
              <svg height="20" width="20">
              <polygon points="10,0 20,20 0,20"/>
              </svg>
              <div>
              <button>Test</button>
              </div>
              </div>





              Edit: You can wrap the button in a div (a block level element). Alternatively, you can just put in a line-break (br) in between the two elements.






              svg {
              display: inline-block
              }

              polygon {
              fill: red;
              }

              .main {
              width: 100%;
              background-color: green;
              text-align: right;
              }

              <div class="main">
              <svg height="20" width="20">
              <polygon points="10,0 20,20 0,20"/>
              </svg>
              <div>
              <button>Test</button>
              </div>
              </div>





              svg {
              display: inline-block
              }

              polygon {
              fill: red;
              }

              .main {
              width: 100%;
              background-color: green;
              text-align: right;
              }

              <div class="main">
              <svg height="20" width="20">
              <polygon points="10,0 20,20 0,20"/>
              </svg>
              <div>
              <button>Test</button>
              </div>
              </div>






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 14 '18 at 12:36

























              answered Nov 14 '18 at 12:24









              Eric

              1866




              1866












              • I need the arrow to be ABOVE the button on the right side hey
                – Freddy Bonda
                Nov 14 '18 at 12:30










              • Edited the answer.
                – Eric
                Nov 14 '18 at 12:38


















              • I need the arrow to be ABOVE the button on the right side hey
                – Freddy Bonda
                Nov 14 '18 at 12:30










              • Edited the answer.
                – Eric
                Nov 14 '18 at 12:38
















              I need the arrow to be ABOVE the button on the right side hey
              – Freddy Bonda
              Nov 14 '18 at 12:30




              I need the arrow to be ABOVE the button on the right side hey
              – Freddy Bonda
              Nov 14 '18 at 12:30












              Edited the answer.
              – Eric
              Nov 14 '18 at 12:38




              Edited the answer.
              – Eric
              Nov 14 '18 at 12:38













              0














              svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;



              try:



              float: right;


              on the svg.






              share|improve this answer





















              • I need the arrow to be ABOVE the button on the right side hey
                – Freddy Bonda
                Nov 14 '18 at 12:32
















              0














              svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;



              try:



              float: right;


              on the svg.






              share|improve this answer





















              • I need the arrow to be ABOVE the button on the right side hey
                – Freddy Bonda
                Nov 14 '18 at 12:32














              0












              0








              0






              svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;



              try:



              float: right;


              on the svg.






              share|improve this answer












              svg is not moving right as you are aligning any text as right, not svg as it is set as display: Block instead of display: inline-block;



              try:



              float: right;


              on the svg.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 14 '18 at 12:26









              Boywithanafro

              13




              13












              • I need the arrow to be ABOVE the button on the right side hey
                – Freddy Bonda
                Nov 14 '18 at 12:32


















              • I need the arrow to be ABOVE the button on the right side hey
                – Freddy Bonda
                Nov 14 '18 at 12:32
















              I need the arrow to be ABOVE the button on the right side hey
              – Freddy Bonda
              Nov 14 '18 at 12:32




              I need the arrow to be ABOVE the button on the right side hey
              – Freddy Bonda
              Nov 14 '18 at 12:32











              0














              As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right; which means that it'll be positioned to the right side of the page.



              Everything in the div will just position under each other.






              .right-section { float:right; }

              svg { margin-left:10px; display:block; }

              polygon {
              fill: red;
              }

              .main {
              width: 100%;
              background-color: green;
              text-align: right;
              }

              <div class="main">
              <div class="right-section">
              <svg height="20" width="20">
              <polygon points="10,0 20,20 0,20"/>
              </svg>
              <button>Test</button>
              </div>
              </div>





              I have also added margin-left:10px; to the svg { } to make sure the arrow is in the center of the button.






              share|improve this answer




























                0














                As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right; which means that it'll be positioned to the right side of the page.



                Everything in the div will just position under each other.






                .right-section { float:right; }

                svg { margin-left:10px; display:block; }

                polygon {
                fill: red;
                }

                .main {
                width: 100%;
                background-color: green;
                text-align: right;
                }

                <div class="main">
                <div class="right-section">
                <svg height="20" width="20">
                <polygon points="10,0 20,20 0,20"/>
                </svg>
                <button>Test</button>
                </div>
                </div>





                I have also added margin-left:10px; to the svg { } to make sure the arrow is in the center of the button.






                share|improve this answer


























                  0












                  0








                  0






                  As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right; which means that it'll be positioned to the right side of the page.



                  Everything in the div will just position under each other.






                  .right-section { float:right; }

                  svg { margin-left:10px; display:block; }

                  polygon {
                  fill: red;
                  }

                  .main {
                  width: 100%;
                  background-color: green;
                  text-align: right;
                  }

                  <div class="main">
                  <div class="right-section">
                  <svg height="20" width="20">
                  <polygon points="10,0 20,20 0,20"/>
                  </svg>
                  <button>Test</button>
                  </div>
                  </div>





                  I have also added margin-left:10px; to the svg { } to make sure the arrow is in the center of the button.






                  share|improve this answer














                  As you have editted your post and you want both objects on the right side above eachother I have added one extra div arround it. This div will float:right; which means that it'll be positioned to the right side of the page.



                  Everything in the div will just position under each other.






                  .right-section { float:right; }

                  svg { margin-left:10px; display:block; }

                  polygon {
                  fill: red;
                  }

                  .main {
                  width: 100%;
                  background-color: green;
                  text-align: right;
                  }

                  <div class="main">
                  <div class="right-section">
                  <svg height="20" width="20">
                  <polygon points="10,0 20,20 0,20"/>
                  </svg>
                  <button>Test</button>
                  </div>
                  </div>





                  I have also added margin-left:10px; to the svg { } to make sure the arrow is in the center of the button.






                  .right-section { float:right; }

                  svg { margin-left:10px; display:block; }

                  polygon {
                  fill: red;
                  }

                  .main {
                  width: 100%;
                  background-color: green;
                  text-align: right;
                  }

                  <div class="main">
                  <div class="right-section">
                  <svg height="20" width="20">
                  <polygon points="10,0 20,20 0,20"/>
                  </svg>
                  <button>Test</button>
                  </div>
                  </div>





                  .right-section { float:right; }

                  svg { margin-left:10px; display:block; }

                  polygon {
                  fill: red;
                  }

                  .main {
                  width: 100%;
                  background-color: green;
                  text-align: right;
                  }

                  <div class="main">
                  <div class="right-section">
                  <svg height="20" width="20">
                  <polygon points="10,0 20,20 0,20"/>
                  </svg>
                  <button>Test</button>
                  </div>
                  </div>






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 14 '18 at 12:57

























                  answered Nov 14 '18 at 12:39









                  JeroenE

                  509318




                  509318























                      0














                      @Eric has explained you well why SVG is not moving to the right.
                      Another solution to resolve your problem is to use flexbox.



                      /*svg {
                      display: block
                      }*/

                      polygon {
                      fill: red;
                      }

                      .main {
                      width: 100%;
                      background-color: green;

                      /* I added only these rules */
                      display: flex;
                      flex-direction: column;
                      align-items: flex-end;
                      }





                      /*svg {
                      display: block
                      }*/

                      polygon {
                      fill: red;
                      }

                      .main {
                      width: 100%;
                      background-color: green;
                      display: flex;
                      flex-direction: column;
                      align-items: flex-end;
                      }

                      <div class="main">
                      <svg height="20" width="20">
                      <polygon points="10,0 20,20 0,20"/>
                      </svg>
                      <button>Test</button>
                      </div>








                      share|improve this answer


























                        0














                        @Eric has explained you well why SVG is not moving to the right.
                        Another solution to resolve your problem is to use flexbox.



                        /*svg {
                        display: block
                        }*/

                        polygon {
                        fill: red;
                        }

                        .main {
                        width: 100%;
                        background-color: green;

                        /* I added only these rules */
                        display: flex;
                        flex-direction: column;
                        align-items: flex-end;
                        }





                        /*svg {
                        display: block
                        }*/

                        polygon {
                        fill: red;
                        }

                        .main {
                        width: 100%;
                        background-color: green;
                        display: flex;
                        flex-direction: column;
                        align-items: flex-end;
                        }

                        <div class="main">
                        <svg height="20" width="20">
                        <polygon points="10,0 20,20 0,20"/>
                        </svg>
                        <button>Test</button>
                        </div>








                        share|improve this answer
























                          0












                          0








                          0






                          @Eric has explained you well why SVG is not moving to the right.
                          Another solution to resolve your problem is to use flexbox.



                          /*svg {
                          display: block
                          }*/

                          polygon {
                          fill: red;
                          }

                          .main {
                          width: 100%;
                          background-color: green;

                          /* I added only these rules */
                          display: flex;
                          flex-direction: column;
                          align-items: flex-end;
                          }





                          /*svg {
                          display: block
                          }*/

                          polygon {
                          fill: red;
                          }

                          .main {
                          width: 100%;
                          background-color: green;
                          display: flex;
                          flex-direction: column;
                          align-items: flex-end;
                          }

                          <div class="main">
                          <svg height="20" width="20">
                          <polygon points="10,0 20,20 0,20"/>
                          </svg>
                          <button>Test</button>
                          </div>








                          share|improve this answer












                          @Eric has explained you well why SVG is not moving to the right.
                          Another solution to resolve your problem is to use flexbox.



                          /*svg {
                          display: block
                          }*/

                          polygon {
                          fill: red;
                          }

                          .main {
                          width: 100%;
                          background-color: green;

                          /* I added only these rules */
                          display: flex;
                          flex-direction: column;
                          align-items: flex-end;
                          }





                          /*svg {
                          display: block
                          }*/

                          polygon {
                          fill: red;
                          }

                          .main {
                          width: 100%;
                          background-color: green;
                          display: flex;
                          flex-direction: column;
                          align-items: flex-end;
                          }

                          <div class="main">
                          <svg height="20" width="20">
                          <polygon points="10,0 20,20 0,20"/>
                          </svg>
                          <button>Test</button>
                          </div>








                          /*svg {
                          display: block
                          }*/

                          polygon {
                          fill: red;
                          }

                          .main {
                          width: 100%;
                          background-color: green;
                          display: flex;
                          flex-direction: column;
                          align-items: flex-end;
                          }

                          <div class="main">
                          <svg height="20" width="20">
                          <polygon points="10,0 20,20 0,20"/>
                          </svg>
                          <button>Test</button>
                          </div>





                          /*svg {
                          display: block
                          }*/

                          polygon {
                          fill: red;
                          }

                          .main {
                          width: 100%;
                          background-color: green;
                          display: flex;
                          flex-direction: column;
                          align-items: flex-end;
                          }

                          <div class="main">
                          <svg height="20" width="20">
                          <polygon points="10,0 20,20 0,20"/>
                          </svg>
                          <button>Test</button>
                          </div>






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 14 '18 at 13:00









                          ReSedano

                          2,6502415




                          2,6502415






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300114%2fhow-to-text-align-an-svg-element-inside-a-div%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Guess what letter conforming each word

                              Port of Spain

                              Run scheduled task as local user group (not BUILTIN)