Issues with Css box-sizing and jquery width not being applied correctly

I've been struggling with this issue for hours and can't seem to figure out why the layout is not working as expected. I have a combination of fixed and fluid columns, box-sizing properties, borders, and a jQuery width setting in place. My goal is to have the left column be 170px in width, while the middle and right columns should each be 50% of the parent container's width minus the left column. However, the borders are overlapping and the middle and right columns do not have equal widths for some reason. Can anyone offer any assistance?

http://jsfiddle.net/Alga/9LGA9/7/

$('#middle').width(function () {
         return ($(this).parent().width() * 0.5) - 85;
     });

$('#right').width(function () {
         return ($(this).parent().width() * 0.5) - 85;
     });

Answer №1

Instead of using .width(), try utilizing .outerWidth() for a more accurate result. I have also replaced the fixed value of 85 with $('#left').outerWidth() / 2 to ensure dynamic functionality.

For further reference, you can visit this link: http://jsfiddle.net/9LGA9/11/


function adjustColumns() {
 $('#middle').outerWidth(function () {
     return ($(this).parent().width() * 0.5) - $('#left').outerWidth() / 2;
 });

 $('#right').outerWidth(function () {
     return ($(this).parent().width() * 0.5) - $('#left').outerWidth() / 2;
 });
}

adjustColumns();

$(window).on('resize', function () {
     adjustColumns();
});

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

Slider with Dual Images: A Visual Comparison

I'm currently working on a webpage that features before and after images using a slider based on mouse movement to display both pictures. I am trying to incorporate multiple sliders on the same page but have been facing difficulties in getting them to ...

Validation process following submission within a modal popup in a partial view

I have a modal window that pops up when a button is clicked, containing a partial view with some fields and a submit button. Upon submission, the data from the partial view is added to the database and the user is redirected back to the original view. Ever ...

Trouble with ScrollTo animation on div with adjustable offset top feature - seeking assistance

Having trouble navigating to the correct slide when clicking the right button on the navigation menu. Clicking the menu button displays a list of links. Clicking on a link for the first time will take you to the correct slide, but if you try clicking a dif ...

Initiate a click action upon receiving a focus event

I can't seem to figure out why this code is not functioning as expected: $('a').focus( function() { $(this).click(); }); Context: I am working on developing a form where navigating through different elements (such as textboxes) will au ...

"Enhance your data visualization with jQuery tree tables and JSON data

Currently, I am working on a tree table project where I need to convert JSON data into a tree table format. After doing some research online, I came across jQuery Treetable which seemed like a good fit for this task. I have successfully created the JSON da ...

Troubleshooting: Why isn't my CSS fixed position working for my sticky

I have a simple jQuery code snippet that is supposed to make the navigation element sticky by applying a class with position: fixed. However, I'm facing an issue on my Commerce platform where the fixed position property doesn't seem to work corre ...

Utilizing the smallslider feature through jQuery/JavaScript operations

I've recently embarked on the journey of learning JavaScript/jQuery. I've been attempting to incorporate this cool effect, but unfortunately, I'm facing some difficulties with it: My goal is to understand how to execute this effect using Ja ...

Guide on downloading jsreport in .Net using C# without opening it

I am using JS Report to generate a file and save it in the root directory. However, I want the file to be downloaded directly instead of opening for viewing. var header = await _jsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "H ...

Load only specific columns in jqGrid to enhance performance and streamline data display

When working with jqGrid, I have implemented selectable columns to display only certain columns. Now I need to figure out how to store the selected column names in a database so that when loading the grid again, only those selected columns are displayed. ...

Stop the reloading of the parent page when the exit button is pressed on the popup screen

I have set up a modal popup that appears when a user clicks on a specific link. Inside the popup, I have included an exit button to close it. However, I am facing an issue where clicking on the exit button not only closes the popup but also reloads the par ...

The navigation buttons on the Bootstrap carousel will only respond to keyboard commands after the arrow on the

Is there a way to change the default behavior of the bootstrap carousel to allow keyboard navigation without having to click the arrows on the screen first? In my modal, I have a carousel that I want users to be able to navigate using the keyboard arrows ...

Using the clip-path property to determine the content padding within a div

I am encountering an obstacle while attempting to insert icons into a polygon-shaped div. The problem lies with the padding, as the icons get cut off by the borders of the polygon. #container { width: 200px; height: 200px; border: 2px solid blac ...

Fluid design: prevent alteration in body width caused by vertical scrollbar

I have successfully implemented a liquid layout for my website by setting the body tag width to 100%. <html> <head> </head> <body> <div id="container"> some content </div> </body> body { mar ...

An innovative way to display or hide a div depending on the multiple selections made in a select2 jQuery field

A select2 jQuery dropdown menu is set up with two options: *For Rent *For Sales If the user selects 'For Rent', specific fields will be displayed below it, as well as for 'For Sales'. The challenge arises when both options are ...

Show text and image side by side on the same row

I am looking to showcase both image and text on the same line, similar to how it's done on tripadvisor.in/ <div style="display:inline-block"> <div style="display:inline;float:left"> <a href="CollegeProfile.php" class="white"> <h ...

The perplexity of CSS Menus

I have this HTML code, but I'm not sure how to write the CSS so that the drop-down menu appears when I hover over the main li. <li><a href="#">#</a> <ul class="sub_menu"> <li><a hre ...

How to Perfectly Align a Gif

I'm trying to understand the functionality behind this code snippet. Can anyone shed some light on it? img{ display:block; margin:auto; } I attempted to center a gif using this code block after my teacher suggested trying align:center; without succe ...

Troubleshooting SCSS Compilation Problems in Vue.JS

I am currently working on a vue.js web application and I want to incorporate SCSS. To do this, I have installed npm i node-sass sass-loader. Additionally, I have created a vue.config.js file at the root level of my project: module.exports = { css: { ...

Achieve a vertical scrolling effect within an ASP repeater by implementing CSS2.1 styling

I am having an issue with my aspx page where I need to call a repeater. The problem is, I want to have a fixed-sized page while keeping the scroll inside of the repeater. How can I achieve this? The div in my ASP wouldn't accept the overflow-y option ...

IE11 alternative for the CSS property "unset"

I have a div fixed to a specific location on my webpage using the following CSS properties: width: 320px; height: 160px; position: fixed; right: 15px; bottom: 15px; top: unset; z-index: -1; While the div displays correctly in other browsers, in Internet ...