Interactive Tiling Technology

I'm new to CSS and I could really use some guidance on my mobile web platform project. I am working on a concept landing page with four equal rectangular tiles, inspired by this image.

Although the design should be responsive for mobile devices, I can't seem to achieve the desired layout. Here is how my HTML is structured:


<div class="page-container">
    <div class="tile-1"></div>
    <div class="tile-2"></div>
    <div class="tile-3"></div>
    <div class="tile-4"></div>
</div>

Currently, my CSS looks like this...


html, body, .container {
    height: 100%;
    min-height: 100%;
}

.page-container {
    margin: 0 auto;
    border: 1px solid black;
    height: 99%;
    min-height: 99%;
    width: 99%;
}

.tile-1, .tile-2, .tile-3, .tile-4 {
    border: 1px solid black;
    height: 48%;
    width: 48%;
}

Unfortunately, the result is far from what I had in mind. I've heard that using percentage-based heights may not be the best approach. The current output looks like this: image link

I would greatly appreciate any help or advice on adjusting the height to achieve the desired layout.

Answer №1

Typically, block level elements do not display on the same line as another block level element. In order to achieve this layout, you can either float them or change their display property to inline-block.

http://jsfiddle.net/kyyjg/

You may notice that combining pixel values for borders with percentages for dimensions can lead to incorrect spacing due to the box-model calculation. To address this issue, consider using box-sizing: border-box.

If you are open to alternative methods, here is an example utilizing flexbox:

http://jsfiddle.net/LJMdx/4/

html, body {
    height: 100%;
}

.page-container {
    min-height: 100%;
    background: red;
    display: -webkit-flex;
    display: flex;
    -webkit-flex-flow: row wrap;
    flex-flow: row wrap;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    padding: 1%;
}

.page-container div {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-flex: 1 1 48%;
    flex: 1 1 48%;
    margin: 1%; /* optional */
    border: 1px solid;
}

To eliminate gaps between the tiles, remove the 1% margin and padding: http://jsfiddle.net/LJMdx/3/

http://caniuse.com/#feat=flexbox

Answer №2

Consider using float:left. Check out this Demo to see if it fits your needs.

I've included a min-width for each tile to ensure consistency across different screen resolutions.

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

Including CSS in an HTML file does not function properly

I've been attempting to import a CSS file into an HTML document, but for some reason it's not working. I have also tried linking the path directly, but that hasn't worked either. <!DOCTYPE html> <html lang="en"> <head> < ...

Tips for displaying CSS background color on top of an inline style background image

I am facing a dilemma while using Laravel - if I put a background image into my CSS style sheet, I lose my variable. Currently, this is how I have it set up: <div class="gradient"><div class="topback" style="background-image: url('/storage/c ...

Animating pseudo-elements using Jquery

I'm having trouble animating the :after pseudo-element of my ul. Below is the CSS code I have: #slider .mypagination ul::after { content: ""; width:25%; bottom: 0; left:0; position: absolute; border-top:1px solid #7accc8; ...

How can I make the second element bold using CSS?

Is there a way to apply bold styling to only the second element in CSS without altering the HTML code? I specifically want to modify just "Products" but don't have permission to edit the HTML. ` <header> <nav> <a hr ...

Using jQuery to toggle sliding the information above a div

I am facing an issue with my customized sliding menu. The menu slides over the image but not over the content-div, pushing it aside. I have tried to fix this problem but haven't found a solution yet. My goal is for the menu to slide over all divs and ...

Customize the Placement of the Add to Cart Button in Woocommerce using CSS

How can I ensure that the “Add to Cart” button remains aligned properly on the shop page, even when the product names vary in length? I attempted to implement this CSS code, but it only seems to work when hovering over the button. .woocommerce .prod ...

A guide on traversing through nested HTML divs using jQuery

I am facing an issue with nested HTML div elements on my website. The data is being fetched from a JSON file and stored in a variable. For example, the 'obj' variable contains an array of objects with properties such as Name, Progress, Descripti ...

Tips for adjusting a static-width website for optimal viewing on an iPad screen

Is there a way to make a 2560px wide website fit perfectly within an iPad's viewport without needing to scroll horizontally? Currently, the @viewport CSS is set as follows: @viewport { width: device-width; max-zoom: .15; orientation: landsca ...

Position multiple div elements at the top with CSS alignment

Hey there! I have a question about the HTML and CSS code snippet below. I'm trying to align the text in the <h2> tags at the top for all three <div class="article-col-3"> containers, but it's currently aligned at the bottom. ...

Is it advisable to blend Angular Material with Bootstrap?

I'm brand new to Angular Material and it seems to have its own intricate API. Coming from using Bootstrap, I'm accustomed to utilizing its grid system with classes like row, containers, cols, etc. I'm curious if it's considered a good o ...

Modify the href attribute of an anchor tag that does not have a specified class or

I am currently using an event plugin that automatically links all schedule text to the main event page through anchor tags, like this: <td><a href="http://apavtcongresso.staging.wpengine.com/event/congresso-apavt-2018/">Chegada dos primeiros c ...

How can I create a jagged CSS gradient effect?

Check out the example below to see my desired outcome in action. I can clearly distinguish between the two, but if it's not clear to you, here's another image for reference. ...

Is it possible to incorporate a CSS3 transition into the styling of a list of images?

Looking to achieve a CSS3 linear transition for a "list-style-image" specifically for Firefox? You'll need to include "-moz-" in your code. -moz-transition: list-style-image 0.2s linear; However, the above code is not producing the desired result. I ...

What is the best way to achieve a smooth rotation effect ranging from 1° to 359° using HTML/CSS in conjunction with JavaScript

Currently, I am retrieving rotation data from a sensor and transmitting it to a webpage containing a 2D-Model that rotates based on this data. To ensure a smoother motion, I have incorporated a CSS transition. However, an issue arises when the rotation da ...

Reducing the slide margins in impress.js?

When using Impress.js, I noticed that the default slides have a large left margin (or padding - it's hard to determine with Firefox's Inspector). I have a slide with a wide <pre> block that would fit if it were aligned to the left, but it d ...

Incorporating Cascading Style Sheets (CSS) to

I'm looking to style my form with CSS but I'm unsure of the process. Currently, the form is generated using PHP and MySQL, and in the browser it appears like this: http://gyazo.com/5d099ead9bd6ea83859a5114b2438748 I want to align the text and dr ...

Is it possible to showcase a background image within table cells?

I'm trying to set a background image on the floating bar at the bottom of my page: . Unfortunately, the background image is being cut off by each table cell. I've attempted two solutions: 1. Converting the table to divs and setting the backgro ...

Accessing an image from a directory using Javascript

I have a simple question that I need help with. In my code, I currently pull images from a website using this syntax: icon: 'http://i45.tinypic.com/2yua8ns.png'. However, I would like to use something like this instead: icon: '\images/i ...

Transforming global CSS into CSS modules: A step-by-step guide

In my nextjs project, I am utilizing react-bootstrap and bootstrap which requires me to include the global css: // _app.js import 'bootstrap/dist/css/bootstrap.min.css'; The issue arises when loading a significant amount of unused css on every p ...

Automated vertical alignment of rows within the Bootstrap table

I'm currently working on a table for my personal project that populates with data from the database. I am trying to get the rows to display vertically under headings (see screenshot at the bottom of this question). I have attempted various solutions f ...