What are the steps to developing a responsive tile using HTML and CSS?

I am exploring the functionalities of CSS and responsive design. To better understand how it works, I created a simple example which can be accessed here.

This demonstration showcases a basic tile template.

My goal is to display my tiles in 2, 3, 4, or more columns depending on the layout. By changing the class of the div "wrapper" to c2, c3, c4, you can adjust the number of columns in this sample.

The key here is that my tiles are set to float left, and the classes c2, c3, c4 modify the width of the wrapper accordingly. Refer to the HTML and CSS files or visit JSFiddle for more details.

HTML

<div class="wrapper c2"> <!-- try with c3, c4-->
    <div class="scrollable">
        <div class="webbutiles">
            <a href='?page_id=77'  class='tile TBlue iconmain '><div class='boxContent'><i class='icon-group'></i></div><div class='tilename '><div class='name'>Tile 1</div></div></a>
            <a href='?page_id=85'  class='tile TDarkGreen iconmain '><div class='boxContent'><i class='icon-comments-alt'></i></div><div class='tilename '><div class='name'>Tile 2</div></div></a>
            <a href='?page_id=89'  class='tile TDarkPurple iconmain '><div class='boxContent'><i class='icon-cogs'></i></div><div class='tilename '><div class='name'>Tile 3</div></div></a>
            <a href='?page_id=91'  class='tile TDarkBlue iconmain '><div class='boxContent'><i class='icon-table'></i></div><div class='tilename '><div class='name'>Tile 4</div></div></a>
            <a href='?page_id=93'  class='tile TDarkRed iconmain '><div class='boxContent'><i class='icon-heart'></i></div><div class='tilename '><div class='name'>Tile 5</div></div></a>
            <a href='?page_id=95'  class='tile TTwitterBlue iconmain '><div class='boxContent'><i class='icon-twitter'></i></div><div class='tilename '><div class='name'>Tile 6</div></div></a>
            <a href='?page_id=97'  class='tile TGreen iconmain '><div class='boxContent'><i class='icon-columns'></i></div><div class='tilename '><div class='name'>Tile 7</div></div></a>
            <a href='?page_id=87'  class='tile TOrange t2x iconmain '><div class='boxContent'><i class='icon-reorder'></i></div><div class='tilename '><div class='name'>Tile Large</div></div></a>
        </div>
    </div>
</div>

CSS

    /* General tile settings */
.tile{ display:block;  float:left;  background-color:#525252;  width:150px;  height:150px;  cursor:pointer;  text-decoration:none;  color:#fff;  overflow:hidden;  position:relative;  font-weight:300;  font-size:11pt;  letter-spacing:0.02em;  line-height:20px;  margin:0 10px 10px 0;  overflow:hidden}
.tile:hover{ outline:3px #3a3a3a solid}


/* Tile responsive setting. */
@media (min-width:1025px){
    .wrapper{width:1024px}
}

.wrapper{margin-left:auto; margin-right:auto}
.wrapper.c2{width:400px}
.wrapper.c3{width:600px}
.wrapper.c4{width:800px}
.wrapper.c5{width:1000px}
.resimgicon {max-width:62px;height:auto;}
.tile .boxContent .resimgicon{ margin-left: 3em; margin-top: 2.7em;}
.tile{ width:157px;  height:157px}
.tile.t2x{ width:324px}
.tile.t2x .boxContent{ width:324px}

@media (max-width:640px){
    .wrapper{margin-left:auto; margin-right:auto}
    .wrapper.c2{width:324px}
    .wrapper.c3{width:491px}
    .wrapper.c4{width:658px}
    .wrapper.c5{width:785px}
    .resimgicon {max-width:64px;height:auto;}
    .tile .boxContent .resimgicon{ margin-left: 2.7em; margin-top: 2.8em;}
    .tile{ width:147px;  height:147px}
    .tile.t2x{ width:304px}
    .tile.t2x .boxContent{ width:304px}
}

@media (max-width:360px){
    .wrapper{margin-left:auto; margin-right:auto}
    .wrapper.c2{width:184px}
    .wrapper.c3{width:281px}
    .wrapper.c4{width:378px}
    .wrapper.c5{width:435px}
    .resimgicon {max-width:38px;height:auto;}
    .tile .boxContent .resimgicon{ margin-left: .74em; margin-top: .68em;}
    .tile{ width:77px;  height:77px}
    .tile.t2x{ width:164px}
    .tile.t2x .boxContent{ width:164px}
}

I find working with fixed tile and wrapper sizes limiting. The left and right (auto) margin that appears isn't necessary on smaller screens like phones or tablets.

Is there a way to create a flexible tile system with variable column numbers without relying on fixed wrapper widths? Any suggestions on improving this tile generation method?

Answer №1

You seem to be approaching this in a unique way compared to standard practices.

Instead of adjusting the width of your wrapper, you're opting for a fluid width wrapper that can range from 320px to 2560px.

The idea is to establish a set of column widths based on a percentage calculation within a grid system. Let's say you aim for a maximum of 12 columns, each totaling 100%.

For instance, if you want one full-width column, it would have a class like "col-12" with width: 100%;

If you desire two equal-width columns with a 3.8% margin between them, you'd calculate the percentages accordingly and create classes like col-6 with width: 48.1% and margin-right: 3.8%;. Additionally, include a "last" class for the final div in a row to remove unnecessary right margins.

Continue this pattern to generate col-1, col-2, col-3, and so on by combining classes to add up to 12. For example, col-6 and col-6 for half-width columns, or various combinations like col-3, col-3, col-3, col-3, or even more diverse layouts like col-1, col-2, col-3, col-5, col-1...

Does this approach make sense?

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

Unable to capture HTML form input in $_POST[]

I've encountered an unusual issue while transferring data from an email form (HTML5) to ajax/JSON and receiving false in order to prevent redirection to the php script after pressing the submit button. When I include commas between each data paramete ...

Design a custom cover page before printing using the window.print() method

When it comes to printing, I have a header and footer displayed on each page. However, I want the first page to be clean with just a picture or title, without the header and footer that appear on subsequent pages. I've attempted to use CSS like this ...

Arrange floating elements in a three-column layout

Can anyone help me with a CSS solution to make boxes with different heights stack underneath each other neatly, similar to Tetris? Here's my code: CSS #page .equipeBox{ float:left; width:280px; padding:10px; margin:10px; backgro ...

Jquery div mysteriously disappearing without explanation

I need some help with my image options. Whenever I hover over the image, the options appear below it. However, when I try to move down to select an option, they disappear. I have configured the slideUp function so that it only happens when the user moves a ...

Calculate the total price using Jquery once selections have been made

I am looking to create a dynamic pricing feature where clicking on a checkbox will update the total price. The prices are calculated per day, so if days are added, the total should reflect that accordingly. Check out our demo here: http://jsfiddle.net/XqU ...

jQuery if statement appears to be malfunctioning

When the condition operates alone, everything works fine. However, when I introduce an 'and' operation, it does not function correctly. If only one of them is true, the code works. It also successfully takes input values. <!DOCTYPE HTML Code ...

Is it possible to remove the address bar from appearing on a browser when a page loads?

I am in the process of developing a customer wifi landing page, and although we have made progress with ensuring it is the first page that loads, I want to take it a step further. My goal is to require customers to agree to our usage policy before gaining ...

Maintaining the state of perspectives

I am currently working on an app that utilizes a form to filter objects from a database. Each change in the form triggers a request to the server for filtered objects, which are then displayed in another view. However, I have encountered an issue where the ...

Using CKEditor in an AngularJS web application: Tips and tricks

I'm having trouble integrating the ckeditor into an HTML page that's built with angularjs. Despite trying out numerous examples, such as the ng-ckeditor and ckeditor directives, I haven't found a solution that works for me. What I need is ...

initiate changes to the application's style from a component nested within the app

I'm looking to update the background color of the entire page, including the app-nav-bar, when I'm inside a child component. When I navigate away from that component, I want the default style to be restored. Any suggestions on how to achieve this ...

The size of table cells automatically adjusts when zooming in the browser

While trying to display my table in Chrome, I noticed that the cell sizes of the table change when zooming in. Additionally, the table is rendered incorrectly in other browsers like IE and Firefox. I attempted adjusting the sizes to percentage values but i ...

Why won't my picture track the movement of the cursor?

I am trying to make my image follow the cursor using a specific code, but it doesn't seem to be working. I'm having trouble figuring out what's wrong with it. Here is the code snippet that I'm currently using: function followIt(e) ...

Check the validity of the data by logging into another website

I've run into a bit of a problem while working on my website. Here's a brief explanation (using fake addresses), I have a website, www.website1.com, with lots of well-coded elements. You can log in to this website using www.website2.com. So whe ...

Positioning the icon within the input field

I am facing a couple of challenges. I have chosen to utilize focus and blur for text values in input fields instead of placeholder text due to an issue in Chrome where the placeholder text is centered. My goal is to position the icon in the input field, p ...

Why do I keep getting an ExpressionChangedAfterItHasBeenChecked error after trying to update a random color in an

Is there a way to assign a random color from an array without causing the error message: "ExpressionChangedAfterItHasBeenChecked"? Even though the color of the chip changes quickly before the message appears, it seems like it's working. How can I reso ...

How can I prevent scrolling in a Vue mobile menu?

In this scenario, the toggle for the menu is controlled by a checkbox with the id "check" below. I attempted to bind v-bind:class="[{'antiscroll': checkboxValue}]" to the body in HTML, and also in the main App.vue file, but it did not work as exp ...

The challenge of styling React components

Starting a new project with React and Redux has presented me with the challenge of deciding on a styling method. As a newcomer to React, I want to choose a method that won't compromise performance, will offer all CSS3 features, and is easy to maintain ...

The functionality of Jquery appears to be malfunctioning on the Drupal platform, although it performs

I've built a jQuery carousel that is fully functional when tested locally, but encounters issues when uploaded to a Drupal platform. Surprisingly, the jQuery functions properly when entered through the Console. Here's the jQuery code: carousel = ...

Empty ng-repeat iteration despite the presence of HTML elements

After receiving a list of numbers from an API, I am using ng-repeat to display them on a web page. However, even though 10 elements are created for 10 numbers, the content is empty. Despite trying various combinations, I am unable to get the content to dis ...

Conceal your password using HTML techniques

My goal is to hide passwords from being visible unless a user hovers directly over them. I've tried using the code below, but the hover effect isn't working as expected - either the password disappears completely or remains visible at all times. ...