Search code examples
htmlcsswebkit

HTML -webkit-center issue


I wrote some code and I realize there is an issue. When I use -webkit-center and write something in textbox, all items going to the right. I tried other -webkit align settings but there are no problem, just -webkit-center. I researched about it but I can't find anything. Can anyone explain why?

Here is the code you can also try.

<div id="mainDiv" style="text-align: -webkit-center; display: inline-grid; margin-left: 40%;border-style:double;">
<span>HEADER</span>
<input name="header" type="text" id="header" style="margin: 20px;width:173px;">
<span>CONTENT</span>
<input name="content" type="text" id="content" style="margin: 20px;height:50px;width:350px;">
<span>HEADER COLOR</span>
<input name="headColor" type="text" id="headColor" style="margin: 20px;width:173px;">
<span>CONTENT COLOR</span>
<input name="contColor" type="text" id="contColor" style="margin: 20px;width:173px;">
<input type="submit" name="button" value="SUBMIT" id="button" style="height: 30px;width:173px;margin:20px;">
</div>


Solution

  • -the webkit-center property works differently than the normal text-center property. Instead of aligning the content, block tries to sort the elements.

    I got the same look by doing different styling. You can control it. for each input, you will need to type media query to be responsive because you give constant width values.

    #mainDiv {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    <div id="mainDiv" style=" text-align: center;width: 40%; margin:auto;border-style:double;">
      <span>HEADER</span>
      <input name="header" type="text" id="header" style="margin: 20px;width:173px;">
      <span>CONTENT</span>
      <input name="content" type="text" id="content" style="margin: 20px;height:50px;width:350px;">
      <span>HEADER COLOR</span>
      <input name="headColor" type="text" id="headColor" style="margin: 20px;width:173px;">
      <span>CONTENT COLOR</span>
      <input name="contColor" type="text" id="contColor" style="margin: 20px;width:173px;">
      <input type="submit" name="button" value="SUBMIT" id="button" style="height: 30px;width:173px;margin:20px auto;">
    </div>