Equal widths that adapt and respond to different screen sizes

Currently, I am in the process of transforming a 960grid 12col responsive design into HTML. There are three separate div elements, each with a width of 300px and a margin-right of 20px. Below is the code snippet that illustrates this:

HTML

<section class="container">
    <h1>Services</h1>
    <div class="box">
        box1
    </div>
    <div class="box">
        box2
    </div>
    <div class="box last">
        box3
    </div>
</section>

CSS

.container{
      max-width: 960px;
      width: 98%;
      margin: 0 auto;
      padding: 0 1.04166666666667%;/*10px / 960px*/
}
.box{
     width: 31.25%;/*300px / 960px*/
     margin-right: 6.66666666666667%;/*20px / 300px*/
     float: left;
     background: red;
     margin-bottom: 10px;
}
.last{
   margin-right: 0;
}

I'm facing an issue where the div element with the "box" class does not completely fit inside the container div. As a result, the last div breaks the line and appears below the other two div elements. You can view the problem here. I am uncertain about where I may have made an error in my implementation.

Answer №1

The issue seems to be with your margin-right setting.

You should set it to 20 divided by 960, which equals 0.020833333333333333333333333333333, or approximately 2.08%.

Remember, in responsive design, margins are typically calculated based on the parent container, not the child element.

Answer №2

You currently have 3 boxes with a width of 31.25% each and an additional margin of 6.67% on each box, except for the last one. This totals to 107.09% width, which is too wide for its container.

To make it fit, reduce the numbers so that they add up to less than 100%.

Remember to calculate the margin-right by dividing 20 by 960.

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

What is the best method to align subtitles in an HTML5 video player? Tips for enhancing the style of subtitles/captions

I am facing an issue where the subtitles in my video do not play in the middle-bottom as desired. I have tried to style them using CSS but they just won't align to the center. The subtitles always appear at the bottom left of the video. Here is the H ...

Pedaling back and forth along a sequence

Is there a way to implement forward and backward buttons for a clickable list without using arrays, as the list will be expanding over time? I have already achieved changing color of the listed items to red, but need a solution to navigate through the list ...

Having trouble integrating SVG icons into my Angular project

I'm encountering an issue with adding icons that I've designed in Figma to my web application. Some of the icons are displaying correctly while others are not. Here is the code snippet I am using to add the icons: .dx-icon-info { mask-image: ...

Do class bindings with variables need to be inline when using Vue 3?

Consider the following HTML: <template v-for="(child, index) in group"> <div :class="{'border-pink-700 bg-gray-100 ': selected === child.id}"> <div>Container Content</div> </div> & ...

Can you help me with compiling Twitter Bootstrap 3.0 on my Windows 8?

Can anyone guide me on compiling Twitter Bootstrap using Less on a Windows machine? I tried following a tutorial but ran into issues with installing lessc (it was not in the npm registry). Also, the tutorial was for BS2 and not 3.0 which made me skeptical ...

What is the significance of the space between form.validate and .ng-invalid-email.ng-dirty?

I'm currently working on an AngularJS application and I'm confused about the spacing between "form.validate" and ".ng-invalid-email.ng-dirty" in the stylesheet code below: <style> form.validate .ng-invalid-required.ng-dirty {background ...

How do I activate validation within bootstrap4 using bootstrap-validate?

I am working with a validation form in Bootstrap4 that displays an error message when less than 5 characters are entered. If I enter 5 or more characters, I want to show a green check-mark and border around that specific input field. <div class="con ...

Hide the popup menu when the user clicks outside of it

I am presenting the following code <!DOCTYPE html> <html> <head> <title>GalacticCraft</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link rel="shortcut icon" type="image/png" href="fa ...

How can I add rows to the tbody of a table that is already inside a div container?

I have an existing table and I want to append a tbody element to it. Below is an example of the HTML table: <div id="myDiv"> <table class="myTable"> <thead> <tr> <th>ID</th> ...

What's the connection between CSS and frameset?

Currently, I have an .html document with XHTML 1.0 Frameset doctype and the following code: <frameset rows="20%, 80%" border="1"> ... </frameset> Upon validating this code on W3C Validator, it gives me the error message: there is no a ...

Tips for perfectly aligning elements (such as text and images) within the navbar

Hi everyone, I hope you're doing well. Currently, I'm working on aligning a small icon with some text. I've tried using the d-inline class inside the a tag, but it doesn't seem to be working. Another issue I'm facing is related to ...

Ways to animate elements while scrolling in React.js?

I am new to using React.JS and currently working on setting up an E-commerce Store. My goal is to have 5 images stack on top of each other and move together as the user scrolls. I used to achieve this effect in Vanilla JavaScript by adding a window.addEven ...

Learn how to incorporate unique breakpoints in Bootstrap 4 and effectively utilize responsive breakpoint mixins in SCSS for a tailor-made responsive design

I am currently developing an Angular 5 application that requires responsiveness. I am encountering difficulties in making it responsive for different resolutions such as 1366X768 and 1920X1080 where font sizes vary. Issue 1: I have customized breakpoints ...

solving the issue of CSS not loading properly on the live server

My current website is hosted on a server with the URL as follows: test1.test.com However, I need to move it to another hosting service that does not support this configuration. I had to change the URL to: test.com/test1 Everything seems to be working f ...

I am puzzled as to why the text color of the navbar is not changing in my code

Struggling to customize the navbar text color using bootstrap and CSS? Despite trying multiple methods, changing the navbar text color seems to only work with inline CSS. Seeking assistance in resolving this issue from anyone knowledgeable in web developme ...

What is causing the inconsistency in the widths of these HTML elements?

I recently created multiple div elements with a uniform width of 5px. Here is the CSS code I used: div { background-color: black; width: 5px; height: 100px; display: inline-block; } To my surprise, despite setting the same width for all divs, som ...

Progress bar using jQuery inside a list of tree folders in CSS

I have a folder tree structure and I would like to include a progress bar alongside each folder name, which is also a clickable link. The progress bar will be created using jQuery UI. The pblabel element should appear on top of the progress bar. The bar e ...

Excessive Empty Area beneath <td>

I'm currently working on creating an e-book and I have encountered a concerning issue. The <figure> and <figcaption> elements are appearing as unknown tags in Sigil. To work around this problem, I decided to use a <table> for display ...

Trouble with CSS: Struggling to apply margins to a line of images in React JS

I've encountered an issue where I can't seem to add margin to the row of images. The margin appears fine without any CSS when viewed on a wide screen, but once I scale it down to mobile view, the margin disappears completely. Even after attemptin ...

ul/div element not displaying background color

I am attempting to showcase navigation items horizontally within a blue colored ribbon. Despite my efforts, the background-color property is not being applied to the ul element. I even tried enclosing it in a div element with a blue background, but still n ...