使HTML小部件动态调整大小

时间:2017-09-13 20:40:18

标签: html css

我正在尝试让我的HTML小部件响应并在调整浏览器大小时调整大小。这是HTML:

<nav class="navigation">
    <ul class="menu">
        <li class="menu__item">
            <a href="" class="menu__link" target="_blank">
                <span class="menu__title">
                    <span class="menu__first-word" data-hover="Executive">
                        Executive
                    </span>
                    <span class="menu__second-word" data-hover="Summary">
                        Summary
                    </span>
                </span>
            </a>
        </li>

        <li class="menu__item">
            <a " class="menu__link" target="_blank">
                <span class="menu__title">
                    <span class="menu__first-word" data-hover="Display">
                        Display
                    </span>
                    <span class="menu__second-word" data-hover="Summary">
                        Summary
                    </span>
                </span>
            </a>
        </li>

        <li class="menu__item">
            <a href="" class="menu__link" target="_blank">
                <span class="menu__title">
                    <span class="menu__first-word" data-hover="Facebook">
                        Facebook
                    </span>
                    <span class="menu__second-word" data-hover="Summary">
                        Summary
                    </span>
                </span>
            </a>
        </li>

        <li class="menu__item">
            <a href="" class="menu__link" target="_blank">
                <span class="menu__title">
                    <span class="menu__first-word" data-hover="LinkedIn">
                        LinkedIn
                    </span>
                    <span class="menu__second-word" data-hover="Summary">
                        Summary
                    </span>
                </span>
            </a>
        </li>

        <li class="menu__item">
            <a href="" class="menu__link" target="_blank">
                <span class="menu__title">
                    <span class="menu__first-word" data-hover="Search">
                        Search
                    </span>
                    <span class="menu__second-word" data-hover="Summary">
                        Summary
                    </span>
                </span>
            </a>
        </li>
                <li class="menu__item">
            <a href="" class="menu__link" target="_blank">
                <span class="menu__title">
                    <span class="menu__first-word" data-hover="Google">
                        Google
                    </span>
                    <span class="menu__second-word" data-hover="Analytics">
                        Analytics
                    </span>
                </span>
            </a>
        </li>
    </ul>
</nav>

这是CSS:

 body {
      display: flex;
      align-items: center;
      height: ;
      background: #FFF;
    }

    a {
      outline: 0;
      text-decoration: none;
    }

    .navigation {
      width: 100%;
      border-bottom: 3px solid #000;
      font-family: 'Pathway Gothic One', sans-serif;
      font-size: 22px;
    }

    .menu {
      display: flex;
      justify-content: center;
      max-width: 1150px;
      margin: 0 auto;
      padding-left: 0;
    }

    .menu__item {
      display: inline-block;
      white-space: nowrap;
    }
    @media screen and (max-width: 480px) {
      .menu__item:nth-child(n + 3) {
        display: none;
      }
      .menu__item:nth-child(2) .menu__link {
        border-right: 0;
      }
    }
    @media screen and (max-width: 768px) {
      .menu__item:nth-child(n + 4) {
        display: none;
      }
      .menu__item:nth-child(3) .menu__link {
        border-right: 0;
      }
    }
    @media screen and (max-width: 992px) {
      .menu__item:nth-child(n + 5) {
        display: none;
      }
      .menu__item:nth-child(4) .menu__link {
        border-right: 0;
      }
    }
    .menu__item:last-child .menu__link {
      border-right: 0;
    }

    .menu__link {
      display: block;
      padding: 6px 30px 3px;
      border-right: 2px dotted #ccd7d7;
    }
    .menu__link:hover .menu__first-word, .menu__link:focus .menu__first-word {
      transform: translate3d(0, -105%, 0);
    }
    .menu__link:hover .menu__second-word, .menu__link:focus .menu__second-word {
      transform: translate3d(0, 105%, 0);
    }
    @media screen and (min-width: 768px) {
      .menu__link {
        padding: 6px 40px 3px;
      }
    }

    .menu__title {
      display: inline-block;
      overflow: hidden;
    }

    .menu__first-word,
    .menu__second-word {
      display: inline-block;
      position: relative;
      transition: transform .3s;
    }
    .menu__first-word::before,
    .menu__second-word::before {
      position: absolute;
      content: attr(data-hover);
    }

    .menu__first-word {
      color: #000000;
    }
    .menu__first-word::before {
      top: 105%;
      color: #000000;
    }

    .menu__second-word {
      color: #F37421;
    }
    .menu__second-word::before {
      bottom: 105%;
      color: #F37421;
    }

请建议调整此方法以使其动态化的最佳方法。我现在已经通过HTML删除了URL引用。

如果您有任何疑问,请与我们联系。

谢谢,

1 个答案:

答案 0 :(得分:0)

HTML不是响应式的,它用于构建您的页面。 CSS用于“设计”它。 我会添加一个JavaScript脚本来动态调整元素大小!

如果您不习惯使用JavaScript,请不要担心,入门非常简单。

以下是一些有用的文档:

希望有所帮助;)