skip to Main Content

I am newbie in web desgin and css, and I need to make the scroll of sidebar div on the right side not left side

The HTML Direction is from Right to Left

I do not want Sidebar on left but only Scroll not Sidebar itself

I tried but I cannot get any solution, I am tried to use overflow-y and overflow-x but not work

* {
    margin: 0;
    padding: 0;
}

body {
    font-family: "Poppins", sans-serif;
    font-size: 16px;
    color: #1a1a1a;
}

.sidebar-link {
    text-decoration: none !important;
}

    .sidebar-link:hover {
        text-decoration: none !important;
    }

.sideBar li {
    list-style-type: none;
    margin-bottom: 0px;
}

.sideBar {
    z-index: 1000;
    background: #273c75;
    position: fixed;
    top: 10px;
    left: auto;
    padding: 40px 30px;
    box-shadow: 0 10px 20px #00000030;
    border-radius: 10px;
    max-height: 1000px;
    width: 120px;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease;
    overflow-y: scroll;
    overflow-x: hidden;
}

    .sideBar .navLinks {
        width: 100%;
    }

        .sideBar .navLinks li {
            border-radius: 15px;
            padding: 5px;
        }

            .sideBar .navLinks li a {
                padding-right: 15px;
            }

    .sideBar .link {
        display: flex;
        height: 30px;
    }

    .sideBar .link-text {
        color: #fff;
        font-weight: 600;
        font-size: 16px;
        transform: scaleX(0);
        transform-origin: right;
        transition: all 0.2s ease;
        font-family: CairoFont;
    }

    .sideBar .link-icon {
        color: #fff;
        flex-basis: 30px;
        font-size: 21px;
        margin-left: 15px;
    }

    .sideBar .text-muted {
        color: #ccc;
        font-size: 21px;
        padding: 10px 0px;
        font-family: CairoFont;
    }

    .sideBar .navLinks li:hover {
        background: #fff;
    }

        .sideBar .navLinks li:hover .link > * {
            color: #2C3A47;
        }

    .sideBar:hover .link-text {
        transform: scaleX(1);
    }

    .sideBar:hover {
        width: 280px;
        align-items: flex-start;
    }
<!DOCTYPE html>
<html dir="rtl">
<head>
    <meta charset="UTF-8">
    <title>Test</title>
</head>
<body>
    
    

    <nav class="sideBar">

        <p class="text-muted">Test</p>
        <ul class="navLinks">
            <li>
                <a href="#" class="link sidebar-link">
                    
                    <span class="link-text">Text Link 1</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">
                    
                    <span class="link-text">Text Link 2</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">
                    
                    <span class="link-text">Text Link 3</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">
                    
                    <span class="link-text">Text Link 4</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">
                    
                    <span class="link-text">Text Link 5</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 6</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 7</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 8</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 9</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 10</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 11</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 12</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 13</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 14</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 15</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 16</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 17</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 18</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 19</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 20</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 21</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 22</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 23</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 24</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 25</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 26</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 27</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 28</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 29</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 30</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 31</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 32</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 33</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 34</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 35</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 36</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 37</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 38</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 39</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 40</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 41</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 42</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 43</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 44</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 45</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 46</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 47</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 48</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 49</span>
                </a>

            </li>
            <li>
                <a href="#" class="link sidebar-link">

                    <span class="link-text">Text Link 50</span>
                </a>

            </li>
        </ul>

    </nav>

    <main>
        
    </main>


</body>
</html>

2

Answers


  1. If you just want to put the sidebar on the right, don’t change the text directionality. One good solution is to use a grid.

    :root {
      --clr-dark-blue: #273c75;
    }
    
    body {
      font-family: sans-serif;
      font-size: 16px;
      color: #1a1a1a;
      display: grid;
      grid-template-columns: auto 150px;
      margin: 0;
      background: aliceblue;
    }
    
    main {
      padding: 0 1em;
      grid-row: 1;
      grid-column: 1;
    }
    
    nav {
      grid-row: 1;
      grid-column: 2;
      margin-top: 1em;
      background: var(--clr-dark-blue);
      padding: 1em 0.5em 1em 1em;
      box-shadow: 0 10px 20px #00000030;
      border-radius: 0.5em 0 0 0.5em;
      display: flex;
      flex-direction: column;
      transition: width 0.2s ease;
      overflow-y: scroll;
      overflow-x: hidden;
      grid-column: 2;
      align-self: start;
    }
    
    nav, nav a {
      color: white;
    }
    
    nav ul {
      list-style: none;
      margin: 0;
      padding: 0;
      text-align: right;
    }
    
    nav a {
      display: inline-block;
      text-decoration: none;
      padding: 0.5em;
    }
    
    nav a:hover {
      color: var(--clr-dark-blue);
      background: white;
      border-radius: 5px;
    }
    
    .text-muted {
      margin-top: 0;
      color: #ccc;
      font-size: 21px;
    }
    <nav>
      <p class="text-muted">Test</p>
      <ul>
        <li><a href="#">Text Link 1</a></li>
        <li><a href="#">Text Link 2</a></li>
        <li><a href="#">Text Link 3</a></li>
        <li><a href="#">Text Link 4</a></li>
        <li><a href="#">Text Link 5</a></li>
        <li><a href="#">Text Link 6</a></li>
        <li><a href="#">Text Link 7</a></li>
        <li><a href="#">Text Link 8</a></li>
        <li><a href="#">Text Link 9</a></li>
        <li><a href="#">Text Link 10</a></li>
        <li><a href="#">Text Link 11</a></li>
        <li><a href="#">Text Link 12</a></li>
        <li><a href="#">Text Link 13</a></li>
        <li><a href="#">Text Link 14</a></li>
        <li><a href="#">Text Link 15</a></li>
        <li><a href="#">Text Link 16</a></li>
        <li><a href="#">Text Link 17</a></li>
        <li><a href="#">Text Link 18</a></li>
        <li><a href="#">Text Link 19</a></li>
        <li><a href="#">Text Link 20</a></li>
        <li><a href="#">Text Link 21</a></li>
        <li><a href="#">Text Link 22</a></li>
        <li><a href="#">Text Link 23</a></li>
        <li><a href="#">Text Link 24</a></li>
        <li><a href="#">Text Link 25</a></li>
        <li><a href="#">Text Link 26</a></li>
        <li><a href="#">Text Link 27</a></li>
        <li><a href="#">Text Link 28</a></li>
        <li><a href="#">Text Link 29</a></li>
        <li><a href="#">Text Link 30</a></li>
      </ul>
    </nav>
    
    <main>
    
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tempor nunc mauris, sit amet placerat tortor lobortis dapibus. Nam lectus eros, maximus ac magna vel, congue consequat eros. Fusce id pretium diam. Cras sit amet pharetra ante. Sed quis commodo quam, vel facilisis ipsum. Vestibulum sodales iaculis arcu, et fringilla nisi ullamcorper sed. Donec interdum sit amet est non accumsan. Donec non augue feugiat, fermentum nunc non, convallis est. Cras vel ligula nec odio faucibus ultricies. Sed vulputate tortor eget pretium convallis. Cras interdum elit eget mi porta suscipit. Morbi ut velit diam. Etiam finibus eros et efficitur rutrum. Quisque viverra metus ac eleifend imperdiet. Quisque pretium ut purus vitae tempus. Duis varius risus congue velit faucibus, sed interdum purus consectetur.</p>
      <p>Cras volutpat velit non mi sagittis condimentum. Cras tempor aliquet turpis sed pretium. Nunc aliquet sodales turpis quis ultrices. Duis auctor accumsan enim, quis maximus ex malesuada a. Donec a felis ut erat tempus euismod non vel neque. Proin lectus massa, sagittis at imperdiet nec, consequat ut neque. Sed vel placerat neque, vel varius urna. Vivamus interdum euismod urna a accumsan. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p>
      <p>Nulla rhoncus aliquam mauris, eu pretium dolor auctor in. Maecenas a sollicitudin dolor, eget commodo quam. Proin et dui sed ligula vulputate egestas. Quisque eget augue vitae purus placerat pharetra. Aliquam rhoncus convallis lorem, sed facilisis odio blandit scelerisque. Vivamus viverra urna ac nulla interdum, eget ullamcorper leo maximus. Mauris nec feugiat enim. Nam congue, dui sit amet vestibulum posuere, leo mauris fermentum lorem, eget bibendum velit nunc quis leo.</p>
      <p>Curabitur eget ullamcorper justo, sit amet dictum neque. Fusce vitae ligula et felis auctor vulputate vel suscipit nibh. Integer a felis varius purus vestibulum viverra. Morbi venenatis placerat augue sit amet commodo. Sed dapibus molestie eros, vitae ultrices nunc commodo aliquam. Vivamus tempus mollis massa vel egestas. Donec ut ante quis eros commodo volutpat. Proin sem nisi, viverra ac sem tristique, consectetur laoreet sapien. Vivamus suscipit orci vel euismod scelerisque. Nullam sed pulvinar tellus. Nullam pulvinar arcu eget nibh rutrum, eget faucibus ligula ullamcorper.</p>
      <p>Sed sed cursus leo. Nam molestie eleifend leo, nec fermentum risus maximus ac. Pellentesque eget placerat ipsum. Vestibulum tempor quam justo. Fusce dapibus turpis non ante faucibus suscipit. Fusce rhoncus eleifend ipsum et lacinia. Curabitur nec congue arcu. Mauris dignissim magna ligula. Nullam ultrices, metus sit amet ultrices porttitor, turpis ligula interdum enim, eu pellentesque purus quam ut arcu. Nullam aliquet vitae tortor vel tincidunt. Fusce maximus lacus diam, sed elementum ligula condimentum vel. Sed consequat orci ac nunc gravida, at accumsan magna porttitor.</p>
      <p>Mauris vulputate quam ac purus laoreet, nec ultrices eros placerat. Fusce id nisi ex. Nunc ornare tellus nisl, suscipit fermentum quam sodales sit amet. Ut ex magna, tempor nec ex sed, ornare ornare sem. Proin gravida turpis urna, vitae posuere purus consequat sit amet. Donec laoreet tempor massa. Praesent porta mauris vitae neque condimentum, non volutpat felis eleifend.</p>
      <p>Aliquam aliquam a est eget cursus. Ut eu tempus justo, rutrum dapibus ex. In hac habitasse platea dictumst. Nulla ornare nisi sit amet arcu semper maximus. Praesent eu augue eget mi sodales sodales. Praesent sodales neque malesuada, euismod est in, lobortis turpis. Nam blandit facilisis mauris. Ut ac ex rhoncus, ornare velit ac, aliquam nibh. Quisque euismod mauris quis nisl consectetur vulputate. Pellentesque mattis, tellus ut dictum dictum, urna ligula sodales magna, euismod malesuada ipsum quam nec elit.</p>
    
    </main>
    Login or Signup to reply.
  2. When your sidebar is set to right side, the scroll bar usually appears on the left side. To add the scroll bar to the right side of the sidebar you can achieve it by adding one line of CSS.

    direction: ltr;

    This will move the scroll bar to the right side

    .sideBar {
    z-index: 1000;
    background: #273c75;
    position: fixed;
    top: 10px;
    left: auto;
    padding: 40px 30px;
    box-shadow: 0 10px 20px #00000030;
    border-radius: 10px;
    max-height: 1000px;
    width: 120px;
    display: flex;
    flex-direction: column;
    transition: width 0.2s ease;
    overflow-y: scroll;
    overflow-x: hidden;
    direction: ltr;
    

    }

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search