简体   繁体   English

移动浏览器换行链接的范围

[英]Mobile browser line wrapping span of links

I have a header on our website that has a variable set of links that should be shown to the user in one row/line. 我在我们的网站上有一个标头,其中包含一组可变的链接,应以一行/行向用户显示。 For example: 例如:

<span class="logout">
   <a href="/schedule">My Schedule</a>
   <a href="/fullSchedule">Full Schedule</a>
   <a href="/timeline">Timeline</a>
   <a href="/roster">Roster</a>
   <a href="/logout">Log Out</a>
</span>

The CSS for the "logout" class is "float: right;" “注销”类的CSS为“ float:right;”。 to make the links go to the right side of the page/header. 使链接转到页面/标题的右侧。

This works fine for us on regular computer browsers, but on mobile browsers (Android and Mobile Safari) we get the links being line wrapped to fit on the screen, even though a table below the header stretches off the screen several times over. 在正常的计算机浏览器上,这对我们来说效果很好,但是在移动浏览器(Android和Mobile Safari)上,即使标题下方的表格在屏幕上延伸了数次,我们也会将链接换行以适合屏幕。

Our desired behavior on the phone is to have the navigation links run as one long line, even if they run off the visible screen. 我们希望在电话上执行的操作是使导航链接沿一条长线运行,即使它们在可见屏幕上也不行。 Trying to tap on links stacked on top of each other is problematic as it is easy to hit "Log Out" when you meant "My Schedule" right above it. 尝试利用彼此堆叠的链接是有问题的,因为当您在其上方意为“我的日程安排”时,很容易点击“注销”。

I've tried various CSS bits: 我尝试了各种CSS位:

  • white-space:nowrap; 空白:nowrap; gave me a truncated list of links, which is not good. 给了我截断的链接列表,这不好。
  • overflow seemed to have no effect. 溢出似乎没有任何作用。

Sadly, the best solution I've found so far is to put all the links into a table (one link per cell). 不幸的是,到目前为止,我找到的最好的解决方案是将所有链接放到一个表中(每个单元格一个链接)。 But before I gave up and use a table, I figured I'd ask StackOverflow and see if there is a clever way to do it that I hadn't considered. 但是在放弃并使用表之前,我想过要问StackOverflow,看看是否有一种我没有考虑过的聪明方法。

Update 更新资料

Having played with Phlume's answer some, I think I understand my problem better. 玩过Phlume的答案后,我想我对我的问题有了更好的了解。 I'm trying to float the links right, but not let them wrap. 我试图使链接正确浮动,但不要让它们环绕。 That means, if the right side of the screen is too close in, it truncates to the left. 这意味着,如果屏幕的右侧过于靠近,则它会向左截断。 I want it to not truncate at all, and stick off the right side (you can scroll to the right), but have any extra space be on the left. 我希望它完全不截断,并停留在右侧(您可以向右滚动),但左侧应有多余的空间。 Not sure how to accomplish this. 不确定如何完成此操作。

You are placing block elements within a span... try changing the markup accordingly: 您正在将块元素放置在一个范围内...请尝试相应地更改标记:

<ul class="logout">
   <li><a href="/schedule">My Schedule</a></li>
   <li><a href="/fullSchedule">Full Schedule</a></li>
   <li><a href="/timeline">Timeline</a></li>
   <li><a href="/roster">Roster</a></li>
   <li><a href="/logout">Log Out</a></li>
</ul>

I ended up realizing that the float: right; 我最终意识到, float: right; was a major part of my problem, so I got rid of it and changed my span into a div tag with "optional" breaks before it. 是我问题的主要部分,因此我摆脱了这个问题,并将其范围更改为div标签,并在其之前添加了“可选”的中断。 The resulting HTML file looks like: 生成的HTML文件如下所示:

<br class="small_break"/><br class="small_break"/><br class="small_break"/>
<div class="logout">
   <a href="/schedule">My Schedule</a>
   <a href="/fullSchedule">Full Schedule</a>
   <a href="/timeline">Timeline</a>
   <a href="/roster">Roster</a>
   <a href="/logout">Log Out</a>
</div>

Here is the relevant CSS I used: 这是我使用的相关CSS:

@media screen and (min-width: 650px) {
    .small_break {
        display:none;
    }
}

.logout {
    text-align: right;
    white-space: nowrap;
}

This hides the breaks with class "small_break" for screens with more than 650 pixels wide, allowing the navigation links to effectively float up beside the branding images which are float: left; 这对于宽度超过650像素的屏幕隐藏了“ small_break”类的中断,从而使导航链接可以有效地悬浮在浮动的品牌形象旁边float: left; . For smaller screens, the breaks appear, moving the links below the branding images. 对于较小的屏幕,会出现中断,将链接移动到品牌图片下方。

The text-align:right; text-align:right; keeps my links in the div right aligned while the white-space: nowrap; 使我的div中的链接正确对齐,同时保留white-space: nowrap; keeps to browser from line wrapping the links. 避免浏览器将链接换行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM