Determining the Width of one div based on the Width of another div

I have organized two divs in a grid layout like this:

<div>
    <div class="col-1-10 a">...</div>
    <div class="col-9-10 b">...</div>
</div>

My goal is to set the minimum width of the div with the class col-1-10 to 85 px in order to accommodate specific items as required. The other div with the class col-9-10 should take up the remaining width.

Currently, I am using the following CSS:

.a{
    @media (max-width: 850px){
        width:85px;
    }
}

.b{
    @media (max-width: 850px){
        max-width:765px;
    }
}

While this solution works for the first div, the second one ends up being displayed below rather than inline. Essentially, I want the width of the second div to be equal to the width of the parent div minus 85 pixels, and all done through CSS alone

Any assistance on achieving this would be greatly appreciated.

Thank you in advance

Answer №1

There are several options available for displaying content, ranging from float (content standing side by side) to utilizing table, flex, or grid (content standing in columns): Here are 4 'easy' ways:

  • float is understood by all browsers.

  • table/table-cell have been part of the CSS specification since 1998 (usable from IE 8 ...).

  • Flex is usable with modern browsers.

  • grid can be used in Chrome and Firefox if experimental CSS is enabled.

Test the behavior in your browser using the snippet below:

Code examples here...

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

Inserting a singular image following a designated list item

I have a question that may seem silly, but I'm trying to understand a specific CSS styling issue. I want to add an image targeting a particular li item. Currently, the code adds the image after all the li items: .menuStyling li:after{ content: u ...

Guide to aligning 2 divs side by side using bootstrap

I have been experimenting with different methods like col-xs-6 for the first child, but I can't seem to get it right. How can I achieve this layout using only Bootstrap? Despite trying col-xs-6, I still haven't been able to place these divs next ...

Develop a dynamic button using JavaScript to fetch information from an array

I'm struggling with incorporating this button creation code into my HTML using JavaScript. The code for creating the button element in JS file looks like this: var numery = ['A','B','C']; var numer = document.createE ...

Improvement in Select2 Change Event: Update the subsequent select2 box options based on the value change in the preceding select2 box

I need assistance with two select boxes, namely Category and Sub-category. My objective is to dynamically alter the available options in the subcategory box based upon the value selected in the category box. Additionally, I would like to load data for the ...

Unlimited highway CSS3 motion

I have come across a stunning 2D Highway background image that I plan to use for my mobile racing game project which involves JS and CSS3. The image can be found at this link. My goal is to create an animation of the road in order to give players the illu ...

What is the best way to implement Infinite scroll alongside Virtual scroll in Ionic 3?

Having recently delved into the world of Ionic and Angular, I am encountering some difficulties with implementing Infinite scroll alongside Virtual scroll. Despite pushing data such as images, text, and click functions from TypeScript, only empty Ionic car ...

Updating a div periodically with Ruby on Rails: The ultimate guide to implementing Ajax or alternative techniques

In my show.html.erb file, I have a div (with id "mydiv") that needs to be updated every few seconds with data from the server. To accomplish this, I am using AJAX with setInterval to fetch the latest information from the backend. However, I am unsure of ho ...

CSS: The relative positioned element now functions correctly with the inclusion of overflow-x

Is there a way to ensure that the images in the day_time_block cover the title class? I would also like all contents within the day_time_block to be displayed using overflow-x. However, when I add overflow-x: auto; to the scroll div, the images in the d ...

Stylish CSS dropdown menu with borders and a subtle shift

I am struggling to create a dropdown menu as shown in this image: Solution for CSS dropdown menu. Unfortunately, my current code is not producing the desired result: Here is my incorrect solution This is the code I am using: .parent-menu li { ...

Position elements flush to the left and right

Is it possible to align the text in divs so that it perfectly lines up along the edges? .name { margin: 0 0 5px 10px; font-weight: bold; font-size: 14px; } .row { margin: 0 0 5px 10px; width: 500px; justify-content: space-between; } < ...

Simple Method To Dynamically Align jQuery LightGallery Thumbnails On a Responsive CSS Website

Can anyone assist me quickly? I've implemented everything but am facing a slight issue with the centering of my ul code. I've tried various solutions without success. Here is my code, any advice would be greatly appreciated (I may sound stressed ...

The Carousel is covering up my Mega-Menu and it is not visible on top

I'm facing an issue where my mega menu is hidden behind the carousel, and I need it to show on top. You can see how it looks before adding the carousel and after adding the carousel from Bootstrap. Here are the links to the Mega Menu CSS and Mega menu ...

What are some techniques for styling a label element with an empty for attribute using CSS?

Here is what I currently have: <label class="filter-label" for="pv[]181"> ::before white <span class="count">5</span> ::after </label> My goal is to modify the ::after element within that label, but so far my attempts ...

Safari experiencing a CSS issue not found in Chrome or Firefox

https://gist.github.com/2354116 When you check the link above in Chrome or Firefox, everything looks good. The divs at the bottom, including the headings and social icons, are centered within a container div without any issues. However, when viewed in Sa ...

When pressed, the button changes color to a vibrant shade of blue, and not just a simple outline

I'm experiencing an issue with a button that turns blue when the user holds onto it for a while on mobile. You can see an example in the image below: https://i.sstatic.net/VmnZ8.png Adding ::selected or outline did not resolve the problem as the ent ...

Identify whether the page is being accessed through the Samsung stock browser or as an independent web application

Hey there! I am on a mission to determine whether my webpage is being accessed through Samsung's default browser or as a standalone web app saved on the homescreen. Unfortunately, the javascript codes I have come across only seem to work for Safari an ...

Switching text appearance upon checking the checkbox

I am currently working on a Vue.js app for a To Do List. I have a feature where you can add tasks to a list, each with its own checkbox. I want to implement a feature that puts a line-through text style on an item once its checkbox is marked. Can anyone pr ...

Access menu options by hovering over the image

I am looking to create a hidden menu that only appears when I hover over an image. I attempted to follow a solution on Stackoverflow, but it did not work for me. Is there a way to achieve this using just CSS? Html: <nav class="navbar navbar-inverse na ...

Using double quotes when adding HTML5 local storage entries

Currently, I am setting the value of a field to a variable like this: newUser = document.getElementById('userName').value; Then putting that variable into local storage: localStorage.setItem('userName', JSON.stringify(newUser)); Fet ...

Two pictures, one adjusting in size and one staying the same size

I am working on a design with an 800px wide div that contains side-by-side images - one photo and one map. The challenge I am facing is that the map, which is 300px in width and has intricate details, becomes unusable when resized for smaller screens. I wa ...