When three floated divs are placed within a container of fixed width, one of the divs will drop down to the next line once all three divs reach

Confusing title, but I couldn't find a better way to explain it. The issue I'm facing is having 3 boxes in a row with only a 1px border on each side, but for some reason, the far right one has a 2px border. How can I fix this?

Take a look at the code:

#content {
  width: 1016px;
  min-height: 664px;
  height: auto;
  border: 1px solid #232323;
  background-color: #12100e;
  float: left;
  padding: 0px;
}

#imagebox {
  Width: 338px;
  height: 221px;
  padding-right: 0px;
  padding-left: 0px;
  border-right: 1px solid #232323;
  border-bottom: 1px solid #232323;
}

<html>
  <head>
    <link rel="StyleSheet" href="Main.css" type="text/css">
    <title></title>
  </head>
  <body>
    <div id="mainbody">
      <div id="menu"></div>
      <div id="content">
        <div id="imagebox"></div>
        <div id="imagebox"></div>
        <div id="imagebox"></div>
        <div id="imagebox"></div>
        <div id="imagebox"></div>
        <div id="imagebox"></div>
        <div id="imagebox"></div>
        <div id="imagebox"></div>
        <div id="imagebox"></div>
      </div>
    </div>
  </body>
</html>

Answer №1

The reason for this issue is that the right-hand border is adding 1px to the total width of the #imagebox element, resulting in a width of 339px.

To resolve this, you can attempt to reduce the width to 337px, which may accommodate all the items properly.

Answer №2

Here is the closest solution:

http://jsfiddle.net/CGEWC/2/

There are a few things to consider:

If you need to apply a style multiple times, use classes instead of IDs.

Make sure to use "width" in all lowercase in your CSS, even though CSS is not case sensitive.

I have added a float: left; to your image boxes.

I have also included first and last classes in your div. It may not be the cleanest code, but it should work.

Answer №3

Consider utilizing max-width in place of width for a more flexible resizing option. Simply subtract 1 from either value to adjust accordingly and convert the ids to classes for uniformity.

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

Issue with CSS 3 gradient compatibility in Internet Explorer 8

My CSS3 gradient button is working perfectly on all browsers except for IE8. To make it work on IE8, I am utilizing CSS3 Pie. You can see the search button in action by visiting: Upon inspecting my console, I noticed an error on this line: PIE.htc, lin ...

Change the button icon to something new when you hover over it

Below is the liquid code I am working with: <a href="{{ section.settings.button_link }}" class="btn--rounded"> {% include 'icon-btn--rounded' %} <div class="link-label">{{ section.settings.button_ ...

Issue with Opening OpenLayers Map after Using the Onclick Function in JQuery

I am facing an issue with my OpenLayers map on my JQM website. It seems to be failing to load properly, and I suspect that the problem lies with the onclick() method. I have explored using the .click() method on the JQuery site as an alternative, but I am ...

What is the method for creating a fixed position div that remains until a certain point?

Is there a way to prevent the position: fixed; property from being applied after a certain point on the screen scroll using only CSS? ...

Transferring a PHP session variable to JavaScript in a separate file

I successfully imported data from a CSV file into PHP and organized it into a nested array. To ensure the data is easily accessible across different files, I stored the array as a session variable. Now, the challenge lies in accessing this session variable ...

What is the proper location to place the CSS I wish to implement for a module?

As I embark on creating my inaugural DotNetNuke website, I find myself faced with the task of adding an HTML module to a page. To style the text within it, I have been advised to utilize CSS classes. I'm curious about where .css files should be place ...

Broken responsive carousel using bootstrap

Looking for some help with a responsive bootstrap carousel issue. The carousel items adjust themselves below each other when the screen size is reduced. I want them to display as single items in the carousel. Here are the screenshots and the code. Please ...

Ways to Place Image and Icons at the Bottom of a Video with CSS

I'm looking to enhance my video by adding images and icons using CSS, but I'm not sure how to go about it. The image that will serve as a profile picture and the icons should be similar to the ones shown in the image below: https://i.sstatic.ne ...

Adjust the background color of Bootstrap 4 checkboxes

I'm trying to figure out how I can modify the background color of a Bootstrap 4 checkbox in this specific scenario. .custom-control-label::before, .custom-control-label::after { top: .8rem; width: 1.25rem; height: 1.25rem; } <link rel="style ...

Altering the appearance of a component that is currently selected and in use

Currently, I have incorporated a component with its selector within another component as shown below: <div class="col-xl-4" style="margin-bottom: 30px;"> <app-patient-info-accordion *ngIf="patient" [cardTitle]=&qu ...

Vue.js V-for not rendering any content

I am currently working on populating an array with objects retrieved from an API. The objects are being fetched successfully, but I am facing issues when trying to display them using v-for in the array. Below are my data variables: data() { return { ...

Error in Bootstrap V5 Sass: Mixin not defined - when transitioning from @import to @use module system

Transitioning to the new SASS module system with @use from @import has presented some challenges, especially when working with bootstrap v5: https://i.sstatic.net/8Hy7W.png Old way: @import "~bootstrap/scss/bootstrap"; @import "~bootstrap/ ...

similar element with alternate background shade

I have a custom component that I am using multiple times on a Vue page. I want to customize the background color for each instance of this component. Here is the code for my component: <template> <div class="project-card" :style="{backgroundCo ...

ASP.NET Expandable Navigation Bar

I'm struggling to create a collapsible navigation bar for my website that works well on mobile devices. Here's the code for my navigation bar: <div style="padding-bottom: 50px;"> <header id="main-header"> <div ...

Having trouble using Selenium for Chrome to locate an element in an HTML file using C#?

I am currently utilizing Selenium to locate elements within an HTML document that is being displayed in the Chrome browser. Unfortunately, the HTML code is not created by me and appears to have numerous issues. I do not have the ability to modify how it is ...

Remember to follow the camel case convention when utilizing element.tagName(String) with jSoup

Looking to change the name of an HTML tag using Jsoup in the following way - element.tagName("p:panelGroup"); But when I run this code, the output changes the case and I end up with p:panelgroup. Is there a method to preserve the camel case in the resul ...

The jQuery script is functioning flawlessly in one specific direction

Currently, I am utilizing a basic script to alter the color of elements based on the div being hovered over. While this works smoothly in one direction down the line, when trying to reverse order and backtrack, the colors do not function as intended. The ...

Don't forget the last click you made

Looking for a way to style a link differently after it has been clicked and the user navigates away from the page? Check out this code snippet I've been using: $(document).ready(function(){ var url = document.URL; function contains(search, find) { ...

When the nav-element is clicked, it will load the new content/file.php into the div with the id of "include."

Seeking the most efficient method to load content from a php file into a designated div on my webpage, prioritizing speed, minimal performance requirements, and ease of implementation. Unsure whether it's preferable to utilize php or javascript for t ...

PHP fails to substitute the variable with its updated value, despite the fact that the value has been changed in the code

I've been working on a PHP script to manage form validation for a submission system, but I'm encountering a persistent error that's puzzling me. Here's what's happening: There's a variable named $resourceContent which gets upd ...