RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1064767
Accepted
Evgeniy Reva
Evgeniy Reva
Asked:2020-12-31 07:41:56 +0000 UTC2020-12-31 07:41:56 +0000 UTC 2020-12-31 07:41:56 +0000 UTC

使这个固定宽度的设计响应

  • 772

我会非常原谅帮助,我开始研究前面 - 并在这项任务上陷入了昏迷。借助对flex+float技术的理解,我需要通过媒体查询来完成以下任务:

“使用固定布局的附件。使用以下媒体查询创建响应式网页布局:非常小的设备(手机,小于 768 像素)(1 张图片)小型设备(平板电脑,768 像素或更多)(2 张图片)中型设备(台式机, 992px 及以上) 大型设备 (大型桌面, 1200px 及以上)"

* {
    box-sizing: border-box;
}

.page-wrap {
    width: 800px;
    margin: 20px auto;
}

.main-story {
    position: relative;
    margin: 0 0 25px 0;
}

img {
    display: block;
}

a {
    color: lightblue;
}

.story-intro {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.75);
    padding: 20px;
    color: white;
}

h1 {
    font-size: 4em;
}
h1, h2 {
    margin: 0 0 10px 0;
}

.story-intro h1 {
    font-size: 2.5em;
}
.story-intro p {
    margin: 0;
}

.sub-stories {
    overflow: hidden;
    margin: 0 0 25px 0;
}

.sub-story {
    float: left;
    width: 250px;
    margin-right: 25px;
    position: relative;
    font-size: 80%;
}

.last {
    margin-right: 0;
}
 /* Медиа-запросы пробовал писать я сам :(
}
@media screen (max-width: 768px) {

   .story-intro, p, h1, img {
       width: 100vw;
       position: relative;
        }
    .sub-story {
        float: none;
        }
    }

 @media screen (min-width: 768px) and (max-width: 992px) {
 .page-wrap, .sub-stories{
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  width: 100%;
  height: auto;

}

.main-story, .sub-story:first-child, .sub-story:last-child,  .last, h1, h2, p{
    width: 50%;
    margin: 0;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
  }
}
  @media screen (min-width: 992px) and (max-width: 1200px) {

}
@media screen (min-width: 1200px) {

}
*/
<!-- This is a piece of code -->
<div class="page-wrap">

    <h1>Make This Responsive</h1>

    <p>While maintaining the heirarchy of importance.</p>

    <article class="main-story">

        <img src="http://f.cl.ly/items/2e3c2a1Z0D1H3u0W2K12/shera.jpg" alt="Sha Ra Rocking"/>

        <div class="story-intro">
            <h1>Most Important Story</h1>
            <p>This article has the most visual weight. <a href="http://nebezial.deviantart.com/art/she-ra-115867096">image source.</a></p>
        </div>

    </article>

    <section class="sub-stories">

        <article class="sub-story">
            <img src="http://placekitten.com/250/350"/>
            <div class="story-intro">
                <h2>Less Important Story</h2>
                <p>This story has less visual weight.</p>
            </div>
        </article>

        <article class="sub-story">
            <img src="http://placecage.com/250/350"/>
            <div class="story-intro">
                <h2>Less Important Story</h2>
                <p>This story has less visual weight.</p>
            </div>
        </article>

        <article class="sub-story last">
            <img src="http://placebear.com/250/350"/>
            <div class="story-intro">
                <h2>Less Important Story</h2>
                <p>This story has less visual weight.</p>
            </div>
        </article>

    </section>

</div>
 

Ps 我将不胜感激并感谢任何帮助。我很善于接受批评,所以不要退缩。我做了我能做的一切(我试着自己写请求),我理解得很糟糕,我很困惑..但想知道的愿望并没有减少:)

flexbox
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    user355286
    2020-12-31T08:51:23Z2020-12-31T08:51:23Z

    我不知道为什么会有媒体查询以及在其中写什么,如果没有它们一切都是自适应的,我唯一要做的就是以某种方式修复边距。

    * {
        box-sizing: border-box;
    }
    
    img {
      width: 100%;
      display: block;
    }
    
    h1, p , h2 {
      text-align: center;
    }
    
    .page-wrap {
      max-width: 800px;
      margin: 20px auto;
    }
    
    .main-story {
      width: 100%;
      margin-bottom: 25px;
    }
    
    .main-story,
    .sub-story {
      position: relative;
    }
    
    .main-story .story-intro,
    .sub-story .story-intro {
      position: absolute;
      bottom: 0;
      width: 100%;
      background: rgba(0, 0, 0, 0.75);
      color: white;
    }
    
    .sub-stories {
      display: flex;
      flex-wrap: wrap;
    }
    
    .sub-story {
      width: 250px;
      flex-grow: 1;
      margin-right: 25px;
      margin-bottom: 25px;
    }
    
    .sub-story:last-child {
      margin-right: 0;
    }
    
    @media (max-width: 834px) {
      .sub-story:nth-child(2) {
        margin-right: 0;
      }
      
      .sub-story:nth-child(3) {
        margin: 0 25px;
      }
    }
    
    @media (max-width: 558px) {
      .sub-story:nth-child(1) {
        margin: 25px 25px;
      }
      
      .sub-story:nth-child(2) {
        margin: 25px 25px;
      }
    }
    <div class="page-wrap">
    
      <h1>Make This Responsive</h1>
    
      <p>While maintaining the heirarchy of importance.</p>
    
      <article class="main-story">
    
        <img src="https://picsum.photos/1980" alt="Sha Ra Rocking" />
    
        <div class="story-intro">
          <h1>MAIN</h1>
          <p>This article has the most visual weight. <a href="https://picsum.photos/250/35">image source.</a></p>
        </div>
    
      </article>
    
      <section class="sub-stories">
    
        <article class="sub-story">
          <img src="https://picsum.photos/1980" />
          <div class="story-intro">
            <h2>SUB 1</h2>
            <p>This story has less visual weight.</p>
          </div>
        </article>
    
        <article class="sub-story">
          <img src="https://picsum.photos/1980" />
          <div class="story-intro">
            <h2>SUB 2</h2>
            <p>This story has less visual weight.</p>
          </div>
        </article>
    
        <article class="sub-story">
          <img src="https://picsum.photos/1980" />
          <div class="story-intro">
            <h2>SUB 3</h2>
            <p>This story has less visual weight.</p>
          </div>
        </article>
    
      </section>
    
    </div>

    • 1
  2. Evgeniy Reva
    2020-01-02T03:20:04Z2020-01-02T03:20:04Z

    我非常感谢那些帮助过我的人,我提出了我的最终版本的 css 答案(任务中的 html)——如果有人有意见或建议,请不要害羞——我对你的意见很感兴趣。

    *{
      padding: 0;
      margin: 0;
      border: 0;
    }
    *,*:before,*:after{
      -moz-box-sizing: border-box;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
    }
    :focus,:active{outline: none;}
    a:focus,a:active{outline: none;}
    
    nav,footer,header,aside{display: block;}
    
    html,body{
      height: 100%;
      width: 100%;
      font-size: 100%;
      line-height: 1;
      -ms-text-size-adjust: 100%;
      -moz-text-size-adjust: 100%;
      -webkit-text-size-adjust: 100%;
    }
    input,button,textarea{font-family:inherit;}
    
    input::-ms-clear{display: none;}
    button{cursor: pointer;}
    button::-moz-focus-inner {padding:0;border:0;}
    a, a:visited{text-decoration: none;}
    a:hover{text-decoration: none;}
    ul li{list-style: none;}
    img{vertical-align: top;}
    
    h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight: 400;}
    
    *{
        box-sizing: border-box;
    }
    
    .page-wrap {
        width: 800px;
        margin: 20px auto;
    }
    
    .main-story {
        position: relative;
        margin: 0 0 25px 0;
    }
    
    img {
        display: block;
    }
    
    a {
        color: lightblue;
    }
    
    .story-intro {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        background: rgba(0, 0, 0, 0.75);
        padding: 20px;
        color: white;
    }
    
    h1 {
        font-size: 4em;
    }
    h1, h2 {
        margin: 0 0 10px 0;
    }
    
    .story-intro h1 {
        font-size: 2.5em;
    }
    .story-intro p {
        margin: 0;
    }
    
    .sub-stories {
        overflow: hidden;
        margin: 0 0 25px 0;
    }
    
    .sub-story {
        float: left;
        width: 250px;
        margin-right: 25px;
        position: relative;
        font-size: 80%;
    }
    
    .last {
        margin-right: 0;
    }
    
    
    @media (min-width: 993px) and (max-width: 1200px) {
      .sub-stories {
        display: flex;
        flex-wrap: wrap;
        }
    .sub-story {
        flex-grow: 1;
        }
         img {
        width: 100%;
    }
      .sub-story:nth-child(1),
       .sub-story:nth-child(2),
        .last {
        margin: 0;
         }
        }
    @media (min-width: 769px) and (max-width: 992px) {
      .sub-stories {
        display: flex;
        flex-wrap: wrap;
        }
    .sub-story {
        flex-grow: 1;
        }
      img {
        width: 100%;
    }
    
      .sub-story:nth-child(1) {
        margin: 0 25px 25px 0px;
      }
      
      .sub-story:nth-child(2) {
        margin: 0 0px 25px 25px;
      }
      .last {
        margin: 0 25px ;
    }
    }
    @media (max-width: 768px) {
     .story-intro, .main-story, img{
           width: 100vw;
            }
        .sub-story {
            float: none;
            }
      .sub-story:nth-child(1),
      .sub-story:nth-child(2){
        margin-bottom: 25px;
        }
    }
    
       

    • 0

相关问题

  • 弹性项目内容的垂直对齐

  • 如何包装一个列表?

  • 弹性盒布局

  • 使用 Bootstrap 4 进行混合块对齐

  • 在 flexbox 容器中没有明确的填充

  • 弹性块高度的问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    根据浏览器窗口的大小调整背景图案的大小

    • 2 个回答
  • Marko Smith

    理解for循环的执行逻辑

    • 1 个回答
  • Marko Smith

    复制动态数组时出错(C++)

    • 1 个回答
  • Marko Smith

    Or and If,elif,else 构造[重复]

    • 1 个回答
  • Marko Smith

    如何构建支持 x64 的 APK

    • 1 个回答
  • Marko Smith

    如何使按钮的输入宽度?

    • 2 个回答
  • Marko Smith

    如何显示对象变量的名称?

    • 3 个回答
  • Marko Smith

    如何循环一个函数?

    • 1 个回答
  • Marko Smith

    LOWORD 宏有什么作用?

    • 2 个回答
  • Marko Smith

    从字符串的开头删除直到并包括一个字符

    • 2 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5