Home > front end >  How to Set Text Exactly under Image and remove extra space?
How to Set Text Exactly under Image and remove extra space?

Time:06-21

I have made HTML Page but here I am not able to Align text exactly under image. please tell how to remove extra space on right side I have googled tried with margin/padding 0 also tried display: inline-block but still not able to find out what is the solution?

body {
  text-align: center;
  width: 1440px;
  background-color: hsl(212, 45%, 89%);
  font-family: 'Outfit', sans-serif;
  font-size: 15px;
}

.bold {
  font-weight: 700;
  width: 45%;
  height: 45%;
  color: hsl(218, 44%, 22%);
}

img {
  width: 50%;
  height: 50%;
  border-radius: 5%;
}

.container {
  display: inline-block;
  background-color: hsl(0, 0%, 100%);
  padding: 17px;
  border-radius: 5%;
}

.context {
  width: 45%;
  height: 45%;
  color: hsl(220, 15%, 55%);
  /* display: flex; */
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <!-- displays site properly based on user's device -->

  <link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">

  <title>Frontend Mentor | QR code component</title>

  <!-- CSS Style Sheet -->
  <link rel="stylesheet" href="styles.css">

  <!-- Google Fonts -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400@700&display=swap" rel="stylesheet">

</head>

<body>
  <div >
    <img src="images\image-qr-code.png" alt="QRCode Loading">
    <p >Improve your front-end skills by building projects</p>
    <p >Scan the QR code to visit Frontend Mentor and take your coding skills to the next level</p>
  </div>

</body>

</html>

[wanted result][1] [1]: https://i.stack.imgur.com/p5IBx.jpg [My result][1] [1]: https://i.stack.imgur.com/DKB5Y.png

CodePudding user response:

You need to remove height and width from "context" and "bold" class. Here is the output:

body{
    text-align: center;
    width: 1440px;
    background-color: hsl(212, 45%, 89%);
    font-family: 'Outfit', sans-serif;
    font-size: 15px;
}

.bold{
    font-weight: 700;
    color: hsl(218, 44%, 22%);
}

img{
    width: 50%;
    height: 50%;
    border-radius: 5%;   
}

.container{
    display: inline-block;
    background-color: hsl(0, 0%, 100%);
    padding: 17px;  
    border-radius: 5%; 
}

.context{
    color: hsl(220, 15%, 55%);
    /* display: flex; */
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device -->

  <link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
  
  <title>Frontend Mentor | QR code component</title>

  <!-- CSS Style Sheet -->
  <link rel="stylesheet" href="styles.css">

  <!-- Google Fonts -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400@700&display=swap" rel="stylesheet">
  
</head>
<body>
  <div >
      <img src="images\image-qr-code.png" alt="QRCode Loading">
      <p >Improve your front-end skills by building projects</p>
      <p >Scan the QR code to visit Frontend Mentor and take your coding skills to the next level</p>
  </div>
 
  <!-- <footer>
    <div >
      Challenge by <a href="https://www.frontendmentor.io?ref=challenge" target="_blank">Frontend Mentor</a>. 
      Coded by <a href="#">Utsavi Patil</a>.
    </div>
  </footer> -->
  
</body>
</html>

  • Related