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

Center alignment within input-group-prepend using Bootstrap 4

Is there a way to create a fixed width input-group-prepend that is larger than its content, while still keeping the content centered horizontally? I've experimented with text-center and align-items-center, but the content always ends up left aligned. ...

How to create a calendar selection input using PHP?

Before I start writing the code myself, I am searching to see if there is already a solution available or if someone has previously outsourced the code. Below is an example of my date selection: I want to create a feature where selecting a month will aut ...

How can I specifically target and count children from a certain class using CSS selectors?

Consider this HTML structure with items arranged at the same level: <div class="h2">Title: Colors</div> <div class="pair">Hello world (1)</div> <div class="pair">Hello world (2)</div> <div class="pair">Hello wo ...

Ways to avoid Bootstrap popovers from automatically breaking lines

I am struggling with adding a tooltip using Bootstrap's popover. Here is what I have tried: <ul> <li>Entry 1 ....................................................................</li> <li>Entry 2 ...................... ...

Tips on changing the text alignment in ant design's Select with search field component within a Form item to support various languages

Is there a way to dynamically change the text direction in a search field based on the language being typed by the user? For example, switch the direction to rtl when typing in Arabic and to ltr while typing in English. I need to achieve this functionalit ...

Show input field depending on chosen option

I'm looking to create a dynamic form where specific input fields are displayed based on the selection made in another field. For example, if "gender: male" is selected, the input field for "blue" should appear, and if "gender: female" is selected, the ...

Using the <ins> element to push content into a separate div lower on the webpage

My text inside the <p> element is being pushed down by the presence of the <ins> tag. Removing the <ins> tag from the DOM using developer tools results in my text returning to its expected position. main { max-width: 1000px; ma ...

Design a dynamic card with an eye-catching Font Awesome icon that adapts well to

As I delve into the realm of CSS, my current mission is to replicate the captivating cards showcased on this particular website. Utilizing Font Awesome icons has become a pivotal aspect of this endeavor. For instance, let's take a look at this card:ht ...

Building dynamic charts using JSON data in Oracle JET

I am attempting to populate a pie chart using JSON data retrieved from restcountries.eu/rest/v2/all. I use $.getJSON to fetch the data, create a temporary array as the data source, and then bind it to the pie chart. However, I seem to be encountering an er ...

Having trouble with implementing ng-hide and ng-show functionality

I have been working on creating my very first Angular website and so far, everything has been going smoothly with the first page. However, I am facing an issue with the second page not appearing as expected when it meets the condition set with ng-show in t ...

How can I utilize PHP to generate several tables within a single database?

I need some guidance on creating multiple tables within the "new" database. I'm curious if it's possible to include PHP code inside the query to generate table names dynamically. Any help would be greatly appreciated. Thank you in advance. <? ...

Align numbers vertically inside scrollbar center

I have created a program where you can input a number, and it will count from 0 to the specified number. Currently, the numbers are aligned horizontally up to 12 before starting on a new line. However, I would like the numbers to be arranged vertically fr ...

Comparing the positions of elements in Selenium WebDriver with PHP

One of the elements on my webpage serves as a button that reveals a drop-down menu. Due to various factors affecting the page layout, there were some alignment issues between the button and the menu until a few bugs were fixed. I am now looking for a way t ...

Ways to stop VoiceOver from selecting the background content when a modal is open

Is there a way to prevent VoiceOver from reading the content behind a modal? I tried using aria-modal=true, but it seems VoiceOver does not support this feature by default like NVDA and JAWS do. I found more information about this on . According to the in ...

HTML5 CSS and Rails theme

I am currently utilizing a free HTML5 template found at this URL: Despite my efforts, I am unable to successfully implement the background images from the main.js file (bg01.jpg, bg02.jpg, bg03.jpg). How should I correctly reference these image files wit ...

What is the most effective way to address duplicate title/meta tags on paginated pages? Can you share some recommended strategies for handling this

Google's webmaster tools are indicating the presence of Duplicate title tags on pages that have pagination. Below are a few examples: HTML suggestions Duplicate title tags Your title provides users and search engines with valuable information about ...

Guide to automatically adjust child div width to match parent container dimensions

I need assistance with structuring my HTML page, which consists of header, main, and footer sections. Below is the HTML and CSS code I'm utilizing: HTML code : <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

Extract content within Python pre tags

A Python code snippet is being used to extract content between PRE tags: s = br.open(base_url+str(string)) u = br.geturl() seq = br.open(u) blat = BeautifulSoup(seq) for res in blat.find('pre').findChildren(): seq = res.string ...

What is the best way to align a button with the edge of an image?

How can I use CSS to position a button on the edge of an image? https://i.stack.imgur.com/FEFDC.png Here is my code: <div> <button class="" aria-label="Eat cake">Btn</button> <img class="pull-left" src="style.png" style="widt ...

Optimal method for showcasing a multitude of columns on an HTML page

Seeking to showcase a vast array of data in HTML (over 10,000 columns with approximately 200-300 rows) to present a schedule. The information will be structured as movable blocks containing text and background colors. Is it feasible to exhibit such a mas ...