Web实现:页面横向滚动

78 篇文章 2 订阅
68 篇文章 0 订阅

实现效果:根据页面宽度,当页面宽度超出内容时,页面禁止横向滚动,页面宽度小于内容时,页面横向滚动。根据页面的不同宽度,字体大小也会相应变化。
HTML部分:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>移动端问吧首页</title>
    <link rel="stylesheet" href="./index.css">
  </head>
  <body>
    <header class="header">
      <div class="search-bar">
        <input type="text" class="search" placeholder="搜一搜" />
        <span class="search-icon"></span>
      </div>
      <div class="options">
        <button class="btn-scan"></button>
        <button class="btn-mail"></button>
      </div>
    </header>

    <section class="banner">
      <img src="./images/banner.jpg" alt="" />
    </section>

    <section class="post-group">
      <div class="info">
        <span class="txt">关注了2个圈子</span>
        <button class="btn-more">
          <span>查看全部圈子</span>
          <span class="arrow-right-icon"></span>
        </button>
      </div>
      <div class="dashed"></div>
      <ul class="groups">
        <li class="group">
          <img src="./images/java.png" alt="" />
          <div class="txt">JAVA</div>
        </li>
        <li class="group">
          <img src="./images/h5.png" alt="" />
          <div class="txt">前端</div>
        </li>
        <li class="group">
          <img src="./images/java.png" alt="" />
          <div class="txt">JAVA</div>
        </li>
        <li class="group">
          <img src="./images/h5.png" alt="" />
          <div class="txt">前端</div>
        </li>
        <li class="group">
          <img src="./images/java.png" alt="" />
          <div class="txt">JAVA</div>
        </li>
        <li class="group">
          <img src="./images/h5.png" alt="" />
          <div class="txt">前端</div>
        </li>
        <li class="group">
          <img src="./images/java.png" alt="" />
          <div class="txt">JAVA</div>
        </li>
        <li class="group">
          <img src="./images/h5.png" alt="" />
          <div class="txt">前端</div>
        </li>
      </ul>
    </section>
  </body>
</html>

CSS部分:

html,
body {
  height: 100%;
  margin: 0; }

ul,
li {
  margin: 0;
  padding: 0; }

li {
  list-style: none; }

h1,
h2 {
  margin: 0; }

p {
  margin: 0;
  padding: 0; }

@media screen and (max-width: 768px) {
  html {
    font-size: 20px; } }

@media screen and (max-width: 320px) {
  html {
    font-size: 17.0666666667px; } }

.btn, .post-group .info .btn-more, header.header .options .btn-mail, header.header .options .btn-scan {
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer; }
  .btn:focus, .post-group .info .btn-more:focus, header.header .options .btn-mail:focus, header.header .options .btn-scan:focus {
    outline: none; }

body {
  max-width: 768px;
  margin: 0 auto; }

header.header {
  max-width: 768px;
  margin: 0 auto;
  height: 2.675rem;
  box-sizing: border-box;
  padding: 0 0.75rem 0.75rem;
  display: flex;
  align-items: flex-end;
  background: #fff;
  position: fixed;
  top: 0;
  left: 0;
  right: 0; }
  header.header .search-bar {
    height: 1.5rem;
    flex: 1;
    position: relative;
    margin-right: 0.825rem;
    font-size: 0; }
    header.header .search-bar .search {
      width: 100%;
      height: 100%;
      box-sizing: border-box;
      background: #f2f2f2;
      border-radius: 1.5rem;
      border: none;
      padding: 0 0.5rem 0 1.85rem;
      box-sizing: border-box; }
      header.header .search-bar .search:focus {
        outline: none; }
    header.header .search-bar ::placeholder {
      font-size: 0.65rem;
      color: #999999; }
    header.header .search-bar .search-icon {
      width: 0.85rem;
      height: 0.85rem;
      background: url(./images/search.png) no-repeat center/contain;
      position: absolute;
      top: 0.325rem;
      left: 0.5rem; }
  header.header .options {
    height: 1.5rem;
    flex: none;
    height: 1.5rem;
    display: flex;
    align-items: center; }
    header.header .options .btn-scan {
      width: 0.95rem;
      height: 0.95rem;
      background: url(./images/scan.png) no-repeat center/contain;
      margin-right: 0.75rem; }
    header.header .options .btn-mail {
      width: 1.05rem;
      height: 1.05rem;
      background: url(./images/mail.png) no-repeat center/contain; }

.banner {
  margin: 2.675rem 0.75rem 0; }
  .banner img {
    width: 100%; }

.post-group {
  padding: 0 0.75rem; }
  .post-group .info {
    height: 2.4rem;
    box-sizing: border-box;
    padding-top: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between; }
    .post-group .info .txt {
      font-weight: 500;
      font-size: 0.8rem;
      color: #333333; }
    .post-group .info .btn-more {
      display: flex;
      align-items: center;
      font-size: 0.7rem;
      color: #3492FD; }
      .post-group .info .btn-more .arrow-right-icon {
        width: 0.275rem;
        height: 0.525rem;
        margin-left: 0.5rem;
        background: url(./images/arrow-right.png) no-repeat center/contain; }
  .post-group .groups {
    height: 4.5rem;
    display: flex;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-left: 0.05rem;
    border-top: 1px dashed #E5E5E5; }
    .post-group .groups .group {
      min-width: 2.8rem;
      height: 3.5rem;
      box-sizing: border-box;
      text-align: center;
      padding-top: 0.375rem;
      margin-right: 1.25rem; }
      .post-group .groups .group > img {
        width: 2.25rem;
        height: 2.25rem;
        margin-bottom: 0.25rem; }
      .post-group .groups .group .txt {
        font-size: 0.7rem;
        color: #000000; }

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jasmyn518

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值