What are the best ways to create a responsive grid layout?

I've recently constructed a website but I'm struggling to make the tiled layout responsive. As a novice in web development, I'm unsure of how to proceed with making my site adaptable across different devices. Any guidance or assistance on this issue would be highly appreciated. Additionally, I've encountered a problem where the background image is repeating itself three times despite implementing the 'no-repeat' property in my CSS code.

HTML

<div class="grid">
  <div class="tile hvr-reveal" id="tile1">
    <div style="text-align: center;"> 
      <div class="img-with-text ">
        <p>
          <strong>
            <a href="Contact.html" style="text-decoration:none">Contact Us</a>
          </strong>
          <img src="homepage images/file242.png" alt="sometext" width="64" height="64" id="img0"/>
        </p>
      </div>
    </div>
  </div>

  <div class="tile hvr-reveal" id="tile2">
    <div style="text-align: center;"> 
      <div class="img-with-text">
        <p>
          <strong>
            <a href="products.html" style="text-decoration:none">Products</a>
          </strong>
          <img src="homepage images/shopping145.png" alt="sometext" width="64" height="64" id="img"/>
        </p>
      </div>
    </div>
  </div>

  <div class="tile hvr-reveal " id="tile3">
    <div style="text-align: center;"> 
      <div class="img-with-text">
        <p>
          <strong>
            <a href="partners.html" style="text-decoration:none">Partners</a>
          </strong>
          <img src="homepage images/celebration19.png" alt="sometext" width="64" height="64" id="img2"/>
        </p>
      </div>
    </div>
  </div>

  <div class="tile hvr-reveal" id="tile4">
    <div style="text-align: center;"> 
      <div class="img-with-text">
        <p>
          <strong>
            <a href="ABOUTUS.HTML" style="text-decoration:none">About Us</a>
          </strong>
          <img src="homepage images/men16.png" alt="sometext" width="64" height="64" id="img1"/>
        </p>
      </div>
    </div>
  </div>
</div>

CSS

body { 
  font-family: chewy;   
  color: #ffffff; 
  background-image: url(pictures%20for%20web/bg3.jpg);
  background-position: center center;
  background-attachment: fixed;
  background-size: cover;
  background-repeat: no-repeat; /* Issue arises due to errant double asterisks */

  webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
}

.grid { 
  width: 1140px; 
  height: 650px; 
  margin: auto;
}


.tile {
  position: absolute;
  width: 200px;
  left: 451px;
  top: 152px;
  height: 152px;
  box-sizing: border-box;
}

#tile1 {
  top: 407px;
  left: 754px;
  width: 338px;
  height: 196px;
  margin-left: 2px;
  margin-right: 2px;
  background-color: #ff3300;
}

#tile2 {
  margin-left: 2px;
  margin-right: 2px;
  top: 100px;
  left: 980px;
  width: 148px;
  height: 154px;
  background-color: #008000;
}

#tile3 {
  top: 255px;
  left: 523px;
  width: 200px;
  height: 150px;
  background-color: #660066;
  margin-left: 2px;
  margin-right: 2px;    
}

#tile4 {
  top: 255px;
  left: 118px;
  width: 200px;
  height: 150px;
  background-color: #990000;
  margin-left: 2px;
  margin-right: 2px;
}

Answer №1

If you're looking for something similar to this:

<div class="wrapper">
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
  <div class="box"></div>
</div>

.wrapper {
  position: relative;
  top: 0;
  left: 0;
  width: 90%;
  height: auto;
  margin-left: 5%;
  background-color: #444;
  display: block;
  text-align: center;
}

.box {
  border: solid 1px #000;
  height: 200px;
  width: 200px;
  display: inline-block;
  margin: 25px auto;
}

.box:nth-of-type(1){
  background: yellow;
}
.box:nth-of-type(2){
  background: red;
}
.box:nth-of-type(3){
  background: blue;
}
.box:nth-of-type(4){
  background: green;
}

This layout will keep the boxes aligned and responsive to the browser's width.

http://codepen.io/DB1500/pen/JGqaBZ

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

R code for extracting data without using CSS path

Hey there, I'm reaching out because I'm struggling to figure out how to extract data from a webpage (""). Learning how to scrape data is my current project, and I'm specifically trying to gather contact information (Office, Fax, email) from ...

Centering a table horizontally using CSS when its position is set to absolute

I currently have 5 HTML pages with identical code. The code snippet looks like this: <div id='generic'> </div> All 5 pages are linked to an external CSS file that contains the following styling: <style> #generic { ...

Intriguing flashing dark streak, reminiscent of a boundary within NextJS

I have recently encountered an unexpected issue with my full-width video header that worked perfectly on multiple pages before. Strangely, a thin black line has appeared around the bottom and right side of the div (.header) containing the video, even thoug ...

What is the method for absolutely positioning an element with separate targets for the `left` and `right` properties?

Seeking a complex CSS result that may seem impossible. Consider the following scenario: <div class="div1"> <div class="div2"> <div class="div3"> <div class="div4"></div> ...

Utilizing Flexbox at Small Screen Sizes in Bootstrap 4

Is there a way to apply the class d-flex to my element only on small screens? I couldn't find a solution in the documentation (https://getbootstrap.com/docs/4.3/utilities/flex/). I tried using d-sm-flex, but it seems to work for small screens and up. ...

Steps for adding hover color to a div with linear gradient border

My current challenge involves adding a hover color to a specific div, but I'm facing obstacles due to the gradient background that was implemented to achieve border-radius functionality. This task is being carried out within a React Component using c ...

Overlapping Divs - HTML Elements Crossing Paths

My challenge is to position the Social Icons at the bottom of the screen and align the Image Gallery in the middle. However, the social Icons keep moving to the center of the screen and the Image gallery ends up overlapping them, making it difficult for me ...

Block public access to the root directory of my domain to enhance security

I have a website at www.domain.com. While inspecting the element and trying to access www.domain.com/css/, I noticed that it displayed all the files in the directory. The structure is as follows: /css/ /images/ /include/ /js/ index.html contact.html si ...

Is It Possible to Create Flash Content Without Using a SWF File?

Is there a way to embed Flash directly in HTML, rather than linking to an external SWF file? I am looking to send an HTML form via email for the recipient to fill out by opening it in a browser. The final step would involve copying the result to their clip ...

Chips Style Vuetify Autocomplete Menu / Dropdown Feature

I am looking to change the appearance of the items in the dropdown menu of my Autocomplete Box. Vuetify-Autocomplete Currently, it displays the standard style for each item: Current <v-autocomplete chips deletable-chips multiple v-model="selectedT ...

Angular ng-grid is not utilizing its maxWidth property

In my quest to make an angular ng-grid element with autosizing properties, I stumbled upon this code snippet: for (var i = 0; i < $scope.dates.length; i++) { var dateElement = { field: 'reportMap.' + $scope. ...

How is it possible for a JavaScript variable sharing the same name as a div Id to automatically pass the div?

This is just ridiculous. Provided HTML <p id = "sampleText"></p> Javascript var sampleText = "Hello World!"; Execution console.log(sampleText); // prints <p id = "sampleText"></p> How is this even possible? I ...

What is the best way to determine the location of just one element?

I am currently working on a rating application where only the selected circle should remain green, not all of them. $('#rating-container').click(function () { var element = $('#target'); var container = $('#rating-containe ...

Automatically updating the JavaScript content on a webpage without having to refresh the entire HTML page, based on the changing

Is there a way to adjust the opacity change rate of my nav bar automatically without the need to refresh the page? The current opacity change rate is based on the width of the window, but once the page is loaded, adjusting the width does not affect the rat ...

Using Svelte to effectively connect to a specified object within an array

Check out this code snippet: <script> let data = [ {id: 1, first: "x"}, {id: 2, second: "y"} ]; </script> <input type="text" bind:value={data.first}/> If you modify the value in the input field and ...

Encountering undefined JavaScript functions when called from HTML

I had most of these functions working perfectly, but after restarting my program, I'm now encountering issues with undefined functions in Chrome. I can't pinpoint the exact problem, and even though I've checked through Eclipse, I still can&a ...

Troubleshooting issues with my Bootstrap 4 responsive column layout

I recently created a basic responsive website layout with Bootstrap 4. It should display 4 columns when in tablet mode, which is when the viewport is 768px wide. However, my layout works fine up to 770px, showing 4 columns. But as soon as it hits 769px, it ...

When the content in one box exceeds the content in the other, one box is considered to be overfilled

For the image, click here: I am facing an issue with boxes stacking on top of each other. When one box has more content, it overlaps the other. CSS: #destaques_container{ margin: 0 auto; } #destaques_container_dentro{ float: left; margi ...

Circular gradient backdrop

Looking to create a sleek and professional body background for my website that is as attractive as Twitter's. Can you help me achieve the same blue shaded background effect? I'm new to web development and would appreciate any guidance on how to m ...

What is the best way to retrieve the content of HTML tags from a string using JavaScript or AngularJS?

I have a string with mixed content of HTML tags and text. Here is an example: var str = "<p></p><p><i>blabla</i></p><p><i><b>blaaaaaablaaaaa</b></i></p><iframe src="..." height=" ...