reactjs 如何使用css将img元素放置在html的H1标记上

kqqjbcuj  于 2023-01-12  发布在  React
关注(0)|答案(1)|浏览(161)

我一直尝试将图像放置在容器内,以便将其放置在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>
 )
}

下面是我的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;
  }
axr492tv

axr492tv1#

1.排印错误为<h1>而非<hi>
1.使用<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>
 )
}

相关问题