Create a dynamic and adaptable "pixelart" DIV using Bootstrap 4

As a newcomer to Bootstrap 4, I have carefully gone through the documentation multiple times, but I have been facing challenges in making my project completely responsive for some time now.

This is my HTML:

<!DOCTYPE html>
<html>
 <head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
   <title>SwaggySauron</title>
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
   <link rel="stylesheet" href="style.css" />
 </head>
 <body>


      <div class="container">
        <div class="swaggysauron">
        <div class="row">
          <div class="col-1 pix pink"></div>
          <div class="col-1 offset-9 pix pink"></div>
        </div>
        <div class="row">
          <div class="col-1 pix pink"></div>
          <div class="col-1 pix offset-3 purple"></div>
          <div class="col-1 pix cyan"></div>
          <div class="col-1 pix purple"></div>
          <div class="col-1 pix offset-3 pink"></div>
        </div>
        <div class="row">
          <div class="col-1 pix pink"></div>
          <div class="col-1 pix offset-2 purple"></div>
          <div class="col-1 pix cyan"></div>
          <div class="col-1 pix black"></div>
          <div class="col-1 pix cyan"></div>
          <div class="col-1 pix purple"></div>
          <div class="col-1 pix offset-2 pink"></div>
        </div>
        ...

<p>My CSS:</p>

<pre><code>.pink {
border: 3px solid pink;
background-color: pink;
}
.purple {
border: 3px solid purple;
background-color: purple;
}
.cyan {
border: 3px solid #00ffff;
background-color: #00ffff;
}
.black {
border: 3px solid black;
background-color: black;
}

.pix {
height: 50px;
border: 1px solid white;
}

.swaggysauron {
min-width: 380px;
}

The challenge I am facing is related to my .swaggysauron DIV, which contains all the colored squares. When the screen size is reduced, it disappears instead of staying in place. Although it seems partially responsive, I believe I might be overlooking something crucial.

Any hints or explanations on where I might be making a mistake would be greatly appreciated.

Answer №1

If you want your design to be fully responsive, it's important not to set the height of a box as fixed. Instead, try using a CSS trick to create a square, which you can learn about here.

Next, focus on the styles for .col-1 and swaggysauron as demonstrated in this jsfiddle here.

.col-1{padding:0;}
.swaggysauron {
    width: 380px;
    max-width: 100%;
}

The use of min-width in swaggysauron and padding in .col-1 can cause issues in this scenario.

Answer №2

If you're looking to make the height responsive as well, you can utilize the following CSS code:

html, body, .wrapper, .awesomecreature {
  height: 100%;
}
.row {
  height: 8.33%;
}
.col-1, .image {
  height: 100%;
}

This code sets the container to be 100% of the window height, assigns 1/12 (8.33%) of the overall height to each row to fit them all within the container (if desired, you can adjust this to 9.09%), and ensures that the .col-1 and .image elements match the height of the rows precisely.

Check out the codepen link for a live example: https://codepen.io/anon/pen/ABcDefG

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

"Here's how you can mark an option as selected in Angular, either from the component or the HTML file

When it comes to my form, I have a select menu that sends data to an SQL database and then fetches it back when it is called for editing. The value being edited should be displayed in the select menu option as selected. Here's a peek at my code: < ...

Develop a MySQL table using AJAX and HTML within a Cordova application

I've been developing an app using Cordova and I'm looking to create a feature where users can create and join different rooms to perform various actions. Despite trying multiple tutorials and scouring the internet, I'm struggling to understa ...

What is the best way to overlay my slider with a div containing content?

In the hero section of my website, there is a slider with 3 slides. I am looking to add a div element that will display content over these slides at all times, regardless of which slide is currently showing. ...

Apply border-radius to the group of columns in CSS

I'm having trouble applying border-radius to the column group in an HTML table. Is there a solution for this issue that allows me to maintain accessibility for the table view? Is there a way to achieve border-radius on the column group while ensuring ...

Tips to successfully utilize addEventListener on a submit action

Having issues getting this to work on submit, it functions properly when using document.getElementById("gets").addEventListener("click", b_button); but does not work when I try document.getElementById("gets").addEventListener ...

What is the best way to show all cards in Angular when no filtering input is provided?

I have implemented a filter feature for multiple cards in Angular using Pipes. The filter works well, but I am facing an issue where no cards are displayed when there is no input value provided. I would like all the cards to be displayed when no input is g ...

Incorporating visuals into Doxygen documentation

Struggling to add an image with a caption in a doxygen .md file. Adding a caption is easy, but aligning the image left is proving difficult. I've tried several methods, but none have worked successfully. ![Caption](my_image.png "Caption") R ...

Find all the child elements within a specific class using CSS

Looking for a method to effortlessly apply styles to all elements within a specific class without repeating code like this: .element-wrapper .coin-box{ margin: 10px; float: left; } .element-wrapper .platform{ margin: 10px; float: left; } .eleme ...

Align labels on top and inputs at the bottom using Bootstrap

I'm facing an issue with alignment in my form using Bootstrap 4.4. Whenever a select element is included, it disrupts the layout by breaking the alignment of labels and inputs on the same row. Is there a way to always keep the labels at the top and t ...

Experience the innovative feature of React Splide Carousel where a peek of the next image is shown until you reach

My current challenge arises when I reach the last slide in the slider. I am trying to prevent it from looping and instead stop with no extra space or any other images peeking out. To address this, I have utilized the padding: '5%' option, which ...

Having difficulties including the Stack Overflow website within an iframe

I've been attempting to embed the Stack OverFlow website into an HTML page using an iFrame, but I'm running into some issues. Oddly, when I tried embedding my other two websites, they displayed correctly, but Stack OverFlow is not showing up on m ...

Utilizing CSS3 Pseudo Elements for Styling a Graph

I'm struggling to achieve the desired look of my ancestor chart using an unordered list format. Initially, I borrowed code from CSS3 Family Tree, but found it to be more like an organizational chart rather than a family tree. For testing purposes, he ...

Once more baffled by the nested boxes, this iteration adorned in vibrant hues and trimmed with a striking border

In a previous inquiry, I sought advice on centering one box within another. However, my attempts this time around have led to some peculiar results. I experimented with two different code variations- one involving a background color and the other utilizing ...

Issue with Sub-Menu closing unexpectedly upon hovering over Menu item

I created a webpage with navigation links that trigger separate menus to open upon hovering. Although I have successfully implemented this functionality, I encounter an issue when trying to click on a link within the sub-menu as it disappears. Below is a ...

Ajax activates a slider

One element I have is a menu div, along with a content div Initially, when the slider (which is a jquery plugin) is placed in the index.php, everything appears to be working well, as shown in the image below However, my objective is to have each page&apo ...

Using Javascript to replace elements with input fields and text areas

I'm currently working on a unique project for my Wordpress blog, where I am developing a custom block editor using JavaScript on the frontend. The goal is to convert all elements from the post content into a series of inputs and textareas. To begin, ...

Notification of Exceeding File Size Limit

Seeking assistance with implementing a 'filesize' error message into a script used for uploading BLOB files to a mySQL server. if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($dat ...

Achieving a transparent background color for a div without affecting the content with CSS

I am attempting to design a div element with a basic background color and some text displayed on it. I would like to lower the opacity of the background color in this div, but every time I try, the opacity of the text also changes. Is there a way to adjust ...

The back button functionality in Android cannot be altered or overridden using JavaScript

Hey everyone, I'm currently in the process of developing a mobile application using phonegap. I'm facing an issue where I want to disable the functionality of the back button from navigating to the previous page. I simply want it to do nothing or ...

Why is it that my JQuery sliders appear perfectly fine when viewed locally, but fail to show up when accessed on

I'm facing an issue with two JQuery sliders on my page. The local version works fine, but when I upload it to my web host, only one slider functions correctly. I need both of them to work as intended. Any insights on how to resolve this problem? See ...