Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

We want to bring the button to the center of the image

button top of the image and vertical and horizontal center
I using margin but not properly work

without using margin

   <html>
        <head>
         <style type="text/css">
          .box-cover{
            width:100%;
            height:80vh;
          }
          button{
           padding:20px 30px;
           background-color:red;
           border:none;
           color:white;
           border-radius:5em;
          }
        </style>
       </head>
       <body>
        <div class="box">
         <img class="box-cover" src="https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png">
         <button>Click ME</button>
        </div> 
       </body>
      </html>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

.box-cover{
  width:100%;
  height:80vh;
  position: relative;
}
button{
  padding:20px 30px;
  background-color:red;
  border:none;
  color:white;
  border-radius:5em;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
<div class="box">
  <img class="box-cover" src="https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png">
  <button>Click ME</button>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading