Vertical sticky text positioning element

Is there a way to use CSS only to keep vertical text aligned next to other elements without any awkward white space or incorrect sizing issues? One method I've tried involves setting the position to sticky, but this creates problems with calculating height and scrolling beyond the parent element:

Check it out here

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

Using techniques like transform:rotate, negative margins, or similar approaches only seem to exacerbate the issue. The challenge lies in correctly determining the height of the text relative to its container.

Another attempt at solving the problem

h2 {
  position: sticky;
  top: 120px;
  margin: 0;
  left:32px;
  transform-origin: top left;
  font-weight: 900;
  overflow: visible;
  white-space: nowrap;
  writing-mode: vertical-lr;  
}

I've experimented with various solutions including adjusting height, width, margins, rotation, transforms, and text orientation. Is there a way to achieve correct sticky positioning for vertically-oriented text within a parent element while maintaining proper alignment?

Answer №1

The space in your design is achieved through the use of top: 120px and margin: 120 0 styles. By replacing these with another element as a spacer, you can achieve the desired effect.

section {
  width:100%;
  position:relative;
  margin:0 auto;
  padding:0 0;
  box-shadow: 0 0 2px 2px #000;
}

.row {
  display:flex;
  flex-flow:column;
  padding-left:120px;
}

.item {
  width:100%;
  height:360px;
  background:blue;
}

.item:nth-of-type(odd) {
  background:green;
}

h2 {
  position: sticky;
    top: 0;
    margin: 0;
    left:32px;
    /* rotate: 90deg; */
    transform-origin: top left;
    /* transform: translate(0,-100%); */
    font-weight: 900;
    /* width: 0; */
    /* height: 0; */
    overflow: visible;
    white-space: nowrap;
    writing-mode: vertical-lr;
  
}
<section>
  <p>Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. Some filler text. </p>
  <h2>MY STICKY WORDS! THESE ARE LONG!</h2>
  <div class="row">
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
  </div>
</section>

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

What could be causing the issue with object-fit not functioning properly within a container with a max

My goal is to insert a video into a container that has a width of 100% and automatically adjusts its height while maintaining the aspect ratio, but with a maximum height set. I want the video to completely fill the container even if some parts are cropped ...

Guide on modifying CSS properties when hovering over the parent element

I am working with a table structure like this: <table> <tr><td class="momdad"><i class='glyphicon glyphicon-cog'></i> Hello </td><td> Mom </td></tr> <tr><td class="momdad">< ...

What is the solution for resolving the "cannot resolve" issue in CSS for an Angular project?

During a small project I was working on, I decided to add a background image to another image using CSS. Here is the code snippet: .child2 img { width: 200px; height: 200px; border-radius: 50%; background-image: url('./assets/images/imageb ...

Adjust the width of the dropdown list to be distinct from the width of the dropdown button

My goal is to create a dropdown where the width of the button is different from the width of the list. I am aware that we can adjust the widths using inline styling like style={{ minWidth: '200px' }}. Now, I want to set the width of the dropdown ...

What is the best way to personalize the icon for this navigation button?

I'm interested in making some changes, especially to the border. I've already figured out how to adjust the color of the 3 bars like so: .navbar-default .navbar-toggle .icon-bar { background-color: #fff; } Modification RESOLUTION .navbar- ...

Set the width of the left div in percentage and have the right div automatically fill

In my layout, I have a left div with a percentage width floating to the left, and a right div also floating left that should take up the remaining space. Here is a [fiddle] link for reference: https://jsfiddle.net/gfhfku8k/. Any assistance would be great ...

Adjusting the appearance of Material-ui table within the row.getRowProps() function

I am currently working on a React application that utilizes Material-UI enhanced table, which is based on react-table. I have been trying to customize the styling of their rows. According to the documentation (https://material-ui.com/api/table-row/), it s ...

"Merging the vibrancy of RGB with the subtlety of

Currently exploring methods to blend an RGB color with a grayscale one. This is for a gradient generator that leverages preset colors and a template (predefined style properties for various vendors) in order to craft a CSS3 gradient. I am certain there is ...

Immersive full-screen YouTube video embedded as hero background

Seeking a solution in HTML & CSS to display this embedded video as a 75vh height hero background. Currently, the iFrame maintains its width: 100% and height: 75vh, but the images themselves do not cover the entire header width. Essentially, I want it ...

Height of Bootstrap 4 footer aligned to the bottom

I've made a template that sets the height of the footer to 120px and specifies the line-height as well. Here is an example: .footer { height: 120px !important; line-height: 120px !important; } <!doctype html> <html lang="en"> &l ...

What is the best way to reposition the main body content lower on the page when switching to mobile layout?

I am facing an issue where my website switches to mobile design at 850px, but the button I have on both desktop and mobile mode gets hidden under the header banner when it transitions to mobile design. I want to adjust the main body content of the website ...

Leveraging the power of Javascript to trigger 2 functions when a button is clicked

After receiving great answers to my previous questions, I am in search of more valuable insights. The challenge at hand involves 9 buttons on a webpage with text inputs. Upon clicking a button, the text entered by the user is supposed to be transferred to ...

Creating a unique carousel design using only CSS in Bootstrap

Trying to create a CSS effect to enhance Bootstrap, I noticed that it only works correctly when clicking the right arrow. Whenever I click the left one, nothing happens. I'm not sure where I made a mistake, can anyone help me spot it? Thanks in advanc ...

The display of the Myriad Pro font is not appearing correctly

I incorporated the Myriad Pro font into my website by uploading it to the server and providing a link as shown below @font-face{ font-family: "Myriad-Pro"; src: url(http://www.anaveer.in/honda/font/MYRIADPRO-REGULAR.OTF) format("truetype"); } H ...

After adding a new class, NextJS fails to style the div appropriately

Currently, I am working on the front-end using the NextJS framework. When a user clicks a specific button, a class is supposed to be added to a particular div which will then change the style of the div based on unique styles defined in my CSS file. The o ...

Adding a scroll bar to a fixed container: tips and tricks

I am looking to implement a scrollbar in a fixed container for the cart products. The goal is to enable easy navigation through a large number of products added to the cart by scrolling within the container. Below is the HTML code snippet representing the ...

What is the best way to manipulate the size and orientation of an image upon hovering over

I'm struggling to figure out how to simultaneously rotate and scale a .png file when the user hovers over it. Currently, it only scales when I hover on the picture. I understand that the scale property overwrites the first transform but I can't s ...

Tips for minimizing the width of a form in CSS/HTML

I created an HTML page with the following code: <div class="panel panel-default"> <div class="panel-heading"> <h1>Users</h1> </div> <div class="panel-body"> <table class="table table-strip ...

Issues with width transitions in Edge when using the ::after pseudo-element

My CSS transitions on the ::after pseudo-element work perfectly in Chrome and Firefox, but not as expected in Edge. While the background color transition is functioning correctly, the width isn't. You can view my current code here: http://codepen.io/ ...

Maintain the jquery menu in an open state after it has been

Encountering a common issue, I am having difficulty adapting existing solutions to my unique situation. I am working with a jquery vertical accordion menu intended for navigation across two websites: home.html and research.html. Below is the relevant excer ...