Bootstrap navigation bar set vertically (rotated at -90 degrees)

Is there a way to achieve vertical alignment for Bootstrap Nav items like this example:

https://i.sstatic.net/xCQ9c.png

I am specifically not looking to create a layout where the items are stacked horizontally below each other.

I attempted using transform:rotate(-90deg); on .list-group-item, but it seems that rotational transformation is applied after elements are already aligned on the page. This would require manually positioning each element with JavaScript. I'm seeking a CSS-only solution that is clean and doesn't involve any workarounds.

Answer №1

(edit) This is my first attempt at creating a vertical text using the CSS properties writing-mode: vertical-lr and transform: rotate(180deg);. I have also included some additional CSS to make it function properly or as a starting point (even though flex isn't necessary, I tend to use it frequently for navbars...)

Codepen link: I find this clearer than the snippet provided below because I was able to utilize Autoprefixer (as well as Normalize and LESS which Bootstrap 3 uses, however Sass can be used here - especially if you are already familiar with Bootstrap 4 alpha as the syntax is identical for both).

If Autoprefixer is not being utilized, the result would look like:

.nav-tabs {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
    -ms-flex-flow: column nowrap;
        flex-flow: column nowrap;
    -webkit-box-align: start;
        -ms-flex-align: start;
            align-items: flex-start;
  }
.nav-tabs > li {
    -webkit-writing-mode: vertical-lr;
        -ms-writing-mode: tb-lr;
            writing-mode: vertical-lr;
    -webkit-transform: rotate(180deg);
            transform: rotate(180deg);
    -webkit-transform-origin: center center;
            transform-origin: center center;
    list-style-type: none;
}
.nav-tabs > li > a {
  display: block;
  padding: 0.6rem 1rem;
  background-color: beige;
}
<ul class="nav nav-tabs">
  <li role="presentation" class="active"><a href="#">Home</a></li>
  <li role="presentation"><a href="#">Profile</a></li>
  <li role="presentation"><a href="#">Messages</a></li>
</ul>

I did not include any existing CSS from Bootstrap for this particular component, so you will need to override numerous declarations. However, I followed the same selectors like *** > li > a and copied the HTML structure from the documentation.

The reason behind my approach is that rotating by +/- 90 degrees is never straightforward. The width becomes height, and vice versa, leading to messy content display. Therefore, I opted to write text vertically using writing-mode and then rotated it half a complete turn to match your design specifications. By doing so, the dimensions of each element remain unchanged without any surprises ;)

Answer №2

In my opinion, the proper approach would be to utilize transform:rotate(-90deg); on the wrapper element which contains all list items, whether it is the main <ul> or a higher level container. This way, everything will be rotated as a cohesive unit.

Answer №3

My second response, utilizing Flexbox positioning and incorporating transformations

Check out my Codepen demo here

.nav-tabs {
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
    -ms-flex-flow: row-reverse nowrap;
        flex-flow: row-reverse nowrap;
    -webkit-box-pack: end;
        -ms-flex-pack: end;
            justify-content: flex-end;
  -webkit-transform: rotate(-90deg) translateX(-100%);
          transform: rotate(-90deg) translateX(-100%);
  -webkit-transform-origin: 0% 0%;
          transform-origin: 0% 0%;
  padding-left: 0;
}
.nav-tabs > li {
  list-style-type: none;
}
.nav-tabs > li  > a {
  display: block;
  padding: 9.6px 16px;
  padding: 0.6rem 1rem;
  background-color: beige;
}
<ul class="nav nav-tabs">
  <li role="presentation" class="active"><a href="#">Home</a></li>
  <li role="presentation"><a href="#">Profile</a></li>
  <li role="presentation"><a href="#">Messages</a></li>
</ul>

The items are arranged from right to left horizontally using flex-direction: row-reverse, with the intention of applying

transform: rotate(-90deg)</code later on. However, this wouldn't work properly on a wide flex container, so I switched to <code>inline-flex
which brought the navbar closer to its final position.
Taking into account the transform-origin, rotation, and adjusting position with translateX() to move… vertically (due to the previous rotation, it can be a bit confusing)

UPDATE: For a comprehensive guide on Flexbox, visit CSS-tricks

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

Codignator does not attach the array elements together

While building a registration form for my website, I encountered an issue with passing single element values into an array in CodeIgniter. The values are not being passed correctly, resulting in an error message about an empty alert. How can I resolve th ...

Adapting Classes in Javascript Based on Screen Width: A Step-by-Step Guide

I'm dealing with two separate menus - one for mobile version and one for PC version. However, the mobile menu seems to be overlapping/blocking the PC menu. How can I resolve this issue? I've attempted various solutions such as removing the mobil ...

Reduce the width beyond the necessary limit

I'm struggling to adjust the width of an image to match it with the card size without stretching it or breaking the layout. Most solutions I've come across recommend using inline-block, but this doesn't work well for smaller images. It seems ...

What is the most efficient method for implementing uniform rounded corners in HTML/CSS across different web browsers?

Is there a simple way to achieve cross-browser compatibility without a lot of tedious work? I'm looking for a solution that works effortlessly on IE7+, FF2+, and Chrome, without resorting to using tables which may be outdated. Is there a middle ground ...

Transitioning from container to container-fluid class for tablets using bootstrap

I'm currently utilizing the container class in my project and I'm looking for an elegant way to switch it to container-fluid or adjust the width to resemble container-fluid when the website is viewed on a tablet, so it utilizes the full width of ...

What is the best way to include multiple font styles for different tags?

While working on a website project, the client requested to use Roboto as the main font (by Google). Different styles of Roboto such as Roboto Thin or Roboto Light were used for various elements on the page. However, I utilized the @font-face selector to e ...

Using PHP variables in CSS styling

Let me explain the situation. In my index.php file, I have a class called 'rectangles' which includes properties for color and size. I defined a variable named $rectangle($rectangle=new rectangles('red',25);). Additionally, I include ...

Ways to personalize an image within a table cell using HTML

I need some advice on adjusting the size of an image that I have inserted into a cell of a table on my html page. Can someone please guide me on how to do this? Thank you! ...

Is there a way to soften the repetitive elements in the background image?

Is there a method to blur the part of a background image that is repeated, such that if it is positioned in the center, the sides of the image appear blurry as well? ...

HTML: A peculiar table setup with an image displayed on the right side and text aligned to the left side. Strangely, the

Just starting out and seeking assistance <table style="border:none" cellpadding="0" cellspacing="0"> <tbody> <tr> <td style="border:none" valign="top" vertical-align:"top"; width="20%"> <div><img class= ...

Adjustments made to the size of the h1 font

I am perplexed by the fact that these two h1 tags have different font sizes, even though they have identical properties and declarations. From what little knowledge I have, it seems like it may be related to inheritance; considering one h1 tag is nested an ...

Tips for utilizing the viewport to ensure that mobile devices adjust to the width of the content

Currently, I am designing a book reader where the width of the book can vary, ranging from 1028px to 2000px to 560px. I want mobile devices to automatically scale the book to fit the screen width when viewing it. This is what I have been doing so far wit ...

applying hover effect to text within a table

After investing some time into solving this issue, I am still struggling to find a solution. Essentially, what I want is for the :hover pseudo-class to trigger the border-bottom effect only when I hover over the text in a table. Currently, the :hover pseu ...

Tips for aligning divs in Zurb Foundation 3 framework

My design conundrum involves a 12 column row and trying to make a series of four div blocks stay in a row without stacking as the browser size decreases. Currently, the divs start to stack when the browser gets smaller. I have 4 divs that should be displa ...

align the p tag vertically next to the image

I'm struggling to get a p tag vertically aligned next to an image. The issue is that only the first line of text aligns properly. How can I make the text in the p tag wrap around the image while maintaining vertical alignment? Here is the HTML code: ...

Mobile Mode Issue with Bootstrap 4 Navbar Example

Currently, I am exploring the Bootstrap material and trying to understand how to integrate their content with a jinja2 file that I am preparing for a django project. Upon attempting to copy and paste their example code (specifically this example http://get ...

Is it possible to override Bootstrap or not?

It's quite a puzzle to figure out when I can and cannot override Bootstrap classes or IDs with custom CSS. For instance, it seems easy enough to change the default navbar-dark background and font style, but altering the font color and size proves to ...

Can you tell me which specific font Adobe Edge Code (Brackets) uses in its code editor?

Can someone please help me? I'm trying to identify the syntax highlighter being used in this code. Is it Prettify or something else? ...

Tips for creating two divs next to each other with inline-block?

Is there a way to align the divs side by side and have the 'contentwrapper' div responsive to the resizing of the browser window? HTML <div id="maincontainer"> <div id="leftcolumn">&nbsp;</div> <div id="contentwrapper ...

The functionality is not operating correctly on Internet Explorer

This code is functioning properly in Mozilla and Opera, but it is not working in IE. Any assistance on this issue would be greatly appreciated. The JavaScript is working fine, however, in IE 10 only the back panel is displayed. Thank you for your help. h ...