如何在图像下精确设置文本并删除额外的空间?

发布于 2025-02-09 02:51:48 字数 2048 浏览 2 评论 0原文

我已经制作了HTML页面,但是在这里,我无法在图像下完全对齐文本。 请告诉我如何删除右侧的额外空间,我搜索过用保证金/填充0的Google Google还尝试了显示:内联块,但仍然无法找出解决方案是什么?

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

</body>

</html>

[想要结果] [1] [1]:https://i.sstatic.net/p5ibx.jpg [我的结果] [1] [1]:https://i.sstatic.net/dkb5y.png

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 class="container">
    <img src="images\image-qr-code.png" alt="QRCode Loading">
    <p class="bold">Improve your front-end skills by building projects</p>
    <p class="context">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.sstatic.net/p5IBx.jpg
[My result][1] [1]: https://i.sstatic.net/DKB5Y.png

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熟人话多 2025-02-16 02:51:48

您需要从“上下文”和“粗体”类中删除高度和宽度。这是输出:

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 class="container">
      <img src="images\image-qr-code.png" alt="QRCode Loading">
      <p class="bold">Improve your front-end skills by building projects</p>
      <p class="context">Scan the QR code to visit Frontend Mentor and take your coding skills to the next level</p>
  </div>
 
  <!-- <footer>
    <div class="attribution">
      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>

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 class="container">
      <img src="images\image-qr-code.png" alt="QRCode Loading">
      <p class="bold">Improve your front-end skills by building projects</p>
      <p class="context">Scan the QR code to visit Frontend Mentor and take your coding skills to the next level</p>
  </div>
 
  <!-- <footer>
    <div class="attribution">
      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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文