简体   繁体   English

有没有合适的方法来制作自适应文本?

[英]Is there a proper way to make responsive text?

I've oftentimes had designers give me responsive designs where the wording of an element changes based on the size of the screen. 我经常让设计师为我提供响应式设计,其中元素的用语会根据屏幕的大小而变化。

Desktop : Read more 台式机 :更多
Mobile : Read 手机 :阅读

Desktop : Download PDF 桌面 :下载PDF
Mobile : Export 手机 :导出

Desktop : Click here 桌面 :点击这里
Mobile : Tap here 手机 :点击此处

What is the correct way to have different text in mobile and desktop versions of a website? 在网站的移动版本和桌面版本中拥有不同文本的正确方法是什么?

There are a couple of approaches I've used where clients have made similar requests (and not been talked out of it*): 当客户提出类似的请求(但并没有被拒绝*)时,我使用了几种方法:

1) Use Javascript to change the text based on screen width / device detection methods; 1)使用Javascript根据屏幕宽度/设备检测方法更改文本;

2) Set the default text as your preferred choice, and wrap it in a span or similar, use the text that you think is best on all devices (best for SEO / content / screen readers depending on priority) then use pseudo selectors eg :before with the content: '' property to set alternative text based on media queries. 2)将默认文本设置为您的首选,然后将其包裹在一个跨度或类似文本中,使用您认为在所有设备上最合适的文本(根据优先级,最适合SEO /内容/屏幕阅读器),然后使用伪选择器,例如:之前带有content:''属性,用于根据媒体查询设置替代文本。 Hiding the default span/element as appropriate. 隐藏适当的默认跨度/元素。

(*) I would say consider your content and see if you can find a universal label for these items is probably better practice though. (*)我想说的是考虑一下您的内容,看看是否可以找到这些项目的通用标签可能是更好的做法。

You could use media queries, pseudo classes and some ingenuity for this: 您可以为此使用媒体查询,伪类和一些独创性:

 a[data-mobiletext] { background-color: #FC0; } @media screen and (max-width: 700px) { a[data-mobiletext] { background-color: #CF0; } a[data-mobiletext] span { display: none; } a[data-mobiletext]:after { content: attr(data-mobiletext); } } 
 <a href="/" data-mobiletext="Read"><span>Read more</span></a> <a href="/" data-mobiletext="Export"><span>Download PDF</span></a> <a href="/" data-mobiletext="Tap here"><span>Click here</span></a> 

Click "Full Page" to view Desktop version. 单击“整页”以查看桌面版本。

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

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