Is it necessary for the padding on the right to fill in the empty space in order to prevent other divs from occupying it?

I'm currently facing a minor issue in my code. I am attempting to create two divs: one with a width of 25% and positioned at the left 25%, and another div next to it with a width of 25% and padding-right of 25%. The goal is for both divs to occupy the entire width. However, the padding seems to be ignored and one of the four divs below is occupying that space. The layout in the fiddle provided is not displaying as expected. Instead of having two divs on one line and four divs below them, all four divs are stacked on top of each other. My main concern is that the padding is not being considered and is causing this issue. You can view the fiddle here.

To visualize, this is the desired layout that I'm aiming for.

However, reality paints a different picture as seen here.

Consider the above as the representation of the div layout.

Answer №1

If you're not quite sure about what's happening in the example provided, here is a straightforward method to achieve the desired layout:

* {
  box-sizing: border-box;
}

.row {
  display: flex;
  width: 100%;
  height: 100px;
}

.row:first-child {
  margin: 0 25%;
}

.row div {
  border: 1px solid black;
  flex: 0 0 25%;
}
<div class="row">
  <div> 1.1 </div>
  <div> 1.2 </div>
</div>
<div class="row">
  <div> 2.1 </div>
  <div> 2.2 </div>
  <div> 2.3 </div>
  <div> 2.4 </div>
</div>

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

Styling button with CSS to change its position

Can you help me position a button next to a textbox using CSS? Here is the HTML code: <div data-bind="text:name" class="my-name"></div> <div id="wrapper"> <input class="my-input"/> </div> ...

Is there a way to disable auto rotation on a website when accessed from a mobile phone?

My current solution involves the following code: @media (max-height: 480px) and (min-width: 480px) and (max-width: 600px) { html{ -webkit-transform: rotate(-90deg); -moz-transform: rotate(-90deg); -ms-transform: rotate(- ...

What are the reasons behind professional web designers opting for absolute paths over relative paths (like for CSS, Javascript, images, etc.)?

It used to be my belief that everyone utilized relative paths, like /styles/style.css. However, I've noticed that certain renowned web designers (such as and ) prefer absolute paths (http://example.com/styles/style.css). This begs the question - why ...

Why isn't it working? Looking for a script that adds a class when the element is empty?

I have a script that should add the class "leftmax" to the li element with id "spect" when the div element with id "tab2" is empty, but it doesn't seem to be working. Can someone provide some assistance? <script type="text/javascript"> $(funct ...

Changing the color of an element on click using jQuery's .css() method,

There is a table and I am using fadeToggle on the list to hide and show the table. The background of the list is green color, but I want to change the list color when hiding the table and revert it back to green when clicking to show the table. Unfortunate ...

Align elements on the left side with some space between them

Having trouble displaying a list of images inline within a div. When I float them left, they leave a lot of space and do not display properly. Can anyone help me with this issue? See screenshot below: Here is my html code: <div class="col75"> & ...

Utilize grids to ensure consistency in the width of every <li> element across the browser

Is there a way to make the ul element span the entire width of the webpage regardless of window size? http://jsfiddle.net/32hp1w5p/ ul { grid-column: 1/13; list-style-type: none; display: table; margin: 0 auto; } li { float: left; border: ...

Search Box in Motion

I found a fascinating resource on how to create an animated search box using CSS3. The only challenge I'm facing is that I need the position to be set as 'relative'. Instead of having the search box in the center of the screen, I want it pos ...

Initiating a horizontal scroll menu at the center of the screen: Step-by

I need assistance setting up a horizontal scrolling menu for my project. The requirement is to position the middle button in the center of the .scrollmenu div. Currently, I am working with HTML and CSS, but open to suggestions involving javascript as well ...

The `div` element automatically starts on a new line rather than expanding vertically

Check out my code here: http://jsfiddle.net/sfhs6ra1/ I'm facing an issue where I want the title of post #2 to be aligned next to the thumbnail image, taking up more vertical space instead of moving to a new line. Any suggestions on how I can achiev ...

Dropdown menu similar to the one utilized in Bootstrap

I am curious to understand how the drop-down menu system in Bootstrap3's tutorial page operates. It seems that it collapses all subtopics under a main topic by default, allowing users to either click or scroll to expand further. Additionally, the menu ...

CSS Styling Makes Text Invisible on Mobile Devices

Is there an alternative style I can implement to ensure mobile compatibility? I suspect the issue lies with the height value, but removing it causes my PHP code to overlap with the text. <section style="width:100%; float:left; height:100px; clear:bo ...

Modifying the background image of div elements with JQuery in a loop function is ineffective when using Google Chrome

I am facing an issue in my application where I have a for loop to change the background image of two divs. The code snippet is as follows: for (var i = 0; i < length; i++) { $("div_" + (i + 1)).css("background-image", "../imageFile.png"); ...

Guide to positioning a button and input within a Twig template using Bootstrap

I have a form in my view that includes a button and an input field with a label. Currently, the button is rendered at the same height as the label of the input field. How can I make sure the input and button are on the same line? This is the code snippet ...

Center the image and align the floated texts on each side horizontally

I've recently started learning about HTML and CSS, but I'm having trouble grasping one concept. My goal is to align two floating <p> elements on either side of a centered <img>. Here's an example of what I'm trying to achiev ...

Utilizing JavaScript to extract an image from one div and seamlessly transfer it into another div

Recently, I came across some HTML code that got me thinking. <Div id=Qimage> <a href="http.wwww.....somehitng"> <img class="postphoto" src=""> </a> </div> <Div id=Limage> <a href="www.designerzblog.com" imageanchor= ...

Experiencing problems with jQuery drop-down menus - added arrows to menu links, but menu disappears when arrows are hovered over

My website has a drop-down menu implemented using jQuery, and it works well. However, I'm facing an issue where I want to add an arrow to the links that have sub-menus. The problem is that when you hover over this arrow, technically you're not ho ...

How to shift an image to the right side of the navbar

Is it possible to change the position of an image within a navbar from left to right? I have tried using the float property but it doesn't seem to work. .logo-img{ float: right; margin: 0px 15px 15px 0px; } <a class="navbar-brand logo-img" ...

Adaptable bootstrap placement

I have created a form that includes a custom checkbox element. The issue is that the label for the checkbox is not vertically aligned with the checkbox itself. How can I adjust the label to be vertically centered with the checkbox? You can see the code ...

Reducing the size of CSS classes and IDs

I am searching for a way to automatically compress classes and ids in an .html file. This specific file is generated through a sequence of gulp commands. I attempted to use the Munch command line application, but it had adverse effects on the file by elimi ...