【问题标题】:Why aren't my anchor tags reflowing?为什么我的锚标签没有重排?
【发布时间】:2014-09-28 04:37:55
【问题描述】:

我正在开发我的新网站,但遇到了一些我无法弄清楚的问题。这是链接:

http://www.adamabrams.com/aadc/

当我将浏览器的大小调整为“移动宽度”时,它比我的站点菜单下方的椭圆形“标签”小行的宽度更窄,我希望标签重新排列成两行(或多达需要)。相反,它们固执地排成一排,并从窗口的右侧突出。

我没有给封闭的 div 一个固定的高度...我知道这一定很简单,但我很难过!

这是 HTML:

<main class="content" itemtype="http://schema.org/Blog" itemscope="itemscope" itemprop="mainContentOfPage" role="main">
<div class="post_tags">
<a class="tagintro" href="#">Select area of expertise:</a>
<a class="database" title="database projects" href="http://adamabrams.com/aadc/tag/database/">database</a>
<a class="ecommerce" title="ecommerce projects" href="http://adamabrams.com/aadc/tag/ecommerce/">ecommerce</a>
<a class="mobile" title="mobile projects" href="http://adamabrams.com/aadc/tag/mobile/">mobile</a>
<a class="website" title="website projects" href="http://adamabrams.com/aadc/tag/website/">website</a>
</div>

...这里是所有相关的 CSS,我认为:

/* TAG BUTTONS */

/* Styling of the buttons, everywhere */
.entry-tags a, .post_tags a {
    color: #3D3D3D;
    font-weight: bold;
    background-color: #EECE88;
    padding: .35em .5em;
    border-radius: .7em;
    -moz-border-radius: .7em;
    -webkit-border-radius: .7em;
}

.entry-tags a:hover, .post_tags a:hover {
    color: black;
    background-color: orange;
}

/* TAGS "HEADER" ON TAG.PHP PAGE */

/* Layout of buttons area */
.post_tags {
    text-align: center;
    margin-bottom: 2em;
}

/* Spacing between buttons */
.post_tags a {
    margin-right: 1em;
}

.post_tags a:first-child,
.post_tags a:last-child {
    margin-right: 0;
}

/* Currently displayed tag */
body.tag-ecommerce a.ecommerce,
body.tag-database a.database,
body.tag-mobile a.mobile,
body.tag-website a.website {
    color: black;
    background-color: orange;
}

a.tagintro, a.tagintro:hover {
    background-color: transparent;
    color: white;
}

欢迎提出任何想法或建议!

谢谢, 亚当

【问题讨论】:

    标签: html css


    【解决方案1】:

    我明白你的目的。获得您想要达到的效果的最佳方法是在所需的断点处更改元素的宽度和边距。

    因此,对于您的“媒体宽度”,您可以将类设置为重新调整大小。通过这样做,元素将自然地顺着文档向下流动。

    例如:

    @media only screen and (max-width: 480px) { /* Your break-point for mobile */
    
      .ecommerce,
      .database,
      .mobile,
      .website{
          width: 48%;
          margin-left: 1%;
          margin-right: 1%;
      }
    }
    

    或一些对您的设计有意义的类似测量。

    【讨论】:

    • 谢谢安德鲁。我会尝试这种方法。不过,我确实想知道,为什么标签不能像文本一样流动……这似乎是一件很简单的事情(尽管我知道 CSS 中的简单性通常难以捉摸!)
    • 实际上,仅将它们以移动宽度向左浮动就可以解决问题并使它们“流动”......但它当然会让它们保持左对齐,当我宁愿它们仍然保持居中时(我已经将它们的整体容器与文本对齐)。流程仅在给定浮点数时发生,我猜这是预期的 CSS 行为,但会覆盖文本对齐。
    猜你喜欢
    • 2022-12-17
    • 2022-07-07
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多