如何在表格中居中图像?

how to center an image inside form?

你好,我想在表格中居中放置一张图片
我用 position: absolute 把它放在中间但没用

 position: absolute;
  left: 50%;
  top: 50%;

像这样:

到目前为止我已经尝试过这段代码:

body {
  top: 0;
  padding: 0;
  left: 0;
  margin: 0;
  height: 100vh;
  width: 100%;
  font-family: Arial;
  position: relative;
  background: linear-gradient(48deg, #1f3347 50%, #2c4050 50%);
}
.from_body {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: 390px;
  width: 400px;
  border-radius: 10px;
  border-top-left-radius: 50%;
  border-bottom-right-radius: 50%;
  border: 1px solid #2980b9;
}
.from_body img {
  height: 120px;
  width: 120px;
  position: absolute;
  left: 33%;
  margin-top: -67px;
}
.from_body .text {
  font-size: 30px;
  font-weight: 600;
  color: white;
  margin-left: 120px;
  margin-top: -5px;
  border-bottom: 2px solid;
  border-radius: 3px;
  width: 160px;
}
<body>
    <div class="form_body">
        <img
            src="https://pngset.com/images/google-contacts-icon-google-contacts-icon-disk-dvd-symbol-number-transparent-png-2734641.png">
        <p class="text">User login</p>
    </div>
</body>

我是初学者,如果有任何帮助,我将不胜感激!

OP 中的 PNG 看起来不像是透明的,所以我得到了一个透明的。正文具有 flexbox 属性,<div>s 被替换为 <figure><figcaption> 用于语义。由于 object-fit: contain.

<img> 将符合 <figure> 的尺寸

body {
  display: flex;
  flex-flow: column nowrap;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  width: 100%;
  font: 3ch/1 'Segoe UI';
  background: linear-gradient(48deg, #1f3347 50%, #2c4050 50%);
}

figure {
  width: max-content;
  margin: 0 auto;
}

figcaption {
  text-align: center;
  color: #fff
}

img {
  object-fit: contain;
}
<body>
  <figure>
    <img src="https://9to5google.com/wp-content/uploads/sites/4/2017/05/google-contacts.png">
    <figcaption>User Login</figcaption>
  </figure>
</body>