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

Trouble Horizontally Aligning Two Elements inside Div

I am trying to add a second element, a text input, next to an existing button, and have them be side-by-side. The button originally occupied most of the space. Now I just want each element to take up roughly 50% of the width of the space available and be next to each other.

Code + image below. I added the parent div and the sponsored_post_bid element to try and achieve side-by-side.

main .add-post-modal .add-post-categories .extra-category {
  float: left;
}

main .add-post-modal .add-post-categories .extra-category input {
  width: 0px !important;
  height: 0px !important;
  overflow: hidden;
  -moz-appearance: none;
}

main .sponsored_post_bid {
  width: 48%;
  height: 100%;
  float: right;
}
<div style="margin: auto; width: 100%;">
  <div class="extra-category">
    <input type="radio" name="category" id="cat9" value="Sponsored" />
    <label for="cat9">Sponsored Post</label>
  </div>
  <input class="sponsored_post_bid" value="Bid $$$" />
  <div>

enter image description here

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

Unfortunately they are on different lines. If I try for .extra-category to have width: 48% I get the following:

enter image description here

Which is also not the intended goal.

>Solution :

I added float to your input and a class called new I added to the label. I wasn’t sure if you wanted to use flex-box or not so I figured going the old fashion route was okay. However, it seems like perhaps in your screenshots the width is not 100% of body which may alter this result. Let us know if that’s the case.

main .add-post-modal .add-post-categories .extra-category {
  float: left;
}

main .add-post-modal .add-post-categories .extra-category input {
  width: 0px !important;
  height: 0px !important;
  overflow: hidden;
  -moz-appearance: none;
}

main .sponsored_post_bid {
  width: 48%;
  height: 100%;
  float: right;
}

input[type=radio] {
  float: left;
}
label.new {
  float: left;
  margin-right: 10px;
}
<div style="margin: auto; width: 100%;">
<div class="extra-category">
   <input type="radio" name="category" id="cat9" value="Sponsored"/>
   <label for="cat9" class="new">Sponsored Post</label>
</div>
<input class="sponsored_post_bid" value="Bid $$$" />
<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