Turn text 90 degrees creating a div that is positioned inside its parent container

Whenever I rotate text (or a div containing text), it seems to break free from its parent container. Additionally, the height of the div appears to be based on its original width after rotation. I prefer using CSS to achieve the desired outcome rather than resorting to javascript or jQuery, even though those options are available since I'm working with Bootstrap-4. How can I ensure that a rotated div remains within its parent container and adjusts its dimensions based on the parent's width/height after a 90° rotation?

Appreciate any insights!

.emptydropzone{
height: 10vh;
border: 1vh dashed #000; 
border-radius: 1vh;
background-color:  #CCC;
}

.taflag{
width: 98%;
min-height: 50px;
margin: 10px 125px 10px 5px;
padding: 10px 10px 10px 10px;
border: 5px solid #90C;
border-radius: 5px;
background-color:  #90C;
color: #FFF;
font-size:xx-large;
font-weight: bolder;
}

.rotateparent {
position:absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: yellow; /* this is just to see the parent div in testing */
}

.agentflag{
transform: rotate(-90deg);
border: 5px solid #F00;
border-radius: 5px;
background-color:  #F00;
color: #FFF;
font-size:xx-large;
font-weight: bolder;



}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<body>

<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="row">
<div class="col-2">
                 <div class="taflag"> TA </div>
</div>
<div class="col-10">
                <div class="emptydropzone" id="ta" > </div>
</div>
</div>
<div class="row">
<div class="col-2">
                 <div class="rotateparent">
                       <div class="agentflag"> AGENTS </div>
                     </div>
 </div>
<div class="col-10">

  <div class="emptydropzone" id="agent1"> </div>
  <div class="emptydropzone" id="agent2"> </div>
  <div class="emptydropzone" id="agent3"> </div>
  <div class="emptydropzone" id="agent4"> </div>
                
</div>
</div>
</div>
</div>
</div>



<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

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

Answer №1

Optimizing with writing-mode may greatly improve efficiency here.

Potential enhancement using fewer HTML elements and more Bootstrap classes

.emptydropzone {
  min-height: 10vh;
  border: 1vh dashed #000;
  border-radius: 1vh;
  background-color: #CCC;
}

.taflag {
  width: 98%;
  min-height: 50px;
  margin: 10px 125px 10px 5px;
  padding: 10px 10px 10px 10px;
  border: 5px solid #90C;
  border-radius: 5px;
  background-color: #90C;
  color: #FFF;
  font-size: xx-large;
  font-weight: bolder;
}

.rotateparent {
  background: yellow;
  padding: 10px 0;
}

.agentflag {
  writing-mode: vertical-lr;
  transform: scale(-1, -1);
  /* until 
  writing-mode:sideways-lr; works everywhere */
  margin: auto;
  border: 5px solid #F00;
  border-radius: 5px;
  background-color: #F00;
  color: #FFF;
  font-size: xx-large;
  font-weight: bolder;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<body>

  <div class="container-fluid">
    <div class="row">
      <div class="col-12">
        <div class="row">
          <div class="col-2">
            <div class="taflag"> TA </div>
          </div>
          <div class="col-10">
            <div class="emptydropzone" id="ta"> </div>
          </div>
        </div>
        <div class="row">

          <div class="col-2 d-flex rotateparent m-0">
            <div class="agentflag m-auto"> AGENTS </div>
          </div>

          <div class="col-10 d-flex flex-column justify-content-around">

            <div class="emptydropzone" id="agent1"> </div>
            <div class="emptydropzone" id="agent2"> </div>
            <div class="emptydropzone" id="agent3"> </div>
            <div class="emptydropzone" id="agent4"> </div>

          </div>
        </div>
      </div>
    </div>
  </div>



  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

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

Switch up your code and toggle a class on or off for all elements that share a specific class

I've been attempting to create a functionality where, upon clicking a switch, a specific class gets added to every element that is assigned the class "ChangeColors". Unfortunately, I have encountered some difficulties in achieving this task. The error ...

Issue with Bootstrap column functionality on iOS devices detected

I created a card using bootstrap that displays perfectly on all devices except for iOS devices. The layout completely changes on iOS devices as shown in the screenshot attached. Here is the link to view my card on the test server: Here are the screenshot ...

The functionality of jQuery .rotate() appears to be malfunctioning

I'm struggling to get this code working properly. My jQuery version is 2.1.0. Here's the code snippet: $("a.shownav img").rotate(180); Any suggestions on how to make it function correctly without relying on a plugin? ...

Custom styles for PrimeNG data tables

Struggling to style the header of a datatable in my Angular project using PrimeNG components. Despite trying various solutions, I am unable to override the existing styles. Even attempting to implement the solution from this PrimeNG CSS styling question o ...

The Best Way to Calculate a Total Sum with Comma-Separated Values in AngularJS

In my application, I am utilizing the MEAN stack with AngularJS as the front-end. I am trying to figure out how to calculate the total sum and include comma values. I have managed to get the total sum value, but the comma value is not being calculated prop ...

Place an IconButton component next to each Material UI TableRow

I am trying to include an icon next to the material UI table row component. Similar to the hint icon shown in the screenshot below Here is my attempt so far, but it's not functioning as expected: Check out the code on CodeSandbox https://i.stack.i ...

Incorporate Bootstrap 4 SASS into ASP Core Project to customize base font size

My journey began with a desire to adjust the base font-size of Bootstrap 4. After some investigation, I learned that overriding the variables in the _custom.scss file was the recommended approach, so I set $font-size-root: 14px. Everything seemed to be goi ...

Combine object attributes to create a new column in a table

Check out this plunker I created. What is the most efficient way to merge the contents of $scope.blacklist into $scope.friends when ng-click="showColumn('Blacklist');" is triggered, and also add a new column named Coming to the table. Ng-App &am ...

What is the best way to ensure that any words exceeding the line length automatically move to the next line?

My webpage width is currently set to 100vw and adjusts responsively as the viewport size changes. However, there seems to be a slight issue where certain words overflow without being pushed to the next line, causing a small horizontal scroll: https://i.s ...

Feature for jotting down notes, creating a break between lines without any information present

I'm currently working on implementing a note-taking feature for my web application. However, I have encountered two issues: Firstly, I am struggling to identify line breaks within the text. While I can hardcode text with line breaks, when a user clic ...

Generating a hyperlink to a specific user ID within a data table

I'm facing an issue with the formatting of my simple table when trying to navigate to user.id. Is there a better approach to this or should I consider moving LinkToUser? All styling has been removed to avoid any conflicts. import styled from 'st ...

The YouTube video continues to play even after the container is closed

I recently worked on implementing a lightbox feature using jQuery, where a window opens upon clicking an element. Everything was working fine with images, but when I tried to open a YouTube video and play it, the video kept playing in the background even a ...

Tick the checkbox to indicate that I want to insert an image in the adjacent column for the same row

Every time I click on the checkbox, an image should appear in the adjacent column for that specific row. Despite using the addClass() method and targeting the td, the image is appearing in all rows instead of just the selected one. Could somebody help me ...

Issue with Bootstrap Navbar dropdown causing page refresh instead of menu dropdown activation

<!DOCTYPE html> <html lang="en" dir="ltr" style="style.css"> <!-- All icons were courtesy of FlatIcon : www.flaticon.com and FreePik : www.freepik.com --> <head> <meta charset="utf-8"&g ...

Tips on aligning vertically centered left and right floating objects without having to use the line height property

          Here is the issue I am facing http://jsfiddle.net/vT4YT/ <table><tr><td><div></div><div></div></td></tr></table> You can see that the options and row text are not vertic ...

The dropdown item in Tailwindcss is unexpectedly flying off the edge of the screen rather than appearing directly under the dropdown button

Currently, I am developing an application using Rails, Vue, and TailwindCss 1.0+ I am facing an issue while creating a dropdown menu for my products. When I click on the dropdown button, the items in the dropdown fly off to the edge of the screen instead ...

The cakePHP time dropdown feature lacks customization options

When viewing my form in CakePHP, I noticed that the time select dropdown appears differently in Chrome compared to Firefox. In Firefox, there are 3 arrow buttons attached to each dropdown, whereas in Chrome it looks different. I want to hide the arrow but ...

When there is no visible content on the mobile website, it starts scrolling horizontally to the right

Why is the website scrolling to the right when there is no content there? This issue seems to only occur on actual mobile devices when I try to recreate it. Currently in the process of transferring it over, which is why the link appears as it does. Any ...

What is the process for creating a beveled edge on a block div?

I am working on an HTML document that includes a DIV tag with specific styling: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>DIV Tag</title> <style type="text/css"> ...