Padding between three evenly spaced divs that adjust to different screen sizes

I need help with creating three divs with equal width, where the third div expands to full width below a 991px breakpoint. Additionally, I want all the divs to stack upon each other when the browser width is below 767px. I also require equal margins between the divs and at the edges. Is there a way to achieve this using just CSS without any frameworks?

Below is the CSS code snippet:

* {
  box-sizing: border-box;
}
h1 {
  margin: 25px;
  text-align: center;
}
div[class|=col] {
  position: relative;
  margin-bottom: 10px;
  border: 1px solid black;
}
html,
body {
  margin: 15px;
}
.title {
  border-left: 1px solid black;
  border-bottom: 1px solid black;
  width: 25%;
  position: absolute;
  top: 0px;
  right: 0px;
  color: black;
  text-align: center;
}
#Title1 {
  background-color: orange;
}
#Title2 {
  background-color: white;
}
#Title3 {
  background-color: green;
}
p {
  background-color: gray;
  width: 100%;
  margin: 0px;
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 25px;
  font-family: Helvetica;
  color: black;
}
.row {
  width: 100%;
}
<div class="row">
  <div class="col-lg-4 col-md-6 ">
    <section id="Title1" class="title">Chicken</section>
    <p>Some text</p>
  </div>

  <div class="col-lg-4 col-md-6">
    <section id="Title2" class="title">Beef</section>

    <p>Some text</p>
  </div>

  <div class="col-lg-4 col-md-12">
    <section id="Title3" class="title">Sushi</section>

    <p>Some text</p>
  </div>
</div>

Answer №1

Assign specific classes to three div elements: div-1, div-2, div-3

@media only screen and (max-width:766px) {
     .div-1.div-2.div-3 {
         margin-bottom: 10px;
     }
}

This method allows you to apply margins based on a specific screen resolution.

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

Top method for creating a structured list based on file paths

My Ruby on Rails page is struggling with slow performance. It's currently generating a hierarchical, unordered list using recursive SQL calls, which has proven to be inefficient. After optimizing the SQL query to retrieve the necessary hierarchy infor ...

When content editable is assigned a value, it skews the direction of the writing

I am currently working on an editable text component with the 'editable' attribute. However, I am facing an issue where the text is not aligning in the correct direction as I type - the first character always ends up at the end of the text. Expe ...

"Combining ASP Repeater with JQuery Carousel for a Seamless User

Incorporating ASP Repeater into a JQuery Carousel, similar to the example provided in this link, has proven challenging. Despite adding all necessary references and links to my .aspx page, the code implementation is not displaying as expected: < ...

Using the html5 file reader API in JavaScript to retrieve a file as a binary string and then sending it through an ajax request

I'm attempting to obtain the binary string of files, but I seem to be unable to do so. Why does readAsDataUrl work while readAsBinaryString doesn't? I have posted my code on jsbin and any help would be greatly appreciated. Thank you. Check out ...

Align labels and inputs to the right in the contact form

I'm having trouble aligning labels and inputs in my contact form. They need to be aligned to the right due to the Hebrew language. Here is a link to the fiddle of my code which is not working, you can see that the input boxes are not aligned. I need t ...

Trouble with Javascript slideshow: Incorrect display and malfunctioning

Struggling with implementing a slideshow banner on my webpage, despite following the W3 tutorial. Here is the code I am currently using: HTML: <div class="slide-content" style="max-width:1000px"> <img class="slidepic" src="testheadphoto.jpg" st ...

Not every form input is suitable for placement within a card design

I'm currently using the most up-to-date version of materializecss and have the following HTML code: <div class="container"> <div class="section"> <!-- Main content --> <div class="row"> <di ...

Arranging pseudo elements using CSS Grid

I am currently working on positioning pseudo-elements on a grid, following the specification. It seems to be working well for my overall layout set on the <body>, however, I am facing difficulties when it comes to the <header> element which is ...

Display and conceal elements within predetermined time intervals using jQuery, while ensuring that the final element remains visible

Is there a way to automatically hide div1 and show div2 after a set amount of time, let's say 10 seconds or 15 seconds? I came across this thread: Show and hide divs at a specific time interval using jQuery, However, the solution provided in the po ...

Is there a way to set up a basic form on my website (cPanel based) that is only accessible during specific time frames?

Every week, I host a conference and I want to keep track of which participants are present. I want attendees to visit my website, input their name, and click "Enter". Then, I want their information to be saved in a database on my website. My website is man ...

Utilizing values from .properties files in Java with Spring for internationalization: A straightforward approach to handle Strings

Here is the code snippet I am using: @Value("${app.user.root}") private String userRoot; This code helps me to fetch a constant value from my application.properties file. Within my GetMapping method, I need to redirect to the error page and pass a S ...

Place the label and input elements next to each other within the form-group

My form group includes both a label and an input field <div class="col-md-12 form-group"> <label class="col-sm-2 col-form-label" for="name">Name</label> <input type="text" class="form-control" name="name" id="name" [(ngMode ...

Two boxes each taking up half of the width, with content placed inside a container

How can I achieve the appearance seen in this image? https://i.sstatic.net/2oZW8.png The layout consists of four columns using regular Bootstrap code. The first two columns should have a white background within a .container, while the other two columns s ...

What is the best way to design a consistent navbar that can be used across multiple HTML pages using Bootstrap 5?

Preferably, I would like to achieve this using only JavaScript without the need for a JavaScript framework in my project. Layout: ./index.html ./about.html ./crew.html ./flights.html ./events.html I am looking to create a consistent navbar across all ...

Are custom HTML tags in Angular 2 truly safe? Exploring the safety of custom tags compared to custom attributes

Here we delve into the realm of Angular 2 selectors, comparing Custom tags versus Custom attributes in relation to SEO and browser rendering. Upon embarking on my Angular 2 journey and altering the selector to '[my-component]' (attribute selecto ...

steps for aligning an enlarged div in the middle upon hovering?

This situation presents a unique challenge. Below is the HTML code. <div class="foo"> <div class="bar"> <div class="a"> <h2>Luigi's Mansion1</h2> <small> ...

Exploring JQuery 3.1.1 in combination with the powerful CSS flexbox techniques

When utilizing the fade functions in JQuery, an element that initially has 'display: none' and is then faded out will have JQuery inject 'display: block' when faded in. In a flexbox layout, this can cause the element to wrap to the nex ...

Techniques for breaking down large CSS files into modules and combining multiple smaller CSS files

My website's CSS file is currently massive, containing site-wide selectors in a file named Mondo.css. While this setup has been effective for ensuring users only need to download the file once, I've recently developed a widget that requires its o ...

Streamlined method for handling child elements within the DOM

I am striving to achieve a randomized shine effect on specific text using CSS animation. I currently have a functioning code, but I am interested in learning if there is a more efficient or straightforward solution. HTML: <span class="foo"> < ...

I encountered an issue with my shopping cart while using ReactJS

this is the App.js file import React from "react"; import ListProduct from "./listProduct"; import ListOrder from "./listOrder"; import pizza from "./pizza.jpg"; import './style.css' import { Container,Row,Col,Button } from 'react-boo ...