Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Centering span with text in div with button in it

My code looks like this:

<div style="text-align:center;">
  <button style="float:left;" onclick="openNav()">
            Osoby
        </button>
  <span>
            Antoni Jankowski
        </span>
</div>

Unfortunately text-align:center makes it center only in the remaining space not taken by the button so its position a little too far to the right. Is it possible to just make it ignore a button? Or are there any other solutions?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

**Try this**
<h1>Try this</h1>
    <div style="display:flex; align-items: flex-start;">
      <button onclick="openNav()" style="flex-shrink:0; margin-right:6px">
        This is your Button
      </button>
      <span style="flex-grow: 1; display: flex; justify-content: center;">
        Center Text in span tag
      </span>
    </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading