Using flexbox to adjust the height of a block in the layout

Is there a way to modify the height of .half-containers1 and .half-containers2?

Additionally, how can I create the triangle shape that is shown in the image? Is it achievable with CSS alone or do I need to use an image?

Check out my fiddle for reference and the layout image I am attempting to replicate.

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

div {
  box-sizing: border-box;
  border: 0.5px solid red;
}

.main-container {
  height: 100%;
  display: flex;
}

.left-container {
  flex: 1 1 0;
}
.center-container {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;


.right-container {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
}

.half-containers1 {
  flex: 1;
  height: 400px;
 
}
.half-containers2 {
  flex: 1;
  height:100px;
  background-image: url("https://upload.wikimedia.org/wikipedia/en/7/78/Small_scream.png")
 
}
<div class="main-container">
  <div class="left-container">Left container</div>
  <div class="center-container">
    <div class="half-containers1">
      <p>Center</p>
 
   
    </div>
    <div class="half-containers2">Center2</div>
  </div>
  
  <div class="right-container">
  Right container
  </div>
</div>

Answer №1

Try using the flex-basis property (or the flex: 0 X shorthand) in your CSS for the elements with the class name halfcontainers. You can also create a triangle shape using the ::after pseudo-element.

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

div {
  box-sizing: border-box;
  border: 1px solid red;
}

.main-container {
  height: 100%;
  display: flex;
}

.left-container {
  flex: 1;
}

.center-container, .right-container {
  flex: 1;
  display: flex;
  flex-direction: column;

}

.half-containers1 {
  flex: 0 70% /*400px*/;
  position: relative;
}

.half-containers1::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: 0;
  height: 0;
  border-top: solid 10px white;
  border-left: solid 10px transparent;
  border-right: solid 10px transparent;
}

.half-containers2 {
  flex: 0 30%/*100px*/;
  background: url("https://upload.wikimedia.org/wikipedia/en/7/78/Small_scream.png") no-repeat center / cover
}
<div class="main-container">
  <div class="left-container">Left container</div>
  <div class="center-container">
    <div class="half-containers1">
      <p>Center</p>
    </div>
    <div class="half-containers2">Center2</div>
  </div>
  <div class="right-container">
    Right container
  </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

Tips for locating and clicking the 'Start' button in HTML using either find_element_by_xpath or the Selenium-Python API

Need help selecting the 'Start' button and clicking it in the HTML code below. I want to do this using the python-selenium library like so: driver.find_element_by_xpath('//div[contains(@class,"box enter")' ...

How can you define & specify parameters for iframe using CSS?

Is there a way to style the parameters of an <iframe> using CSS? I am trying to embed multi-track audio from archive.org. For example, like this: <iframe src="https://archive.org/embed/art_of_war_librivox​&playlist=1​&list_height=200 ...

Tips for changing the CSS properties of input elements in iView

Exploring Vue's single file components and experimenting with the iView UI framework. Here is a snippet of code I am working with: <template> <div> <i-input class="cred"/> </div> </template> I want to adjust the ...

Is there a combination of 'auto' and 'none' values in any CSS properties?

Is it safe to assume that if a property is set to auto, it cannot have the value of none, and vice versa? Or if a property has none, can it not have auto as well? I understand that these values have distinct meanings, but I am curious if this concept has ...

Should we make it a routine to include shared sass variables in each vue component for better practice?

Within my Vue application, there are numerous components that rely on shared variables like colors. I'm considering having each component import a global "variables.scss" file. Would this approach have any adverse effects? ...

Fixed header in a div, allowing content to scroll when hovering over the header

How can I ensure that the header remains fixed at the top while allowing the content to scroll when hovered over? The current issue is that when a user hovers over the header and tries to scroll, the content does not move. body { margin: 0; ...

The overflowing issue with the Nextjs Tailwind Marquee Component is causing a display

I've recently developed a unique nextjs/tailwind component. This component displays an isometric marquee that scrolls horizontally. However, I'm facing an issue where the content overflows to the right and causes the page to become horizontally s ...

Connect to dynamically generated div on separate page

I am facing an issue with my navigation bar drop down menu that displays event titles fetched from the database. I want users to be able to click on a specific event and have the page scroll to the dynamically generated content for that event. However, it ...

What is the best way to change the font size in HTML?

After carefully analyzing the image provided, I encountered an issue while attempting to incorporate the code display:block. However, no changes were reflected. Can you identify what may be causing this discrepancy in my text? How can this issue be recti ...

send data to a hyperlink

I need to pass a parameter to the href based on the first name in the list. The names are links to another page that I retrieve via an _id passed in the URL. The issue I am facing is that the id is not being passed to the URL, resulting in an error. How ...

What is the best way to send HTML tag content to mark.js and delimit them with a space or comma?

I have been utilizing the mark.js library to highlight keywords on a webpage, and it's been working well. However, I now need to insert an extra space or a comma after each tag such as h1, h2, etc. Initially, I thought about using a loop like the one ...

Tips on eliminating excess white space or margins beneath a flexible video player

My issue is with a video and some content underneath. When I reduce the height of the video on mobile, there is too much white space below it. @media only screen and (max-width: 600px) { video { height: 80%; } Instead of adding margin-bottom ...

Class Div is visible only within the jQuery Tab

I have encountered a perplexing issue that has left me stumped. I recently added tabs using a jQuery plugin [Tabulous] and am in the process of transferring existing content into these tabs. However, I stumbled upon a strange problem while attempting to po ...

The integration of HTML and CSS using ng-bind-html appears to be malfunctioning

<ion-item ng-bind-html="renderHtml(word[key])"> </ion-item> When referring to word[key], it represents: <ul> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul> This is the CSS being u ...

Encountering a Tailwindcss error while attempting to compile the CSS file

Struggling to grasp Tailwind CSS as I try to compile the CSS but keep encountering errors. Despite following numerous tutorials, this persistent error continues to hinder my progress. This is the specific error message that keeps popping up: $ npm run bui ...

What is the best way to connect added elements together?

I am currently utilizing Plupload to upload files. Due to specific requirements, I need to place FilesAdded "inside" init as demonstrated below. The issue I'm facing is the inability to utilize jQuery.remove() on elements that have been appended usin ...

The outline color cannot be removed from vue-carousel

I recently downloaded the Vue Carousel library and here is the version I am using: "vue": "^2.6.11", "vue-carousel": "^0.18.0", When I click on the pagination, a focus effect is added to the element with an outlin ...

AngularJS scope watch isn't firing as expected

In the scope, I store a filtering string for dates. $scope.myModel = {date:""}; Utilizing a jQuery datepicker, <input date-value="myModel.date" date-picker /> This directive updates the string through AngularJS - Attribute directive input value c ...

Spacing applied to content within a fresh Vue application

Having been assigned the task of developing a Vue page for my team, I am facing an issue with a persistent white border surrounding the entire page. <script setup lang="ts"> </script> <template> <body> <div>&l ...

Focused on individual characters in a string to implement diverse CSS styles

Is there a way I can apply different CSS classes to specific indexes within a string? For example, consider this string: "Tip. \n Please search using a third character. \n Or use a wildcard." I know how to target the first line with CSS using : ...