Vertical text on rigid bars

Hey there, I've encountered an intriguing problem that's got me stumped.

I'm attempting to create a menu made up of vertical bars that span the full height of the window and have a fixed position. I want the text within these bars to display vertically. Take a look at the sketch I put together:

And you can also view this JSFiddle.

The HTML structure is as follows:

<header>
    header
</header>

<nav>
    <ul>
        <li><a href="#">bar 1</a></li>
        <li><a href="#">bar 2</a></li>
        <li><a href="#">bar 3</a></li>
        <li><a href="#">bar 4</a></li>
    </ul>
</nav>

Here is the corresponding CSS:

header {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 250px;
    padding: 20px;
    background: rgb(42,42,42);
    background: rgba(10,10,10,0.95);
}
nav {
    position: fixed;
    left: 300px;
    width: 100%;
    margin-left: -50%;
    top: 50%;
    height: 75px;

    -webkit-transform: rotate(-90deg);
    -moz-transform: rotate(-90deg);
    -ms-transform: rotate(-90deg);
    -o-transform: rotate(-90deg);
    transform: rotate(-90deg);

    -webkit-transform-origin: 50% 50%;
    -moz-transform-origin: 50% 50%;
    -ms-transform-origin: 50% 50%;
    -o-transform-origin: 50% 50%;
    transform-origin: 50% 50%;

    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
    background: blue;
    border: 2px solid red;
}
nav ul {
    margin: 0;
    padding: 0;
    list-style: none;
    width: 100%;
}
nav ul li {
    width: 100%;
}
nav ul li a {
    display: block;
    width: 100%;
    height: 32px;
    background: #f3b200;
}
nav ul li:nth-child(1) a { background: #c61c05; }
nav ul li:nth-child(2) a { background: #dc572e; }
nav ul li:nth-child(3) a { background: #d27b26; }
nav ul li:nth-child(4) a { background: #f3b200; }

The issue arises when trying to position the nav element as desired. Any measurements (width, height, top position, left position) are applied based on a 0 degree rotation, causing the height to be relative to viewport width rather than height.

I attempted different approaches like rotating the ul and li elements inside the nav, but couldn't achieve the desired positioning for the navigation bar.

If anyone has a pure CSS solution, I'd greatly appreciate the help.

Answer №1

If you're aiming for a design where everything is 100% the height of the page, consider utilizing the natural flow of the page instead of manipulating the position property. Align your navigation beside your header and proceed accordingly. To add a unique touch, try rotating certain sections within your links rather than the whole element. Here's a modified snippet to get you started:

Custom HTML Structure

<header>header</header>
<ul>
    <li><a href="#"><span>bar 1</span></a></li>
    <li><a href="#"><span>bar 2</span></a></li>
    <li><a href="#"><span>bar 3</span></a></li>
    <li><a href="#"><span>bar 4</span></a></li>
</ul>
<div class="other">Plenty of additional content</div>

CSS Styling

html, body {
    margin:0;
    padding:0;
    height:100%;
}
header {
    float:left;
    height:100%;
    width: 250px;
    background: rgb(42, 42, 42);
    background: rgba(10, 10, 10, 0.95);
}
ul{
    float:left;
    display:block;
    margin:0;
    padding:0;
    height:100%;
}
ul li{
    display:block;
    margin:0;
    padding:0;
    float:left;
    height:100%;
}

ul li a{
    display:block;
    height:100%;
}

ul li a span{
    position:relative;
    top:20px;
    color:#FFF;
    display:block;
    -webkit-transform: rotate(-90deg);
    -moz-transform: rotate(-90deg);
    -ms-transform: rotate(-90deg);
    -o-transform: rotate(-90deg);
    transform: rotate(-90deg);
    font-size:26px;
    width:60px;
    direction: rtl;
    white-space: nowrap;
}

Interactive Example on JSFiddle

Answer №2

What are your thoughts on this design?

html:

<div class="mainWrap">
    <header class="mainBody">

    </header>
    <nav>
        <ul>
            <li class="sBar s-1"><span class="rot">Bar 1</span></li>
            <li class="sBar s-2"><span class="rot">Bar 2</span></li>
            <li class="sBar s-3"><span class="rot">Bar 3</span></li>
            <li class="sBar s-4"><span class="rot">Bar 4</span></li>
        </ul>
    </nav>
</div>

css:

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    border: 4px solid red;
}

* {
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
}

ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
}

.mainWrap, .mainWrap nav, .mainWrap ul {
    width: 100%;
    height: 100%;
}

.mainWrap li, .mainWrap header {
    float: left;
}

.mainBody {
    width: 40%;
    height: 100%;
    background: #2b2b2b;
}

.sBar {
    width: 50px;
    height: 100%;
    padding-top: 30px;
    display: block;
}

.s-1 {
    background: #c61c05;
}

.s-2 {
    background: #dc572e;
}

.s-3 {
    background: #d27b26;
}

.s-4 {
    background: #f3b200;
}

.rot {
    -webkit-transform: rotate(-90deg);
    display: block;
}

Fiddle: To see and edit code, remove "show" from the URL

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

Troubleshooting: Dealing with overflow problem in a span element containing an image tag

One issue I encountered involves overflow. A div is set to overflow: hidden, with all elements inside positioned absolutely. These elements consist of a span tag containing text and an image tag. An arrow allows control of the span tag moving forwards or b ...

Preserve the original color of links in CSS by using the `a

Is it feasible to specify in CSS that a link should not change its color and instead use the default one? For example: If I have text displayed in red, and that text is also a hyperlink. Typically, when clicked on, the text would change to blue because i ...

What is the best way to exclude the "table" property from a button inside a row of a table?

I'm currently working with bootstrap and have implemented a table with the property "table" to create a light background for the data pulled from a database. The design looks great, except for when I try to insert a button in each row for editing purp ...

Make the most of your Bootstrap 3 layout by utilizing a full page container that fills both the width and height between a fixed header and

I am currently working on a basic bootstrap page with the Example template from Bootstrap's website. I want the content in the middle to take up the space between the header and footer, while ensuring that both the header and footer remain visible at ...

Opening a Material Dialog automatically scrolls the body to the top of the page

I'm currently using Material UI within a React application and I'm facing an issue where opening a dialog causes the body of my page to scroll to the top. This behavior also occurs when opening a Material Popover or a Material TextBox selector. D ...

What are some methods for identifying a single attribute element that is duplicated elsewhere on a webpage?

<html> <tr id="userman-orgchart-tree-node-9" class="fancytree-expanded fancytree-folder fancytree-has-children fancytree-exp-e fancytree-ico-ef"> <td> <span class="fancytree-node" style="padding-left: 16px;"> <span class="fancytr ...

What is the best way to have react-bootstrap's Dropdown automatically open when hovering your mouse over it?

Looking for a simple solution. I want the dropdown to open when hovering over it, rather than clicking on it. Here is my current code: <Nav> <NavDropdown onMouseEnter = {()=> isOpen=true} open={isOpen} noCare ...

Incorporate a comma after the second or third digit to separate currency values in JavaScript

Is there a way to add commas to currency values at the 3rd or 2nd place depending on the value itself? The desired output format is: 1000 => 1000 10000 => 10,000 210000 => 2,10,000 2010000 => 20,10,000 12010000 => 1,20,10,000 I am currentl ...

Is there a way to eliminate the shadow effect on a specific part of a material-ui AppBar?

I want to remove the shadow that appears on the navbar when it overlaps with the sidebar. https://i.sstatic.net/eHh0u.png Currently, I am using Material-UI's AppBar component for my NavBar. export default function NavBar() { return ( <div&g ...

Problem with Active State of DOM Element

My goal is to create an effect where clicking on a DOM element, specifically a list, will cause the target list to rotate and remain in that position. Describing it can be a bit challenging, so I have provided a visual example of what I'm working on ...

Ways to cap the height of elements at predetermined values ("stepped") depending on the content within

After posting a question on this topic here, I am seeking advice on how to implement "step-based heights" for a div element. To further clarify, my goal is to have each box with a height that is a multiple of 400px. For example, if the height is 345px, it ...

Difficulty achieving transformation of one div element within another div element

My aim is to create a unique hover effect for a button where it tilts slightly without affecting the text. You can view my progress here: https://codepen.io/kyannashanice/pen/QWveOMg I tried stacking the text and button in separate divs and triggering the ...

Allow users to zoom in and out on a specific section of the website similar to how it works on Google Maps

I am looking to implement a feature on my website similar to Google Maps. I want the top bar and side bars to remain fixed regardless of scrolling, whether using the normal scroll wheel or CTRL + scroll wheel. However, I would like the central part of the ...

The close button on the modal vanishes on a real iPhone

The issue I am facing is that the Close Button appears when testing responsiveness in Chrome, but disappears on a real iPhone. When clicking on an image, the image gallery should appear. However, on an iPhone, only the previous and next buttons are visibl ...

Tips for Deselecting a Table Cell in React

I've been working on a table in React and I'm trying to implement a feature where clicking on a cell colors it, and clicking on another cell uncolors the previous one. So far, I've managed to color cells upon clicking but I'm stuck on h ...

What is the reason that the text-overflow property does not function properly within a nested flexbox

Why does my overflow text only show ellipsis when one parent element with display: flex is removed? It seems the text width determines the parent's width rather than using ellipsis. To test this behavior, try reducing the browser width in the provided ...

Is there a way to adjust the slide length in JQuery's slideUp function using pixels? It seems like

At the bottom of a page, I have a fixed position div element. There is another div below it, but it is hidden outside of the page margins. I am attempting to slide both divs upwards so that the bottom one becomes visible (moving out of the margin). However ...

Placing an image beyond the boundaries of the design

Currently, I am in the process of creating a website that is 960px wide. One of my goals for this site is to have images on both sides of the header visible to those with larger screens. However, maintaining the site at 960px width poses a challenge when ...

Is the card-columns class not available in Bootstrap 5.0? Are there any other alternatives provided by Bootstrap besides using CSS media queries and flex column?

While exploring Bootstrap 5.0, I noticed that the card-columns class was missing and there is no mention of it or its alternative in the Bootstrap 5.0 documentation. However, it can still be found in the Bootstrap 4.6 documentation. I understand that usin ...

How can I obtain the width of one element and then use it to adjust the size of another element that is

Currently, I am working on a dropdown menu and facing an issue with setting the submenus to match the width of the top-level page. In my HTML structure (specifically for a WordPress theme), it looks something like this: <ul class="menu"> <li ...