Is the height of the element determined by the parent rather than the content?

I need help with a layout featuring three containers - Total (with a red border), Left (yellow border containing an image), and Right (blue border containing text).

Left is set to approximately 30% width with float: left, while Right is set to 70% width with float: right.

My goal is to make both Left and Right containers have the same height as Total, while still allowing Total's height to be dependent on its content. This way, I can easily center the content of Left and Right vertically within the middle of Total using margin-top and margin-bottom properties.

Two challenges I'm facing: 1) Setting a fixed height on Total fixes the height issue, but causes content to spill over when the screen is narrowed. 2) Here's a video showcasing the elements to better illustrate what I'm trying to achieve: . I would prefer to accomplish this without using JavaScript.

Answer №1

To accomplish your desired layout, consider using flexbox:

.container {
  display: flex;
}

.box1 {
  border: 2px solid blue;
  flex: 1 0 50%; /* occupy 50% width */
}

.box2 {
  border: 2px solid green;
  flex: 1 0 50%;
}
<div class="container">
  <div class="box1">
    <img src="http://placehold.it/150x150">
  </div>
  <div class="box2">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi.
  </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

Unable to change the font-size in Bootstrap 5 is not possible

I've been exploring Bootstrap 5 and encountered an issue while trying to change the font-size of the navbar-brand element. Despite my efforts, the font-size remained unchanged. Additionally, attempts to add padding to the navbar-brand did not result i ...

What is the best way to retrieve a GWT textbox value using Selenium WebDriver?

I'm currently testing my GWT application with selenium, and the HTML generated by GWT Textbox appears like this: <input type="text" class="gwt-TextBox" > Even though there's no value visible in the code above, I can see text in the UI. Is ...

Display Text Only When Selected - Material-UI

Is there a way to display only the selected tab's text? I came across this code snippet in the MUI documentation that involves showing labels on selection. How can I achieve this effect, maybe by manipulating the state to change the color of the selec ...

Do not let CKEditor interact with widget content

Even though the HTML content within the aside tag is not editable, CKEditor still performs content filtering and removes tags while displaying hidden input fields. Here is the relevant HTML widget code: <aside class="widget widget-form" contenteditabl ...

Is it possible to maintain child divs in a single line?

Despite trying numerous recommendations (many involving white-space:nowrap and display:inline-block), I have been unsuccessful in keeping these child divs on a single line with horizontal scrolling. This is my code: <div id="list"> < ...

What is the process for integrating php script within javascript?

Is it possible to incorporate php scripts into javascript[1] in the same manner as it can be done in html[2]? server.php: <?php echo 'hello World'; ?> client.js (or client.php if needed): function foo() { var i = <?php include ...

Hovering over the image causes it to flicker and it remains the same

I have an image column within a grid, where the images are displayed at 25px x 25px to fit nicely in each row. I've added a hover effect to the images so that when you hover over them, they shift left (which is working) and then expand for better vis ...

Is it advisable to utilize media queries and transform: translateY(-%) to position content above the mobile keyboard?

I've been struggling for nearly a whole day and could really use some assistance. I'm having trouble understanding how chat web apps manage to work around this particular issue. There have been numerous forum posts discussing the problem: I am tr ...

AngularJS uses double curly braces, also known as Mustache notation, to display

I'm currently working on a project where I need to display an unordered list populated from a JSON endpoint. Although I am able to fetch the dictionary correctly from the endpoint, I seem to be facing issues with mustache notation as it's renderi ...

What is the best way to initiate a change event using JavaScript?

I am attempting to enable my 4th checkbox automatically when there is a new value in the textbox (myinput). If the textbox is empty, I want to disable it. Currently, you have to tab out before the change event is triggered. Also, how can I check for an e ...

Ways to customize the default font in themes by using locally stored fonts

Currently, I am utilizing Quarto for the creation of a website and attempting to modify the default fonts within a specific theme. My ultimate objective is to incorporate local Google fonts rather than relying on the Google API. In my _quarto.yml file, it ...

Tips for employing CSS hover within HTML elements?

Is there a way to achieve the following: <li style="hover:background-color:#006db9;"> I have tried this approach but it doesn't seem to work. Is there an alternative method, or do I need to include the CSS in the head section or an external CS ...

What is the best way to place <a> links next to each other in the header?

Looking to align the links horizontally in the header using CSS, can someone assist me with this? <body> <nav> <div class="wrapper"> <a href="index.php"><img src="spaceship.png" alt="blogs logo& ...

Create a dynamic feature in Bootstrap4 where the navigation bar changes color as the user scrolls to different sections of the

Currently building my personal portfolio website with Bootstrap 4, I came up with a great idea: changing the navigation bar color based on different sections of the website. I attempted to achieve this using JQuery's offset and scrollTop functions, bu ...

Is it possible to change the CSS styling of a specific DIV class that contains nested anchor tags using jQuery?

The HTML: <div id="main_menu"> <a id="menu_item_articles" href="articles">articles</a> </div> The CSS: #main_menu { float: left; padding-top: 10px; vertical-align: middle; text-align: center; width: 500px; ...

Eliminate any unfamiliar or unidentifiable text that appears on the

Utilizing a widget known as "addthisevent," I have successfully enabled users to add a booking for a class to their calendar. However, upon echoing the link to the page, I notice an unexpected '1' next to the button. For reference, please see . ...

Image broken on default bootstrap navbar

On my computer where I am developing a Ruby on Rails app, I have a relative link to an image. To customize the style, I am using Bootstrap and have used their code to source the image for the top left brand placement. You can view the Bootstrap link here. ...

Bring in the SCSS directory from the overarching SCSS program

I am currently working with Angular (Jhipster) in my application and I am looking to include multiple .scss files in my global.scss file. To achieve this, I have created a folder called "util" at the same level as the global.scss file and placed these .scs ...

Ensure that the Materialize CSS modal form remains open even after submission

Is there a way to reload a form inside a materialize modal with empty fields without closing the modal after submitting? The issue is that currently, when the submit button is clicked, the modal closes and redirects. <div class="modal" id="docM ...

What is the best way to incorporate tooltips in SVG?

My teacher wants me to display a tooltip on an SVG circle with links and information when we hover over it. They suggested using jQuery UI, but I've done extensive research and nothing has been able to assist me so far. ...