Home > database >  <div> center of screen not text of element
<div> center of screen not text of element

Time:03-31

I want elements of div to center of the screen but not text inside it. For example Sample size (n) should be aligned left in the code below.

.center-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}
<div class='center-screen'>
<label class='input2' for='pop'><b>Population proportion (p)</b></label>
<input class='input2' type='number' step='0.01' id='pop' value='0.43'/>
<label class='input2' for='samplesize'><b>Sample size (n)</b></label>
<input class='input2' type='number' id='samplesize' value='40'/>
<input class='input2' type='button' value='Calculate' />
</div>

CodePudding user response:

You can wrapped with a div flex container. Then you align only the child container. Afterwards remove the text-align form the child container.

.container {
  display: flex;
  justify-content: center;
}
.center-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  
}
<div >
  <div class='center-screen'>
    <label class='input2' for='pop'><b>Population proportion (p)</b></label>
    <input class='input2' type='number' step='0.01' id='pop' value='0.43'/>
    <label class='input2' for='samplesize'><b>Sample size (n)</b></label>
    <input class='input2' type='number' id='samplesize' value='40'/>
    <input class='input2' type='button' value='Calculate' />
  </div>
</div>

  • Related