【问题标题】:Container that is both view-port responsive and flexible to child contents对视口响应和对子内容灵活的容器
【发布时间】:2020-04-24 12:55:21
【问题描述】:

我正在尝试使容器既能响应视口,又能灵活(扩大或缩小)其内部内容。

我为圆形容器设置了最大宽度/高度,并使内容适合。 但是当我希望容器缩小/增长以适应更小/更大的变量内容时,事情就崩溃了。

容器也需要响应视口。

我不确定如何使用 CSS、JS 甚至 SVG 来解决这个问题?我知道可能有好几个。

.messages {
  display: grid;
  grid-column: 1 / 2;
  grid-row: 1 / 2;

  grid-template-columns: 1fr;
  grid-template-rows: max-content;

  justify-content: center;

  max-width: 100%;
  margin: 0 auto;
  padding: 0 0 0 0;
  
  background-color: #1DA1F2;

  list-style: none;

  z-index: 1;

  --twitter-blue: #1DA1F2;
  --twitter-lite-blue: #C9E8F5;
  --twitter-lite-gray: #F5F8FA;
  --twitter-dark-gray: #657786;
  --twitter-black: #161616;
  --twitter-white: #FFFFFF;
}

@media (min-width: 42rem) {
  .messages {
    margin: 0 auto;
    padding: 0 0 0 0;
  }
}

.tweet {
  display: grid;
  grid-template-rows: min-content max-content min-content;
  grid-template-areas: "time" "message" "author";
  align-content: center;
  justify-self: center;

  max-width: 100%;
  padding: 2.5rem;
  margin: 1.125rem 0;

  border-radius: 50%;
  width: 20rem;
  height: 20rem;

  background-color: var(--twitter-lite-gray);

  font-family: "Helvetica Neue";
  font-weight: 600;

  -webkit-tap-highlight-color: transparent;

  z-index: 1;
}

@media (min-width: 42rem) {
  .tweet {
    grid-template-rows: min-content max-content min-content;
    grid-template-areas: "time" "message" "author";
    align-content: center;
      justify-self: center;

    max-width: 100%;

    border-radius: 50%;
    width: 30rem;
    height: 30rem;
  }
}

.tweet:nth-child(odd) {
  margin: 1.125rem 0;
}

.tweet:nth-child(even) {
  margin: 1.125rem 0;
}

.tweet__wrapper {
  display: grid;
  grid-template-rows: min-content max-content min-content;
  grid-template-areas: "time" "message" "author";
  align-content: center;
    justify-self: start;

  margin: 0;
  padding: 0;

  width: 100%;
}


.tweet__time {
  gird-area: "time";
  display: inline-block;
  width: 100%;

  padding: 2% 0;

  font-size: calc(16px + (21 - 16) * ((100vw - 320px) / (2000 - 320)));

  visibility: hidden;
}

@media (min-width: 42rem) {
  .tweet__time {
    color: var(--date-font-color);
  }
}


.tweet__time-text {
  color: var(--twitter-black);
  padding: 0 .425rem 0 0rem;
}

.tweet__message {
  grid-area: message;
  display: inline;

  padding: 0 0 5.5% 0;

  color: var(--twitter-black);

  font-size: calc(18px + (26 - 18) * ((100vw - 320px) / (2000 - 320)));
  font-weight: 500;
  font-style: normal;
}


@media (min-width: 42rem) {
  .tweet__message {

  }
}

.tweet__handle {
  grid-area: author;
  /* justify-self: center; */

  display: flex;
  justify-content: flex-end;

  width: 80%;

  color: var(--twitter-black);

}

.tweet__handle:hover {
  text-decoration: none;
}

@media (min-width: 42rem) {
  .tweet__handle {

  }
}

.tweet__handle-link {
  font-size: calc(16px + (25 - 16) * ((100vw - 320px) / (2000 - 320)));
}


@media (min-width: 42rem) {
  .tweet__handle-link {

  }
}

.tweet__handle-link:hover {

}

.tweet__handle-link-text {
  color: var(--twitter-dark-gray);
}
<section class="messages">
  <section class="tweet">
    <blockquote class="tweet__wrapper">
      <time class="tweet__time">
        <span class="tweet__time-text">01/06/2020 @8:30PM</span>
      </time>
      <a href="#" class="tweet__message">
        <q cite="">@acdlite Jest's simple predictions of how long the test suite will take are so great. I haven't seen that in any other devtool.</q>
      </a>
      <cite class="tweet__handle">
        <a class="tweet__handle-link" href="#">
          <span class="tweet__handle-link-text">– rauchg</span>
        </a>
      </cite>
    </blockquote>
  </section>
  <section class="tweet">
    <blockquote class="tweet__wrapper">
      <time class="tweet__time">
        <span class="tweet__time-text">01/06/2020 @8:27PM</span>
      </time>
      <a href="#" class="tweet__message">
        <q cite="">@SilvestriCodes @JuniorsInTech You mean many current white/asian straight-appearing male engineers would struggle g… </q>
      </a>
      <cite class="tweet__handle">
        <a class="tweet__handle-link" href="#">
          <span class="tweet__handle-link-text">– jensimmons</span>
        </a>
      </cite>
    </blockquote>
  </section>
  <section class="tweet">
    <blockquote class="tweet__wrapper">
      <time class="tweet__time">
        <span class="tweet__time-text">01/06/2020 @8:20PM</span>
      </time>
      <a href="#" class="tweet__message">
        <q cite="">@ThePeraCar ????</q>
      </a>
      <cite class="tweet__handle">
        <a class="tweet__handle-link" href="#">
          <span class="tweet__handle-link-text">– wesbos</span>
        </a>
      </cite>
    </blockquote>
  </section>  
</section>

【问题讨论】:

  • 预期结果是什么?
  • 容器应该增长/缩小到其内容的大小,并具有最大宽度/高度以设置顶部大小。
  • 不确定我是否理解该问题,请添加图片以获得预期输出。

标签: css svg flexbox css-grid responsiveness


【解决方案1】:

完善了我的问题并找到了我原来问题的答案。 https://www.endocreative.com/flexbox-circle-responsive-elements/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-31
    • 2014-06-19
    • 1970-01-01
    • 2015-06-17
    • 2020-04-28
    • 1970-01-01
    • 2017-01-07
    • 2018-05-31
    相关资源
    最近更新 更多