css - 我如何使表单输入 rtl 没有很多重复项

标签 css laravel bootstrap-4

如果区域设置如何使表单 RTL 不是英语,有没有一种方法可以更改 CSS 中的区域设置,而不是为每个输入重复大量代码以使其 RTL,如果条件为真?

例如:

    <div class="form-group" id="form-group-name">
    <label for="name" class=" control-label {{ app()->getLocale() == 'ar' ? 'float-right' : ''}}">{{ __('user.User') }}</label>
    <div class="col-sm-12">
        <input type="text" id="name" name="name"
               value="{{ isset($user->name) ? $user->name :'' }}" maxlength="50" required=""
               class="form-control {{ app()->getLocale() == 'ar' ? 'text-right' : ''}}">
        <span style="color: red" class="help-block {{ app()->getLocale() == 'ar' ? 'float-right' : ''}}"></span>
    </div>

</div>

我不想在每个输入中重复所有条件。

最佳答案

如果您使用的是 bootstrap4,只需将文档的方向更改为 RTL

所以你必须这样做

body {direction:rtl} 

在“RTL 方向”的外部 rtl css 文件中,将其放在要覆盖的主要 css 样式之后。

另一种方法是在主 css 文件的末尾编写 rtl 样式 css 数据,但通过与 rtl 版本相关的任何 html 属性检测每个类

喜欢:

html[lang="ar"] body {
  direction:rtl
}
/* the same for any other elements */
html[lang="ar"] .class-name {
  padding-left:0;
  padding-right:20px
}

关于css - 我如何使表单输入 rtl 没有很多重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58185276/

相关文章:

html - bootstrap + django,包装卡

html表格单元格间距在div中不起作用

javascript - DZSlides 如何缩放视口(viewport)内容?

php - Laravel,验证 alpha_dash 防止破折号

php - 将 laravel jenssegers 连接到 mongodb atlas 集群

javascript - 模态内的表单输入不可点击

css - Bootstrap 4 right Column on top on mobile view

html - 添加 anchor 标记后,图标不会在悬停时改变颜色。

css - 使用 Bootstrap 的移动设备上 <body> 的空白左边距

php - Laravel - 通过 View 传递对象并在 Blade 中使用