'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: blue;
}
<div class="myform">
<cfform action="landing.cfml" method="post">
<div class="checkboxes">
<cfoutput query="animals">
<input type="checkbox" name="myDataList" value="#animals#" <cfif listFind(selectedAnimals, animalid)></cfif>> #animalname# <br />
</cfoutput>
</div>
<cfinput type="Submit" name="SubmitForm" value="Submit">
</cfform>
</div>
I coloured the background of the checkboxes blue 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.
Everything I have read says to use margin: auto;
and it should position the div in the centre horizontally.
Solution 1:[1]
You can try using display: flex;
on the parent with justify-content: center;
.myform {
position: relative;
right: 0; /* Fill in a positive value here, to push to left */
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |