Adjust the height of the left div to be compact without impacting any other div within the parent

Struggling to come up with a name for this issue, so I apologize if it's unclear. Basically, I am working on a tabbed module where the .right div always stays the same height.

The .left div contains the links/tabs, but I don't want its height to match the .right divs.

For example, in the following approach, I want the div with the text "Content" to have an auto height (matching the text height).

Approach:

.parent {
  display: flex;
  flex-direction: column;
}
.flex-row{
  display: flex;
  flex-direction: row;
}

.left,
.right {
  flex-basis: 50%;
}

.left {
  border: 1px solid blue;
}

.right {
  background: red;  
  min-height: 200px;
  width: 200px;
}
<div class="parent">

  <div class="flex-row">
    <div class="left">Content</div>
    <div class="right"></div>
  </div>
  
  <div class="flex-row">
    <div class="left">Content 2</div>
  </div>
  
</div>

So something like this:

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

I've managed to achieve the above by simply using

<div class="left">Content<br>Content 2</div>
for demonstration purposes.

Answer №1

Utilize the left property as a flex container, and include two children within it. Then, adjust the first child's height attribute to 100%. Here is an example:

.parent {
  display: flex;
  flex-direction: column;
}

.flex-row {
  display: flex;
  flex-direction: row;
}

.left,
.right {
  flex-basis: 50%;
}

.left {
  border: 1px solid blue;
  display: flex;
  flex-direction: column;
}

.row1 {
  height: 100%;
}

.row2 {
  background-color: lightblue;
}

.right {
  background: red;
  min-height: 200px;
  width: 200px;
}
<div class="parent">

  <div class="flex-row">
    <div class="left">
      <div class="row1">
        Content
      </div>
      <div class="row2">
        Content2
      </div>

    </div>
    <div class="right"></div>
  </div>


</div>

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

Data displayed in a table-like format

Is there a way to achieve this layout view image here (currently done using tables) while maintaining semantic markup? I believe the best tag for this would be dl. Each cell should have the height of its corresponding row. EDIT: The left column contains d ...

Ways to transfer textbox value to another jsp page upon clicking a separate form button without relying on javascript

Here is the code snippet: <body> <input type=text name=name> <form action=new3.jsp method=post name="f1"> <input type=text name=name> <input type=submit value=next> </form> <form action=new1.jsp method=post> <i ...

Preventing scrolling in jQuery UI Draggable when using flexbox

In my project, I am looking to organize a container using jQuery UI draggable/droppable feature. Since the elements in my list are arranged in a straight horizontal line, I have utilized display: flex. This arrangement works well when adding new items to ...

What is the formula for determining the REAL innerWidth and innerHeight?

I am currently working on a responsive website using Bootstrap and I am looking to create an element that perfectly fits the screen size. When I set the height/width to 100%, the browser includes the toolbar, other tabs, and the Windows taskbar in the cal ...

Is there a way to create a table cell that occupies zero space?

I have a very intricate table setup that resembles a tree structure, with only a few cells on the left and many on the right. I am looking to completely hide specific cells, along with their entire rows, using JavaScript based on their class. Using visibi ...

The synchronization issue between ng-class and animation

I'm experiencing a strange issue with ng-class and suspect that it may be related to a race condition. Here is the example on Plunker: example Below is the relevant JavaScript code: self.slideLeft = function() { if (self.end_index < se ...

How can I retrieve the URL for a specific location on Google Maps using latitude and longitude coordinates?

Is it possible to generate a URL using latitude and longitude coordinates that will take me directly to a Google Maps page showing that location? For instance, consider the following sample code: var lat = 43.23; var lng = 114.08; var url = 'http:/ ...

How can white space be maintained using <select> and <V-for> in Vue.js?

Using select and v-for to display values can be tricky when dealing with white space, such as "a a - ". Sadly, most of the white space gets removed when the values are shown and returned to the backend. Here is the code snippet illustrating the i ...

I am attempting to send a variable from my Google Script to HtmlOutputFromFile in a seamless manner

I am currently working on developing an input box with a dropdown list, where the options are generated from a 2D array retrieved from a Spreadsheet. My investigation has revealed that by storing HtmlService.createHtmlOutputFromFile in a variable, I can " ...

Creating a cohesive look with a background gradient and image simultaneously

Short Version Is it possible to have both a background color with a linear gradient and a background image at the same time? Long Version I have styled a table with a vertical linear gradient in the header, as shown below: table { white-space: no ...

The JQuery script is not producing any results

After integrating a script into my website template, it is not functioning as expected. I suspect there may be a conflict with JavaScript, but upon inspecting with firebug, I am unable to identify any abnormalities. Here is the link for reference: Link ...

Issue with implementing custom fonts using @font-face

I've added custom @font-face styling to my CSS using a downloaded font, but it doesn't seem to be working. Below is my CSS code: @font-face { font-family: "Quicksand"; src: url("fonts/Quicksand/Quicksand-Light.otf") format("opentype"); } The f ...

The left margin in Carousel is malfunctioning when it comes to hovering

I would like to achieve an effect where, on hover, my images shift the other images to both the left and right. However, currently when hovered, all the images shift to the right only. The code snippet in question is as follows: .item-img:hover { trans ...

Incorporate props within the CSS template string of Emotion for enhanced styling flexibility

I am currently in the process of transitioning my design system from styled-components to emotion. Within styled-components, the following syntax is considered valid: export interface AvatarProps { // ... shape: AvatarShape; size: AvatarSize; } con ...

How to instantly return progress bar to zero in bootstrap without any animations

I am currently working on a task that involves multiple actions, and I have implemented a bootstrap progress bar to visually represent the progress of each action. However, after completion of an action, the progress bar is reset to zero using the followi ...

Determining When to Apply max-height / max-width for Images in CSS

At what point should one consider using max-height or max-width for an image? Is it beneficial if I refrain from mentioning the specific dimensions of the image due to uncertainty? ...

Annoying AngularJS Scrolling Problem

I am facing an issue with a Container that loads multiple views <md-content flex id="content"> <div ng-view></div> </md-content> One of the loaded views has the following structure: <div layout="column" id="selection-whit ...

Manage the input in the text field using a checkbox

Hello, I currently have 2 text fields and 2 checkboxes: <input type="checkbox" id="class1"> <input type="checkbox" id="class2"> <div id="hidden"> <input type="text" id="valclass1"> <input type="text" id="valclass2"> </div ...

`Center the image on top of the text`

Currently, I am working with Bootstrap 4 to create a component that includes two tiles. Each tile has an icon image on the left side and a hyperlink on the right side. On desktop view, the tiles should be displayed horizontally and vertically centered. How ...

Issue with border in Bootstrap Grid Navigation Bar

I've experimented with margins, padding, and border options extensively, but I still can't get rid of the white space at the end of my navbar. Can anyone provide a simple solution, please? See the attached image for a clear visual of the issue. T ...