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

Center check boxes with css in cfml page

I’m having a really basic issue with css. It won’t let me centre my checkboxes in the middle of the page. The checkboxes are actually coldfusion, but should work the same.

myform.cfml:

.myform {
  position: relative;
  padding: 2rem;
  margin-left: auto;
  margin-right: auto;
}

.checkboxes {
  background-color: aquamarine;
}
<div class="myform">
  <cfform action="landing.cfml" method="post">

    <div class="checkboxes">
      <cfoutput query="toolIds">

        <input type="checkbox" name="myDataList" value="#toolid#" <cfif listFind(selectedTools, toolid)></cfif>> #toolname# <br />
      </cfoutput>
    </div>

    <cfinput type="Submit" name="SubmitForm" value="Submit">
  </cfform>
</div>

I coloured the background of the checkboxes aquamarine to see how it lies. It spreads across the whole screen. margin: auto; or margin: 0 auto; make no difference. It also doesn’t matter if the margin: auto; is in the .myform or the .checkboxes, it still doesn’t work. If I change it to margin-left: 30rem; margin-right:30rem; it moves, but I can’t have an absolute positioning.

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

Everything I have read says to use margin: auto; and it should position the div in the centre horizontally.

>Solution :

You can try using display: flex; on the parent with justify-content: center;

.myform {
  position: relative;
  padding: 2rem;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  justify-content: center;
}

.checkboxes {
  background-color: aquamarine;
}
<div class="myform">
  <cfform action="landing.cfml" method="post">

    <div class="checkboxes">
      <cfoutput query="toolIds">

        <input type="checkbox" name="myDataList" value="#toolid#" <cfif listFind(selectedTools, toolid)></cfif>> #toolname# <br />
      </cfoutput>
    </div>

    <cfinput type="Submit" name="SubmitForm" value="Submit">
  </cfform>
</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