html - bootstrap float 标签方向为rtl时滑动到中心

标签 html css bootstrap-5 direction

我正在尝试使用 bootstrap v5.2 以希伯来语显示 float 标签。 问题是,当我单击输入框时将方向更改为 rtl 时,标签会向中间滑动。

我的代码:

<div class="form-floating mb-3" dir="rtl">
        <input class="form-control" id="title" placeholder="כותרת"></input>
        <label for="title">כותרת</label>
</div>

You can see that the text moves to the center and does not stay adjacent to the right

我尝试仅在标签中将方向更改回 ltr,它有效,但在希伯来语中看起来不太好(粘在框的左侧)。

最佳答案

添加自定义类并使用这些 CSS 代码:

<style>
    .form-floating.custom-class>label {
        top: 0;
        right: 0;
        transform-origin: 100% 0;
        transition: opacity .1s ease-in-out,transform .1s ease-in-out;
    }
    .form-floating.custom-class>.form-control-plaintext~label, .form-floating.custom-class>.form-control:focus~label, .form-floating>.form-control:not(:placeholder-shown)~label, .form-floating>.form-select~label {
        opacity: .65;
        transform: scale(.85) translateY(-0.5rem) translateX(-0.15rem);
    }
</style>


<div class="form-floating mb-3 custom-class" dir="rtl">
    <input class="form-control" id="title" placeholder="כותרת"></input>
    <label for="title">כותרת</label>
</div>

关于html - bootstrap float 标签方向为rtl时滑动到中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75734889/

相关文章:

javascript - 将 JSON 文件导入 Highcharts 以实现条形图可视化

javascript - 如何从 webpack 入口点排除文件

jquery - CSS 或 jQuery 高度继承问题

javascript - 在元素上使用 css 属性内容异常存储 javascript 的信息

html - 如何根据行中的一列将行居中?

css - 如果目录不在 ScrollView 中则显示 Div

java - 可以使用 Java 库转换为 HTML 和 LaTeX 的轻量级文本标记语言?

html - 使用Bootstrap的显示属性d-none d-md-block和d-flex的冲突

html - 使用 Bootstrap 在容器内对齐步进器 div

html - Bootstrap Navbar 的颜色不会改变