使用网格和Flexbox的响应页面问题

问题描述 投票:0回答:1

我启动了一个项目,但我尝试不使用@media使其响应。我使用的是flexbox和grid,但对于英雄背景,左侧和右侧都有文字,当屏幕尺寸变小时,该文字与文字重叠。我想做的是,当尺寸变小时,图像在文本下不重叠。

https://codepen.io/claudiuu/pen/PowVQvL

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

body {
  font-family: "Open Sans", sans-serif;
}

.header {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-areas:
    "logo logo logo nav nav nav"
    "hero hero hero hero hero hero";
  background: rgb(233, 98, 123);
  background: linear-gradient(
    63deg,
    rgba(233, 98, 123, 1) 0%,
    rgba(191, 79, 212, 1) 100%
  );
}

.logo,
.nav {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 1rem;
}

.logo {
  grid-area: logo;
}

.nav {
  grid-area: nav;
}

.nav ul {
  display: flex;
  list-style: none;
}

.hero {
  grid-area: hero;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
  min-height: 50vh;
  padding: 6vmax;
  color: #fff;
}

.h1-hero {
  font-size: 3rem;
  font-weight: 600;
}

.txthero {
  flex: 1;
  max-width: 30vmax;
  min-width: 40vmin;
}

.img-hero {
  grid-area: hero;
  display: flex;
  background-image: url(https://www.apple.com/uk/music/images/overview/hero__drdt6ucq1rqu_small.png);
  background-position: center right;
  background-repeat: no-repeat;
}

.main-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15em, 1fr));
  /* background-color: rgb(233, 98, 123); */
  margin: 1.5rem;
  gap: 3em;
  justify-content: center;
}

.bg-box {
  background-color: #fafafa;
  padding: 1.2rem;
  border-radius: 1rem;
}
css flexbox css-grid
1个回答
0
投票

经过数小时的思考,更新了代码

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

body {
  font-family: "Open Sans", sans-serif;
}

.header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15em, 1fr));
  background: rgb(233, 98, 123);
  background: linear-gradient(
    63deg,
    rgba(233, 98, 123, 1) 0%,
    rgba(191, 79, 212, 1) 100%
  );
}

.logo,
.nav {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 1rem;
}


.nav ul {
  display: flex;
  list-style: none;
}

.grid-hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15em, 1fr));
  background: rgb(233, 98, 123);
  background: linear-gradient(
    63deg,
    rgba(233, 98, 123, 1) 0%,
    rgba(191, 79, 212, 1) 100%
  );
  padding: 2rem;
}

.txthero {  
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.img-hero {
  /* min-height: 40vh; */
  margin: 1rem;
  height: 30vmin;
  background-image: url(https://www.apple.com/uk/music/images/overview/hero__drdt6ucq1rqu_small.png);
  background-repeat: no-repeat;
  background-size: contain;  
  background-position: center;
}


.main-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15em, 1fr));
  /* background-color: rgb(233, 98, 123); */
  margin: 1.5rem;
  gap: 3em;
  justify-content: center;
}

.bg-box {
  background-color: #fafafa;
  padding: 1.2rem;
  border-radius: 1rem;
}

https://codepen.io/claudiuu/pen/yLyZQdP

© www.soinside.com 2019 - 2024. All rights reserved.