Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7855293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:20:27+00:00 2026-06-02T20:20:27+00:00

I have an HTML django template page that is both RTL and LTR (depends

  • 0

I have an HTML django template page that is both RTL and LTR (depends on user’s locale).

The CSS of this page is stored in another file, and that file is currently static.

What is the best way to switch the attribute left and right according to the locale? Is there a built in attribute in CSS for this problem? (I don’t want to use JS, it feels too messy)

I have:

.elem{
    left: 10px; 
    bottom: 10px;
    position: absolute;
}

I want something like this:

.elem{
    right-or-left-according-to-html-dir: 10px; 
    bottom: 10px;
    position: absolute;
}

Currently the only option I can think of is turning the file into a template also:

.elem{
    {{dir}}: 10px; 
    bottom: 10px;
    position: absolute;
}

Is there a better way that will let me keep my CSS file static?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:20:28+00:00Added an answer on June 2, 2026 at 8:20 pm

    You say you’re making the document rtl or ltr depending on locale. In that case you can use the :lang() selector to make certain parts of your document have styling depending on the locale.

    • http://www.w3.org/wiki/CSS/Selectors/pseudo-classes/:lang
    • http://www.w3.org/TR/css3-selectors/#lang-pseudo

    If you want a little more support (IE7+) you could use the attribute selector selector[lang='en'] though that will only test the attribute on the specified selector.

    • http://www.w3.org/TR/css3-selectors/#attribute-selectors

    If you specify the language in the html element (which you should, with lang="en" for example) you can just put the html selector in front of the class you want to apply in certain locales:

    .elem {
        margin: 0 10px 0 0;
        color: blue;
    }
    
    html[lang='en'] .elem {
        margin: 0 0 0 10px;
    }
    

    Even better, if you specified the dir attribute you can directly use that in css like so:

    .elem[dir='rtl'] {
        margin: 0 10px 0 0;
    }
    

    Please note that with a class on the body element you will always depend on that class always being there. But the dir and lang attribute can be specified on a more specific scope, like a single div, and still be used in the css along with styles for the ‘other’ reading directions.

    Edit

    Lastly, to gaze into the future, the CSS Selectors ‘Level 4’ will include a psuedo tag which will be able to filter on text directionality. Of course the specs are in development and adoption by browsers may take years before it is possible to reliably use it:

    http://dev.w3.org/csswg/selectors4/#dir-pseudo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base template in Django and several html files that are children
I have a page, index.html, that contains both a login and registration form. I
I am new to the Django web framework. I have a template that displays
I have a page which displays a form that a logged-in user can use
I have a Django template that contains a Javascript function, like so: <a class
Say there exists a template x.html in Django templates section. The contents of this
I have a Django form that is part of page. Lets say I have
I'm kind of confused by this because it seems that Django templates have optional
In one of my Django templates, I have a chunk of HTML which repeats
How do I serve a dynamically generated image in Django? I have an html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.