What is the best way to arrange inline elements in RTL mode?

I'm currently working on creating an RTL version of the website, but I'm encountering a challenge with a specific layout:

.content {
  width: 200px;
}

.content.rtl {
  direction: rtl;
  text-align: right;
}
<h5 class="content">
  <span>3</span> <span>h</span> &nbsp; <span>45</span> <span>min</span>
</h5>
<h5 class="content rtl">
  <span>3</span> <span>h</span> &nbsp; <span>45</span> <span>min</span>
</h5>

The first h5 tag is currently displaying content as "3h 45min", but I want the second tag to display it as "min45 h3" in reverse order.

However, instead of the desired output, I am getting "h 45min 3" and I'm unsure why this is happening.

Can anyone provide suggestions on how to resolve this issue with the layout?

Answer №1

To achieve the desired layout, simply apply the CSS rule flex-direction: row-reverse

.content
{
width: 200px;
}
.content.rtl
{
display:flex;
  -webkit-flex-direction: row-reverse; 
  flex-direction: row-reverse;
}
<h5 class="content">
<span>3</span>
<span>h</span>
&nbsp;
<span>45</span>
<span>min</span>
</h5>
<h5 class="content rtl">
<span>3</span>
<span>h</span>
&nbsp;
<span>45</span>
<span>min</span>
</h5>
 Run code snippetCopy snippet to answerExpand snippet

Implementing the use of flex direction can help in achieving the desired result.

Answer №2

To make the spans inline-block, simply add display: inline-block to them.

.content {
  width: 200px;
  border: solid 1px black;
}

.content.rtl {
  direction: rtl;
  text-align: right;
}

span {
  display: inline-block;
}
<h5 class="content">
  <span>3</span>
  <span>h</span> &nbsp;
  <span>45</span>
  <span>min</span>
</h5>
<h5 class="content rtl">
  <span>3</span>
  <span>h</span> &nbsp;
  <span>45</span>
  <span>min</span>
</h5>

Answer №3

dir impacts a span element, however, the span itself will not be right-aligned as expected, only its content.

If you want to see the effect on span, try ending it with a period - the period will appear on the left side rather than the right.

A div is a display:block object, which means it spans the entire width allowing text alignment within it. On the other hand, a span is display:inline, so it behaves like part of the text, similar to a single letter in a simplistic sense.

(It is worth noting that having a block element nested inside an inline element is considered invalid)

Experimenting with right-to-left directionality using div and span: <br />
<span>(span) Hello World!</span> <br />
<span dir='rtl'>(span rtl)  Hello World!</span>
<div>(div) Hello World!</div>
<div dir='rtl'>(div rtl) Hello World!</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Copying to the clipboard now includes the parent of the targeted element

Edit - More Information: Here is a simplified version of the sandbox: https://codesandbox.io/s/stupefied-leftpad-k6eek Check out the demo here: https://i.sstatic.net/2XHu1.jpg The issue does not seem to occur in Firefox, but it does in Chrome and other ...

real-time updating of a list in a Jquery and Asp.net web app

In my asp.net application, I have the following code snippet: <div class="divparent" > <div class="child1" ><label> Occupation</label></div> <div class="child2" > <input type="text" name="name" id="Te ...

Error: Attempting to assign a value to the property 'running' of an undefined variable

While working with Nuxt.js, I encountered an issue related to reading the running property of my client object. Here is the HTML code snippet: <b-button v-show="!(projectSelecter(project.ID)).isStarted" //this work just fine variant="success" c ...

Having trouble understanding the differences between Bootstrap 4's .list-inline class and .list-inline-item class?

I am currently utilizing Bootstrap 4 within Wordpress. Strangely, I am facing an issue where I am unable to have list items appear inline (horizontally) solely by using the class .list-inline on the list itself, as shown below: <ul id="dances" class="l ...

In Chrome, there is a conflict between the screen width when using `position: absolute` and `position: fixed` if there is vertical

I'm in the process of developing a website with a video banner set to fixed positioning in the background, and a div that has absolute positioning covering part of the video on the bottom half. However, I've encountered an issue - when I add this ...

When a <dl> element is nested within an <ol>, it will be rendered as a list format

I'm facing an issue with my CSS that affects how different browsers render definition lists embedded within ordered lists. In IE10, the list displays as expected - a bulleted list inside the ordered list without affecting the numbering. However, Firef ...

Adjust the size of a div using absolute positioning

Can a div with absolute position be resized? I need this pink modal to maintain the same width as the input and resize accordingly. This modal will be utilized in a dropdown component, so it should resize along with the input. Moreover, is using absolute ...

PHP function with JSON response encountered an error during the AJAX call

I am currently working on creating a News Ticker that utilizes PHP, Javascript, and AJAX. The first step involved creating a PHP function called getFeed(), which gathers data from various news websites into an Array. This data is then returned in JSON form ...

Is it possible to craft poetic lines with indents in HTML using blockquotes, pre, or dd tags?

I am struggling to format a few lines of text with indentations using HTML. Here is an example I found: HERE Below is my attempt: <p><code>"Knowing is not enough. We</code></p> <p><blockquote><code>must apply. Wi ...

A step-by-step guide on incorporating click and drag events into an HTML Canvas

I have developed a unique business tool using html canvas. It is equipped with a variety of draggable and droppable elements. I personally created the functionality with the following pseudocode: if(mouseIsDown && mouseInBoundsOfIcon){ icon.g ...

Requesting PayPal for an HTTPS transaction

When attempting to call the Express Checkout Paypal API using $http.get(AngularJS), I encountered error 81002(Method Specified is not Supported). However, when I tried calling the API using the search bar in Google Chrome, I was able to retrieve the token ...

Trouble with Flex 3 styles not fully applying to dynamically generated tabs within a TabNavigator

When using ActionScript to dynamically create a tab, I noticed that the style is applied to the skins but not to the text of the newly created tab until I click on another tab and then go back to it. ActionScript private function clickAddTabHandler(event ...

Tips for creating a responsive navbar image alongside your navbar

On my desktop, the navbar appears perfectly. However, when I switch to mobile view, the navbar image does not fit properly and the hamburger menu is missing. See the image below: View Image Here After refreshing the page, the hamburger menu finally shows ...

Activating Cors Support on Firefox

When working with AngularJS, I wrote the following code to make an API call: $http({ method: 'GET', url: 'https://www.example.com/api/v1/page', params: 'limit=10, sort_by=created:desc', //h ...

Prevent uniform width for child elements in flexbox when using flex-direction column

In my navigation bar, I implemented flex with flex-direction column to stack the child elements vertically. However, I am facing an issue where all the child elements have the same width. I want each child element to have its own specific width so that I c ...

What is the purpose of the menu tag if it is not universally supported by all major browsers

While diving into front-end web development, a question popped into my mind. What is the purpose of the menu tag in HTML if it's not universally supported by all major browsers? I came across this tag while inspecting a webpage and decided to do some ...

Please indicate the decimal separator for the Number() function

UPDATE : TITLE IS MISLEADING as testing showed that Number() returned a dot-separated number and the HTML <input type="number"/> displayed it as a comma due to locale settings. I changed to using an <input type="text"/> and filtered keydown lik ...

Alignment issues with columns in Bootstrap

In my layout, I have three columns with a container in each column. However, I am experiencing an unusual display issue: https://i.sstatic.net/CLT1q.png An example of the desired display is shown here: https://i.sstatic.net/4dCru.png The three columns ...

Using PHP's header function to alter directories

So I am currently diving into PHP and facing a challenge with using headers. My setup involves using xampp for development purposes. I have a basic form where users can log in on "index.php". Upon successful login, the header function kicks in to redirect ...

Achieving a sleek line effect with a gradient border

Is there a way to make the gradient border transition between two colors look like a straight line? Additionally, is it possible to have the line start in the bottom left corner instead of the middle of the right side of the button? The current CSS code I ...