简体   繁体   English

如何使用 css 将 img 元素放置到 html 上的 H1 标签上

[英]How to place an img element on to of a H1 tag on html using css

i have been trying to place an image inside a container so it is placed on top of the text of the h1 tag but it is just adding the image next to it and i Want the image to be on top of the text, what should I do?:我一直在尝试将图像放在容器内,以便将其放置在 h1 标签的文本之上,但它只是在其旁边添加图像,我希望图像位于文本之上,我应该怎么做做?:

const Login = () => {
        return(
        <div className="login-container">
        <form className='log' >            
        <img className='img'
        src={logo}
        alt="logo"/>         
        <hi> Hello there</hi>          
        <input placeholder="enter email"/>       
        <input placeholder="password"/>
        <button type="submit">Submit</button>
        </form>
        </div>
 )
}

here is my css file that has the styling of my login component file:这是我的 css 文件,它具有我的登录组件文件的样式:

.login-container {
        width: 600px;
        height: 500px;
        margin-top: 20px;
        margin-bottom: 10px;
        margin-left: 350px ;
        display: flex;
        border: 7px solid grey;
        background-color: white;
        border-radius: 10px;
        align-items: center;
        justify-content: center;
}
.log{
        text-align: center;
        columns: 170px;
        position: relative;
        display: block;
        margin-left: 190px;
        margin-right: 180px;
        width: 200px;
        height: 170px;
        border: 10px solid rgb(140, 128, 168);
        border-radius: 10px;
        align-items: center;
        justify-content: center;
}
 input{
        margin-top: 30px;
        text-align: center;
        border-radius: 30px;
 }

 h1 { 
        font-family: Lato, sans-serif;
        color-scheme: blue;
        display: block;
 }

 img { 
        width: 20px;
        height: 20px;
        border-radius: 30px;
        margin-left: 60px;
  }
  1. Typo for <h1> not <hi> . <h1>不是<hi>的拼写错误。
  2. use <div> tags for your mentioned requirement to display image on top of the text使用<div>标签满足您提到的在文本顶部显示图像的要求
const Login = () => {
        return(
        <div className="login-container">
         <form className='log'>  
          <div>          
           <img className='img'
            src={logo}
            alt="logo"/>
          </div>
          <div>
           <h1> Hello there</h1>          
           <input placeholder="enter email"/>       
           <input placeholder="password"/>
           <button type="submit">Submit</button>
          <div>
        </form>
       </div>
 )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM