Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get dir="rtl" to work with bootstrap 4.3.1?

I am creating a simple html/css page using bootstrap 4.3.1 . In one paragraph, I will be using some arabic text which needs to show up in a right-to-left format.

I have tried to use direction:rtl in css , dir="rtl" in html and bidi-override as well. But nothing seems to be working. I think it has got something to do with bootstrap 4.3.1 but I could be wrong. I am unable to understand where I am going wrong and would greatly appreciate any help.

This is my html

<div class="row justify-content-center">
  <div class="col-sm-6" style="border:1px solid black">
    <div class="row">
      <div class="ayat_box">
        <div class="ayat_ar">
          <p class="ayat_ar_txt">
            حَتَّى إِذَا جَاءَ أَمْرُنَا وَفَارَ التَّنُّورُ قُلْنَا احْمِلْ فِيهَا مِنْ كُلٍّ زَوْجَيْنِ اثْنَيْنِ وَأَهْلَكَ إِلَّا مَنْ سَبَقَ عَلَيْهِ الْقَوْلُ وَمَنْ آَمَنَ وَمَا آَمَنَ مَعَهُ إِلَّا قَلِيلٌ  <span class="ayat_period">٣</span>
          </p>
        </div>
        <div class="ayat_en">
          <p class="ayat_en_txt">
some content in ltr
          </p>
        </div>
        <div class="ayat_exp">
          <p class="ayat_exp_p">
some content in ltr
          </p>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="ayat_box" style="background: pink">
        This is another box
      </div>
    </div>
  </div>
</div>

This is my css:

.ayat_box
{
    width: 700px;
    margin:0 auto;
}

.ayat_ar
{
    background: pink;
}

.ayat_ar_txt
{
    direction:rtl;
    font-family: arial;
    font-size:25px;
}

.ayat_period
{
  display:inline-block;
  border-radius:50%;
  border:1px solid black;
  padding-left:5px;
  padding-right:5px;
}
like image 206
Shah Quadri Avatar asked Apr 27 '19 11:04

Shah Quadri


People also ask

How to rtl in bootstrap?

There are two strict requirements for enabling RTL in Bootstrap-powered pages. Set dir="rtl" on the <html> element. Add an appropriate lang attribute, like lang="ar" , on the <html> element.

How do I use RTL in CSS?

The direction CSS property sets the direction of text, table columns, and horizontal overflow. Use rtl for languages written from right to left (like Hebrew or Arabic), and ltr for those written from left to right (like English and most other languages).

What is LTR and RTL?

For example, the en-US locale (for US English) specifies left-to-right. Most Western languages, as well as many others around the world, are written LTR. The opposite of LTR, RTL (Right To Left) is used in other common languages, including Arabic ( ar ) and Hebrew ( he ).

How do I get bootstrap 4?

There are two ways to start using Bootstrap 4 on your own web site. You can: Include Bootstrap 4 from a CDN. Download Bootstrap 4 from getbootstrap.com.


1 Answers

Just add text-right to align text right and dir="rtl" to make the right-to-left direction:

          <p class="ayat_ar_txt text-right" dir="rtl">
            حَتَّى إِذَا جَاءَ أَمْرُنَا وَفَارَ التَّنُّورُ قُلْنَا احْمِلْ فِيهَا مِنْ كُلٍّ زَوْجَيْنِ اثْنَيْنِ وَأَهْلَكَ إِلَّا مَنْ سَبَقَ عَلَيْهِ الْقَوْلُ وَمَنْ آَمَنَ وَمَا آَمَنَ مَعَهُ إِلَّا قَلِيلٌ  <span class="ayat_period">٣</span>
          </p>
like image 147
عمر حمدان أبوروك Avatar answered Oct 21 '22 13:10

عمر حمدان أبوروك