What is the best way to center a rotated element and have it aligned to the top?

* {
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    margin: 0px;
}

.we-adopt {
    background-color: #8a8484;
    color: #ffffff;
    padding: 88px 0px;
    height: 100px;
}

.we-adopt-list span {
    display: inline-block;
    vertical-align: top;
    padding: 16px 60px 16px 24px;
    background-color: #222222;
    color: #ffffff;
    width: 100%;
}

.we-adopt-list li {
    color: #FFFFFF;
    font-size: 32px;
    font-weight: 500;
    letter-spacing: 1.6px;
    line-height: 24px;
    margin-bottom: 70px;
    text-transform: uppercase;
}

.we-adopt-list ul {
    display: inline-block;
    transform: rotate(-90deg) translateY(-50%);
    position: relative;
    left: 50%;
}

.we-adopt-list {
    position: relative;
}

.we-adopt-list li:last-child {
    margin-bottom: 0px;
}
<section class="we-adopt" style="height: 100px;">
    
</section>
<section class="we-adopt-wrap">
    <div class="container">
        <div class="we-adopt-list">
            <ul>
                <li><span>Mental agility</span></li>
                <li><span>Emotional agility</span></li>
                <li><span>Trust</span></li>
            </ul>
        </div>
    </div>
</section>

When I use the transform- rotate property on my list section, it sometimes overlaps or takes space from the content above.

Scenario 1

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

Scenario 2

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

After applying transform- rotate, I want the list section to start just below the grey section with no spacing as shown in the image below.

Expected Outcome

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

Is there another way to achieve this design?

Answer №1

Take into account the transform-origin property and modify the transform as shown below:

* {
  box-sizing: border-box;
}

body {
  font-family: 'Poppins', sans-serif;
  margin: 0px;
}

.we-adopt {
  background-color: #8a8484;
  color: #ffffff;
  padding: 88px 0px;
  height: 100px;
}

.we-adopt-list span {
  display: inline-block;
  vertical-align: top;
  padding: 16px 60px 16px 24px;
  background-color: #222222;
  color: #ffffff;
  width: 100%;
}

.we-adopt-list li {
  color: #FFFFFF;
  font-size: 32px;
  font-weight: 500;
  letter-spacing: 1.6px;
  line-height: 24px;
  margin-bottom: 70px;
  text-transform: uppercase;
}

.we-adopt-list ul {
  display: inline-block;
  transform-origin: top left;
  transform: rotate(-90deg) translateX(100%) translateY(50%);
  position: relative;
  margin: 0;
  left: 50%;
}

.we-adopt-list {
  position: relative;
}

.we-adopt-list li:last-child {
  margin-bottom: 0px;
}
<section class="we-adopt" style="height: 100px;">

</section>
<section class="we-adopt-wrap">
  <div class="container">
    <div class="we-adopt-list">
      <ul>
        <li><span>Mental agility</span></li>
        <li><span>Emotional agility</span></li>
        <li><span>Trust</span></li>
      </ul>
    </div>
  </div>
</section>

Answer №2

transform: rotate is primarily for visual enhancement and does not affect the layout of the page. If you need to adjust its position, consider using transform: translate, margin, or alternative methods.

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

Can you provide guidance on how to prioritize container div style over CSS class?

Here's the HTML code snippet I'm working with: <html> <head> <style> .text-box { color: red; } </style> </head> <body> <p class=&qu ...

Issue with EaselJS: mouse events are no longer functional

I'm currently working on adding a touch animation using the EaselJs library. Interestingly, when I load an image from a local folder, all mouse events work as expected, such as onPress. However, things take a different turn when I opt to use an imag ...

Creating subpages using IDs can be accomplished by following these simple steps

Currently, I am in the process of developing a website that contains a plethora of information, specifically news articles. Each news article on my site features an introduction and a header. Upon clicking on a particular news article, the full content is ...

What is the best way to center the startIcon material ui icon?

I'm having trouble keeping the icon button centered on my page. When I add left: "0.5rem" to the sx prop, it ends up pushing the button icon even further away from center. I'd prefer not to use makeStyles to manually override the position. Any ad ...

Styling a div to wrap around an image

I'm working with an image element that has the style attribute set to style='width:40%;height:40%'. My goal is to add a div around this image that will automatically adjust its size to wrap around the image. However, when I try inserting the ...

Animated scrolling in Angular

I am working on a webpage using Angular, where each module is a component with an animation. However, I am facing an issue where the animation only runs when the page loads, but I want it to happen while the component is visible on the screen. One approa ...

The error message encountered is "Uncaught (in promise) Error: Unable to access attributes of an undefined object (reading 'launch')."

I am currently learning electron.js by developing a basic application that extracts information from a website. However, I am encountering a frustrating and annoying error. Here is the folder structure of my project The following code snippet represents ...

Implementing full-height list elements using CSS

I'm still facing challenges with my lists... After receiving some assistance, I was able to create a horizontal list with perfect dimensions for my needs: each element taking up 33.33% width and adjusting its height based on the tallest element. I ac ...

Adjust the alignment of text on both ends of the HTML5 canvas

Is there an easier way to align text on both sides of a canvas element besides using CSS? The link below might provide some insight: https://github.com/nnnick/Chart.js/issues/114#issuecomment-18564527 I'm considering incorporating the text into the d ...

Navigating websites: Clicking buttons and analyzing content

When looking to navigate a website's directory by utilizing buttons on the page or calling the associated functions directly, what language or environment is most suitable for this task? After experimenting with Python, Java, Selenium, and JavaScript, ...

Error parsing in Visual Studio 2012

I have included the following code in my master page: <link rel='stylesheet' id='layer-styles-css' href='css/layerslider.css?ver=3.4.1' type='text/css' media='all' /> When debugging in MS Vis ...

A list containing various checkboxes

I have created a list with checkboxes in each item. I want to ensure that if any of the child checkboxes are checked, the parent checkbox is also automatically checked. Here's the HTML code: <input type="checkbox" id="parent"> <ul> ...

What is the best way to align a jQuery Cycle 2 Slider in the middle of the

Having some trouble centering a jQuery Cycle 2 Slider on my page. You can see the slider here. I've attempted multiple methods to center it, but none have been successful. Check out the HTML code: <div class="slider"> <div id=outside> ...

Tips on organizing elements

Here are three elements: <!DOCTYPE html> <html lang="en"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.boo ...

Protecting against overflow for text inside a container that changes when hovered over

There is text displayed on top of an image within a div container that functions as a link. <a href="https://link.com" style="color:white"> <div class="thumbnail"> <img src="image.jpg" clas ...

Indent the text within a span element that is displayed as an inline block

I am in search of a solution using only CSS for the following issue. Take into account the HTML below: <p> <span>Some text</span> <span>Some text</span> </p> Both <span> elements are set as inline-block. ...

Customize your Bootstrap design by selecting a background color that doesn't

Why is the dropdown background black when used in a bg-dark navbar but white when used outside of the navbar? I want to use a white dropdown in a dark navbar. Here is my complete code: MyCode Here is my navbar & dropdown: <nav class="na ...

Ensure that all divs have the same height and padding when resizing

I have 3 divs nested within a parent div. My goal is to dynamically set the height of all the child divs to match the height of the div with the maximum height, even when the screen resizes due to responsiveness. Below is my HTML structure: <div class ...

The Faux-Dynamic News Feed on a stationary website

As I work on revamping my employer's static website, it has become clear that a news section needs to be integrated. The site is being built using the Bootstrap 3.0 framework. My plan is to implement the following strategy: I aim to have a JavaScrip ...

What steps should I take to resolve the textarea border bottom CSS effect?

My simple border bottom animation is working fine with a basic input element, but it's not functioning properly when used with a textarea. (If using JavaScript is necessary for a solution, please provide guidance) How can I adjust the height of a te ...