Gap between two div elements side by side

Take a look at this simple code - fiddle here.

The CSS is as follows:

.subcontent > div {
    display: table-cell;
}
.orangebox {
    width: 55%;
    background-color: red;
    padding-top: 6px;
}
.bluebox {
    width: 43%;
    background-color: blue;
    padding-top: 60px;
}
.spacer{
    width: 1%;   
}

The code showcases two types of boxes, one styled with "orangebox" and another adjacent to it in the same line styled with "bluebox". Both have the property "display: table-cell".
Between these two boxes, there is the "spacer" that creates space between them using a width of 1%.
The issue arises when zooming in or out on the webpage (CTRL + or -), as the spacer starts expanding beyond 1% during zoom out, gradually decreasing its size. Additionally, deep zooming causes the spacer to disappear, leading to overlap between the two boxes.
Is there a solution to maintain a fixed space between the two boxes regardless of zoom level?

Answer №1

If you're looking to create space between elements using table properties, I suggest setting border-spacing: 10px; (or your preferred amount) on the parent element with display: table;. This method is highly effective for spacing elements.

For more precise control over spacing, you might need to explore alternatives to table-cell layouts. Hopefully, this solution will meet your needs!

You can see an updated version of the layout in action in this fiddle showcasing the use of border-spacing:

http://jsfiddle.net/vBngZ/7/

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

Variations in CSS Stylesheets for Various Parts of the Body

Currently, I am in the process of creating a single page website. One issue that I have encountered is needing a Bootstrap "modal" class popup to appear when a button is clicked. However, the template I am utilizing was designed using Bootstrap Version 1, ...

Unusual patterns appearing in HTML image files

As a beginner in html, please pardon my silly questions and mistakes. I have designed this webpage: <!DOCTYPE html> <html> <head> <meta charset = "UTF-8"> <style type = text/css> #topbar { ...

Tips for implementing custom styles on React components that have been imported locally

I'm currently struggling with applying CSS successfully to components imported from an npm library. My main challenge seems to be my use of css-loader in the react starter kit (https://github.com/kriasoft/react-starter-kit) without a full understandin ...

Warning message in ReactJS Material UI Typescript when using withStyles

I am facing an issue even though I have applied styling as per my requirements: Warning: Failed prop type validation- Invalid prop classes with type function passed to WithStyles(App), expected type object. This warning is originating from Wi ...

Is it possible for webkit CSS resize to not function properly when applied to a canvas element that is

Consider this HTML and CSS code snippet: #box { width: 100px; height: 100px; overflow: hidden; resize: both; border: 1px solid black; } #content { width: 100%; height: 100%; } <div id="box"> <canvas id="content"> ...

Menu is not functioning properly as it is not staying fixed in place

I am trying to create a fixed menu that sticks to the browser window as it scrolls. However, I am encountering an issue where the transition from sticky to fixed is not smooth when I remove position: relative; from navbar__box. window.onscroll = functio ...

Issue encountered: Angular 4 CLI not converting scss to css during ng build process

After running ng build, the dist folder does not properly convert the scss files to css. In my assets folder, I have a main.scss file and in the .angular-cli.json file, it is configured as: "styles": [ "assets/scss/main.scss" ], ..... "styleEx ...

Hover Effect in JavaScript

After thoroughly checking all the duplicates below, I still couldn't quite figure out how to achieve the desired effect. Here are some resources I looked into: make animation hover like transition hover JS hover-like animation Hover animation with js ...

A text box will appear when you click on the edit button

When the edit button is clicked, I need to display text boxes and list boxes. Can someone please provide suggestions on how to accomplish this? HTML: <div class="textboxes"> <ul> <li><input type="text" id="txt" /></li> ...

Animate the rotation of specific paths within the SVG

I've designed an SVG using Illustrator and I have a specific animation in mind for it. My goal is to create an animation where the upper part of the circle line rotates from left to right (considering that there are 4 circle lines, with number one st ...

Is there a way to position the search bar on a new line within the navigation bar when the screen size is at its maximum width for mobile

I have a search bar on my navigation bar, but I am looking to move it to the next line within a maximum width if the screen display is extra small (xs) or for mobile devices. Below is the code snippet: <nav class="navbar navbar-expand-md fixed-top ...

CSS filling a height percentage from the bottom up to the top

I have a container div containing a transparent image with only a border. Here is an example: In the "dislike" case, I am able to dynamically change the container's height percentage so it appears as if the figure is being filled. As the height grows ...

Have you ever wondered how the automatic video play on scroll feature works on Tiktok.com and YouTube shorts when using a mobile device?

My goal with React JS is to develop a website similar to Tiktok, where the video below will automatically play with sound as the user scrolls down. I attempted to set this up using window.addEventListener("scroll",...), but after looking into it further, ...

Is there a way to produce a unique color using Stylus CSS?

Currently, I'm utilizing Express for Node.js and Stylus as the CSS engine. While Stylus is great, I'm facing some challenges in passing color variables or generating random colors. Despite attempting to use the javascript API for stylus, I find m ...

The impressive wipe effect in velocity.js using css and jquery

I am looking to achieve a slide effect similar to Powerpoint's wipe using css, jquery, or velocity.js. Here is a video showing the desired effect: https://www.youtube.com/watch?v=VSBB0wfccws I attempted to use css3 masking (svg/gradient) but was uns ...

Why isn't my ng-click event working in Ionic/AngularJS?

I'm currently experimenting with Ionic/AngularJS, but I'm having trouble getting an alert window to appear. I began with a blank template in Ionic, and while the app launches in the browser window, nothing happens when the button is pressed. / ...

Tips for switching back and forth between two classes using jQuery?

I'm having some trouble with the toggleClass function. It doesn't seem to be working correctly for me. The image should toggle between displaying and hiding, but it only changes to hide, not back again. You can view my example here, along with t ...

Utilizing Vue.js and Webpack to Handle Requests for Multiple Incorrect Resource Links

After utilizing Vue.js single file components to construct a website and appreciating the modular approach, I've encountered an issue. The browser appears to be requesting multiple versions of resources instead of just one URL for each. HeaderBar.vue ...

Avoid loading the background image by utilizing CSS to set the background image

Whenever I attempt to assign a background image using CSS, it triggers a console error. This is my CSS code: body { background-image: url("background.png"); background-repeat: no-repeat; } The error message displayed is: GET http://localhost/myWeb/ ...

Is there a way to adjust the width of the datepicker on my device?

I've been attempting to adjust the width of the date picker, but I'm having trouble achieving it. Below is my code: import React from "react"; import ReactDOM from "react-dom"; import { DatePicker, RangeDatePicker } from &qu ...