如何在Ionic 7标签或输入中换行文本,因为之前的答案不再适用。

huangapple go评论115阅读模式
英文:

How do I wrap text in ionic 7 labels or inputs as pervious answers no longer work

问题

以下是您要翻译的内容:

在以前的ionic版本中,您可以使用<ion-label class="ion-text-wrap"或

.item.sc-ion-label-md-h,.item .sc-ion-label-md-h {
white-space: normal !important;
}

.item.sc-ion-label-ios-h,.item .sc-ion-label-ios-h {
white-space: normal !important;
}

以下是ionic文档中的一些示例

html

<ion-input class="custom" label="Long Long Long Text Here"></ion-input>

scss

ion-input.custom {
--background: #373737;
--color: #fff;
--padding-end: 10px;
--padding-start: 10px;
--placeholder-color: #ddd;
--placeholder-opacity: 0.8;
}

我尝试添加

--white-space: normal !important;

ionic似乎正在摆脱

<ion-label>Label Here</ion-label>

任何帮助将不胜感激。

英文:

In previous versions of ionic you could use <ion-label class="ion-text-wrap"

or

.item.sc-ion-label-md-h, .item .sc-ion-label-md-h{
  white-space: normal !important;
 }

 .item.sc-ion-label-ios-h, .item .sc-ion-label-ios-h{
   white-space: normal !important;
 }

Here are some examples of what the ionic docs say

html

&lt;ion-input class=&quot;custom&quot; label=&quot;Long Long Long Text Here&quot;&gt;&lt;/ion-input&gt;

scss

ion-input.custom {
   --background: #373737;
   --color: #fff;
   --padding-end: 10px;
   --padding-start: 10px;
   --placeholder-color: #ddd;
   --placeholder-opacity: 0.8;
  }

I tried adding

--white-space: normal !important;

ionic seems to be moving away from

&lt;ion-label&gt;Label Here&lt;/ion-label&gt;

Any help would be appreciated.

答案1

得分: 1

这是我遇到的同样问题,以下是我想出来的解决方法:

  1. 为了保持一致性,我将内置的 ion-text-wrap 类添加到我想要包装标签的元素上,例如 ion-inpution-textarea
  2. 然后我在 global.scss 中添加了以下规则:
[label].ion-text-wrap .label-text-wrapper &gt; .label-text {
	white-space: normal;
}

这对我有帮助,希望对你也有帮助。

英文:

I faced the same issue, and here is what I came up with:

  1. For consistency, I added the built-in ion-text-wrap class to the elements whose label I want to be wrapped, e.g., ion-input or ion-textarea.
  2. And I added the following rule to global.scss:
[label].ion-text-wrap .label-text-wrapper &gt; .label-text {
	white-space: normal;
}

It helped me, and I hope it will help you too.

答案2

得分: 0

这是ionic 7中的一个错误,在任何地方<ion-label>被替换为labelPlacement=""。您不再能够换行文本。我将把我的项目转回ionic 6。

英文:

This is a bug in ionic 7 any where <ion-label> has been replaced labelPlacement="". you no longer have the ability to wrap text. I will convert my project back to ionic 6

huangapple
  • 本文由 发表于 2023年5月18日 02:19:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76275113.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定