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

Why is my button going to the next line in my layout?

Trying to have it to where these elements appear on the same exact line. So the header of "Header" will be on the left and the button to submit will be on the right.

<div>
  <div width="float: left; width: 50%">
    <h4> Header </h4>
  </div>
  
  <div style="float: right; width: 50%">
    <button> Export to Excel </button>
  </div>
</div>

enter image description here

I have used similar setup in the past and it worked. Any ideas?

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 :

To align two items next to eachother you need to make sure you assign them both a 50% width and you can get them both on the same line using align: left. This method works, but I suggest looking into flexbox for positioning, this makes it much easier.

.wrapper {
  width: 50%;
  float: left;
}
<div>
    <div class="wrapper">
      <h4>
        Header
      </h4>
    </div>
    <div class="wrapper">
        <button
        cButton
        (click)="exportExcel(1)"
        >
        Export to Excel
        </button>
    </div>
  </div>

Flexbox:

.parent {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  width: 100%;
}

.wrapper {
  flex-direction: column;
  flex: 1;
}

.wrapper button {
  width: 125px;
}
<div class="parent">
    <div class="wrapper">
      <h4>
        Header
      </h4>
    </div>
    <div class="wrapper">
        <button
        cButton
        (click)="exportExcel(1)"
        >
        Export to Excel
        </button>
    </div>
  </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