Responsive width is applied to the first div, while a fixed width is set for the second div in

Is there a way to create this specific layout using CSS? It seems like a simple design, but I'm struggling with the coding. The red div will display an image advertisement and will always be 350px wide, positioned on the right side of the page. The green div will hold the website content and its width will adjust dynamically to fill the remaining space next to the red div. Both divs should maintain the same height.

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

html, body {
  width: 100%;
  margin: 0 auto;
}

.green-div {
  background-color: green;
  display: inline-block;
  margin: 0 auto;
  height: 100%;

}

.red-div {
  background-color: red;
  display: inline-block;
  width: 350px;
  height: 100%;
}
<div class="green-div">
  <p>Green Div</p>
</div>

<div class="red-div">
  <p>Red Div</p>
</div>

Answer №1

One way to accomplish this is by utilizing flexbox.

html, body {
  width: 100%;
  margin: 0 auto;
  display: flex;
  height: 100vh;
}

.green-div {
  background-color: green;
  flex-grow: 1;
  margin: 0 auto;
  height: 100%;

}

.red-div {
  background-color: red;
  width: 350px;
  height: 100%;
}
<div class="green-div">
  <p>Green Div</p>
</div>

<div class="red-div">
  <p>Red Div</p>
</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

Changing the CSS class dynamically by clicking with jQuery

I'm in the process of setting up a WordPress website, utilizing this specific template obtained from ThemeForest. You can view the live preview here of what I am currently working on (which should be functioning properly now - kindly inform me if it&a ...

Conceal information from view without hiding pseudo content visually

Here's a method I'm using to incorporate icons through the use of :before or :after pseudo content: <span class="icon icon__example is-content-visually-hidden">assistive text</span> Is there a way to hide the assistive text visually ...

Creating a centered vertical border in Tailwind between two divs can be achieved by following these steps

Hey there, I'm working on creating a timeline and I'd like to have a line intersecting each year similar to this example. My tech stack includes tailwind CSS and next.js. Although I've written some code, I can't seem to get the line ce ...

Triangle shape with transparent background on top of iframe or div

Currently facing an issue where I need to add an iframe containing maps to my page. However, I also need one (or two) triangles placed over this iframe with a transparent background. I attempted this solution, but unfortunately, it did not work as expect ...

Is it not allowed to use target="_blank" in XHTML Strict 1.0?

I recently ran my XHTML Strict 1.0 document through the W3C validator service and it reported that: <ul id="socialnetwork"> <li><a href="http://www.twitter.com" target="_blank"></a></li> <li>< ...

Change the width of the iframe

Can the width of an iframe with inline property be set using external CSS? Here's the code snippet: <iframe src="video.html" width="625" height="430"></iframe> I've tried setting the width to a fixed size and it worked, but I'm ...

Ways to dynamically toggle visibility and hide elements by clicking outside the specified div

I have a div that, when clicked, displays a contact us form. This form toggles between being visible and hidden. How can I make it hide when clicked on another part of the document? Here is the code: function showContactForm(){ var formWidth = &apos ...

Having trouble selecting the text field after adding CSS styling

This problem is puzzling me, as it seems like a simple issue but I can't pinpoint the cause. UPDATE: I have created a fiddle where you can see the problem in action: http://jsfiddle.net/X374V/1/ The form contains a basic text input: <input type= ...

If the content within a <div> element exceeds the available width, a horizontal scrollbar will be displayed

I have a scenario where I am using an absolute div to overlap another div. The div that overlaps is the absolute one (.content), and if the overlapped div (.left) doesn't fit the screen width, a horizontal scroll bar does not appear. How can I automat ...

Refresh a partial view in Rails using AJAX with JSON feedback

Whenever I make a call to $.getJSON, my goal is to refresh the tbody elements. This means that I need to remove all current elements and replace them with new elements based on the JSON response. Javascript $(document).ready(function(){ $('#positi ...

Is it possible to automatically resize my text below an image using only HTML and CSS?

I need my text wrapper width to automatically shrink below an image. For instance: <figure> <img src="mypicture.jpg" /> <figcaption> This is a lengthy description. This is a lengthy description. This is a lengthy descrip ...

Using JavaScript import may encounter issues when trying to access the same file or a different file

When importing something and using it, there are certain scenarios where it may not work as expected. For example: <html> <body> <button onclick="foo()">Click Me</button> </body> <script type="module"> ...

Leveraging HTML5 Semantic Tags in Harmony with the BEM Approach

Would it be beneficial to utilize HTML5 semantic elements alongside BEM? For example, is <header class="header header--full"> <nav class="header__nav">...</nav> </header> Acceptable or should I opt for divs instead? ...

Eliminate screen flickering during initial page load

I've been developing a static website using NuxtJS where users can choose between dark mode and default CSS media query selectors. Here is the code snippet for achieving this: <template> <div class="container"> <vertical-nav /> ...

Achieving (keyup.enter) event on an option within a datalist in Angular 6

How can I trigger the (keyup.enter) event on an option within a datalist in Angular 6? This is my HTML Code: <input list="filteredArray" (keyup)="filterEmployee(empForm.controls['empname'].value)" type="text" formControlName="empname" /> ...

Google fonts are being blocked by Chrome version 37.0.2062.102m

I encountered the following issue while using the latest version of Chrome: Redirect at origin '' has been blocked from loading by Cross-Origin Resource Sharing policy: The request was redirected to a URL ('about:blank') which ha ...

Update the page using Ajax without relying on jQuery

I want to implement automatic page updates without the need for a refresh using Ajax. However, most resources I've come across suggest using jQuery and PHP, which are areas of coding I am not very familiar with. My goal is to integrate Ajax into my HT ...

Interacting with a JavaScript button using C# WebBrowser

Can someone please assist me with a problem I'm facing? I have a webpage coded in HTML and Javascript. Whenever I use webBrowser1.Document.GetElementById("hmenu").InvokeMember("click");, the menu pops up on my screen. However, I am unsure how to cli ...

The "list-group" class is not functioning properly in Bootstrap 4

I've been diligently working on a project with Bootstrap 4. In one particular section, I need to display images in rows within a list-group that pulls images from a folder. However, when using Bootstrap 4, the image sizes are too large, unlike when I ...

Display loading spinner and lock the page while a request is being processed via AJAX

Currently, I am working on a project using MVC in C#, along with Bootstrap and FontAwesome. The main objective of my project is to display a spinner and disable the page while waiting for an ajax request. Up until now, I have been able to achieve this go ...