Home > Software engineering >  How to lace an img element on to of a H1 tag on html using css
How to lace an img element on to of a H1 tag on html using css

Time:01-10

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?:

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:

.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;
  }

CodePudding user response:

  1. Typo for <h1> not <hi>.
  2. use <div> tags for your mentioned requirement to display image on top of the text
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>
 )
}
  • Related