CSS for leaving white space at the end of one third of a container

Currently developing a website and facing an issue with the layout:

I am trying to create 3 columns of equal height with each column taking up one-third of the width. However, there seems to be a small white gap on the right side of the last column. Here is a screenshot for reference:

Click to view image

You can see the white line next to the blog image in the third column.

This is the CSS code I have used for the 1/3rd column:

.thirdBox {
  float: left;
  width: 33.33%;
  width: calc(100% / 3);
  padding: 20px 40px;
  box-sizing: border-box;
  min-height: 400px;
  display: table;
}

and here are the background images added:

.thirdBox:nth-of-type(3) {
  background: url("imagelinkhere...") no-repeat 50% 50%;
  background-size: cover;
}

Answer №1

One common issue is that when you try to set the width to 100%/3, it may end up as 33.33% in most browsers, which might not be the exact width you are hoping for.

Instead of relying on using calc() to calculate each table's width, a better approach would be to utilize display:flex; on the parent element containing all three elements that you want to display in a single row.

Unfortunately, without the context of your HTML structure, this is the extent of assistance I can offer. If you provide the HTML code, I may be able to provide further guidance.

.parentElement{
  display:flex;
}

.firstBox, .secondBox, .thirdBox {
  padding: 20px 40px;
  flex:1;
}

.firstBox{
  background:blue;  
}

.secondBox{
  background:red;  
}

.thirdBox{
  background:green;  
}
<div class="parentElement">
  <div class="firstBox"></div>
  <div class="secondBox"></div>
  <div class="thirdBox"></div>
</div>

Answer №2

Here is an example that demonstrates the use of display: table:

<div class="row">
    <div class="col">
        <div class="col-inner">
            <span>Products</span>
        </div>
    </div>
    <div class="col">
        <div class="col-inner">
            <p>Some content goes here</p>
        </div>
    </div>
    <div class="col">
        <div class="col-inner">
            <span>Contact</span>
        </div>
    &It;/div>
</Itiv>

Css:

.row {
    background-color: #999; 
}

.row:after {
  content: "";
  display: table;
  clear: both;
}

.col {
    float: left;
    width: 33.33%;
    min-height: 400px;
}

.col-inner {
    display: table;
  width: 100%;
    box-sizing: border-box;
    padding: 20px 40px;
}

.col:first-child,
.col:last-child {
    background-color: yellow;
}

.col-inner span,
.col-inner p {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

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

The custom font fails to load on a customized Material UI theme

In my React web application, I tried to implement a custom font by writing the following code: import React, { FunctionComponent } from 'react' import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles' import SofiaPro ...

I am experiencing issues with the HTML footer not displaying correctly on my website

My GitHub Pages hosted website is giving me trouble with the footer styling. No matter what I try, I can't seem to get the background color to show up: h1 { background-color: #000000; } I'm attempting to create a footer similar to the one at ...

Increasing margin and padding by a factor of two, achieved through the utilization of float and

Whenever I apply float or inline-block to elements, I notice that their margin or padding appears to be doubled. For example, the margin between the middle and bottom sections is set to 5%. However, the size of the top section is also 5%, but it is only ha ...

Efficient guide to unlock the secrets of JS height measurements

I've noticed that there are several different 'Height' related properties in JavaScript such as clientHeight, Window.height, scrollHeight, offsetHeight, and more. Although I have a general idea of what they do, I am seeking a formal and det ...

What key element is not included in this code?

I've been trying to create an interactive green circle that switches between red and green when clicked. Despite checking and rechecking my code, it's still not functioning correctly. I must be making a beginner mistake somewhere. Can anyone poin ...

Can a shadowed box feature a notch using only CSS?

I am facing a challenge with designing a layout where I am questioning whether it can be achieved using pure CSS or if images are necessary. My goal is to create something similar to the following: In this design, the <body> represents the yellow a ...

Selecting the parent span element using jQuery

Is there a better way to display text in the parent <div>'s <span>? I'm having trouble with using spans and .parent(), any advice would be appreciated. HTML: <div> <span></span> <!--the span where I need to show ...

HTML - one div's child element takes precedence over another div

My HTML page features two consecutive divs. The first div contains a child span that has a relative position, causing it to overlap the second div. I have implemented click events for both divs. However, when I click on the span that overlaps the second d ...

Discovering components with identical html attributes in Selenium

I am currently developing a web crawler using Python 3.8. My goal is to convert the table below into a pandas dataframe using Selenium, Pandas, and BeautifulSoup. <table class="no_border_top" width="95%" align="center"> ...

Tips for efficiently playing a WAV file in JavaScript by building an AudioBuffer

I'm having trouble playing the WAV file located at this link. The file plays fine in VLC and the details show that it is a Mono IMA WAV APDCM Audio (ms) file sampled at 24000Hz with 16 bits per sample. However, when I try to play the file by embeddin ...

Looking to preserve the "ALL" selection in a JavaScript-CSS filter?

On the front page, there are approximately 16 posts displayed along with a filter featuring 4 drop-down menus showcasing post categories. I have assigned category names as classes to each post div and am currently using javascript to hide them. The code s ...

Flex and Bootstrap 5.1.3 divs are not aligned with the prices

I have implemented flex from here Whenever the content text increases in size, the div and the price do not remain aligned. See image here. My goal is to achieve the following: Make sure the div maintains the same size whether the content text is long ...

Why does the "error loading page" message appear on the server when there is a PHP function inside jQuery Mobile?

I am facing an issue with a function I created in my jQuery Mobile code. It works perfectly fine on my local machine, but when I host it on the server, it does not work properly. Can someone please assist me? Here is a glimpse of the code: <!DOCTYPE ht ...

I am unable to switch my carousel to full-screen mode

I'm struggling to make the carousel fullscreen even though I've set the width to 100%. Bootstrap was used in this project. Any help would be appreciated. Thank you! <html> <head> <link href="homepage.cs ...

"Arranging elements with identical class in a single column but on separate rows using CSS grid - a step-by-step guide

I'm facing an issue with organizing choices and matches in columns using grid CSS. Currently, the match column is overlapping with the choice column. Here is how it is coded at the moment: .grid{ display:grid; grid-template-columns: 1fr 1 ...

Using Jquery to preserve the selected value in a radio button

Having two radio buttons, <div class="class1"> <span><input name="chk1" type="radio" checked="checked" id="check1"/>Option 1</span> <span><input name="chk2" type="radio" id="check2"/>Option 2</span> </div> ...

Ensure that the jQuery ajax function triggers only after the images or iframes have completely loaded

I am currently in the process of creating an online portfolio. My goal is to have project information load into the current page via ajax when a user clicks on a specific project. However, I am facing an issue with the timing of the load() success function ...

Exponential calculator in Javascript

I'm working on a basic calculator project using html5, css3 and javascript. However, I've run into an issue with the exponent button not functioning properly. Here's my code snippet: <html> <head> <meta charset = "utf-8" ...

How can links in HTML be eliminated if a certain condition is not fulfilled?

If a specific condition is met, I would like to eliminate the "a href" tag. For example, when the term "None" is present, I prefer it not to be linked. html: {% for item in responses %} <tr> <td ...

Enhancing User Experience with Interactive React Hover Effects

Hello, I have tried various combinations but still cannot get the desired background color to display when hovering over my <p> element. I am looking for a CSS-only solution and not interested in using JavaScript hover events. I would appreciate it ...