如何在更改屏幕尺寸时调整卡片大小

How to get card to resize when screen size is changed

我有一个带有导航栏的网页和一张包含信息的卡片。导航栏随屏幕调整大小,但我正在努力让卡片做同样的事情 。我试过将 CSS 中的 px 更改为 rem,但这似乎不起作用。我也试过制作一个包装器来围绕 HTML 主体内的元素,但这也没有解决问题。

如果有人能帮我解决这个问题,我将不胜感激。

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./styles.css">
</head>
<body>
    <div class="content-wrapper">
    <div class="loader"></div>
    <header>
        <a href="#" class="logo">[Ayanfe]:)</a>
        <ul>
            <li><a href="./Pages/1/index.html" class="active">Next</a></li>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </header>

    <main>

  <a href="#" class="card">
      <div class="inner">
        <time class="subtitle">Before I delve into my pitch, I think its important to acknowledge that present me is much different from younger me. Growing up, I was extroverted, trusting and extremely open to people. As life progressed the realities of the world became more apparent and the world that lived inside my head became a lot more attractive.<time>
            <br>
            <br>

        <time class="Key">Keyword: Escapism<time>


      </div>

 
  </a>
</div>
    
</body>
</html>

CSS

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}



body {
   background-color: black;
   padding: 0;
   margin: 0;
   height: 100vh;
   width: 100vh;
}

header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1.875rem 6.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: Poppins, sans-serif;
    z-index: 10000;
}

header .logo {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
    font-size: 1.563rem;
    text-transform: uppercase;
    letter-spacing: 0.313rem;

}

header ul{
    display: flex;
    justify-content: center;
    align-items: center;

}

header ul li {
    list-style: none;
    margin-left: 1.25rem;
}

header ul li a {
     text-decoration: none;
     padding: 0.375rem 0.938rem;
     color: #fff;
     border-radius: 1.25rem;

}

header ul li a:hover,
header ul li a.active {
    background: #fff;
    color: #2b1055;
}

main,
footer {
  max-width: 60rem;
  margin: 0 auto;
}

.card {
  height: 28.125rem;
  position: relative;
  left: 18.75rem;
  top: 12.5rem;
  padding: 1.25rem;
  box-sizing: border-box;
  display: flex;
  align-items: flex-end;
  text-decoration: none;
  border: 0.25rem solid;
  border-color: black;
  margin-bottom: 1.25rem;
  background: url(./Images/1.jpg);
  background-repeat: no-repeat;
  background-size: 105%;
  margin: auto;

}

@include media {
    height: 500px;

}

.inner {
  height: 100%;
  width: 500px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center; 
  background: white;
  box-sizing: border-box;
  padding: 40px;
  border: solid;
  border-color: grey;
  border-radius: 2px;
}
  
  @include media {
    width: 50%;
    height: 100%;
  }


.title {
  font-size: 24px;
  color: black;  
  text-align: center;
  font-weight: 700;
  color: #181818;
  text-shadow: 0px 2px 2px #a6f8d5;
  position: relative;
  margin: 0 0 20px 0;
}
  
  @include media {
    font-size: 30px;
  }


.subtitle {
  color: black;
  font-size: 20px;
  text-align: center;
}


.content-wrapper {
  margin-left: auto;
  margin-right: auto;
  width: 60rem;
}

您已将 .inner 的宽度设置为 500px。 这意味着它将始终保持 500 像素,与屏幕尺寸无关。

尝试使用百分比 - 您的页眉有 width: 100%,这就是它在调整大小时改变宽度的原因。

如果您需要比这更大的灵活性,calc() 允许您计算具有不同单位的值,例如 width: calc(20% - 10px + 2rem)

您的问题的解决方案是删除 body {...} 选项,然后响应将适用于 <a class="card">。另外我添加了一些 @media(max-width: ... px) 设置。

*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
   background-color: black;
}

header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 1.875rem 6.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: Poppins, sans-serif;
    z-index: 10000;
}

header .logo {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
    font-size: 1.563rem;
    text-transform: uppercase;
    letter-spacing: 0.313rem;

}

header ul{
    display: flex;
    justify-content: center;
    align-items: center;

}

header ul li {
    list-style: none;
    margin-left: 1.25rem;
}

header ul li a {
     text-decoration: none;
     padding: 0.375rem 0.938rem;
     color: #fff;
     border-radius: 1.25rem;

}

header ul li a:hover,
header ul li a.active {
    background: #fff;
    color: #2b1055;
}

main,
footer {
  max-width: 60rem;
  margin: 0 auto;
}

.card {
  height: 28.125rem;
  width: 70%;
  position: relative;
  left: 18.75rem;
  top: 12.5rem;
  padding: 1.25rem;
  display: flex;
  align-items: flex-end;
  text-decoration: none;
  border: 0.25rem solid;
  border-color: black;
  background: url(./Images/1.jpg);
  background-repeat: no-repeat;
  background-size: 105%;
  margin: 0 !important;
}

/*
@include media {
    height: 500px;

}*/

.inner {
  height: 100%;
  width: 50%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center; 
  background: white;
  box-sizing: border-box;
  padding: 40px;
  border: solid;
  border-color: grey;
  border-radius: 2px;
}
  
 /* @include media {
    width: 50%;
    height: 100%;
  }*/


.title {
  font-size: 24px;
  color: black;  
  text-align: center;
  font-weight: 700;
  color: #181818;
  text-shadow: 0px 2px 2px #a6f8d5;
  position: relative;
  margin: 0 0 20px 0;
}
  
  /*@include media {
    font-size: 30px;
  }*/


.subtitle {
  color: black;
  font-size: 20px;
  text-align: center;
}

.Key{
    margin-top: 50px;
}

.content-wrapper {
  height: 100vh;
}

@media(max-width: 1000px) {
    .Key, .subtitle {
        font-size: 1rem;
    }
}
@media(max-width: 750px) {
    .Key, .subtitle {
        font-size: 0.8rem;
    }

    .inner {
        height: 70%;
    }
}
@media(max-width: 720px) {
    .Key, .subtitle {
        font-size: 0.6rem;
    }

}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="content-wrapper">
        <header>
            <a href="#" class="logo">[Ayanfe]:)</a>
            <ul>
                <li><a href="./Pages/1/index.html" class="active">Next</a></li>
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </header>

        <a href="#" class="card">
            <div class="inner">
                    <time class="subtitle">Before I delve into my pitch, I think its important to acknowledge that present me is much different from younger me. Growing up, I was extroverted, trusting and extremely open to people. As life progressed the realities of the world became more apparent and the world that lived inside my head became a lot more attractive.<time>
                    <br>
                    <br>

                <time class="Key">Keyword: Escapism<time>
            </div>
        </a>
    </div>
    
</body>
</html>