Attempting to troubleshoot an issue with the responsive web design grid viewport

I've been experimenting with creating a grid layout based on the instructions from w3schools. Unfortunately, I am facing an issue where all the rows span 100% across the viewport no matter what combinations of columns I try. I have created multiple rows with different column placements, but nothing seems to fix the problem.

For reference, here is a Codepen link to the code.

<div class="row">
    <div class="col-6, sec1">Content</div>
    <div class="col-6, sec2">Content</div>
</div>
[class*="col-"] {
    width:100%;
    float:left;
}

.row::after {
  content: "";
  clear: both;
  display: table;
}

@media only screen and (min-width:768;){
    /*Desktops*/
    .col-1{width:8.33%;}
    .col-2{width:16.66%;}
    .col-3{width:25%;}
    .col-4{width:33.33;}
    .col-5{width:41.66;}
    .col-6{width:50%;}
    .col-7{width:58.33%;}
    .col-8{width:66.66%;}
    .col-9{width:75%;}
    .col-10{width:83.33%;}
    .col-11{width:91.66%;}
    .col-12{width:100%;}
}

Answer №1

To begin with, it's essential to grasp the fundamentals of html and css. In html tags, css classes are separated by spaces NOT commas. Keeping that in mind, let's dive into the code.

  1. You've been using commas to divide classes, as previously mentioned
<div class="col-6 sec1">Use classes like this!</div>
<div class="col-6, sec1">Do NOT use classes like this!</div>
  1. In your selector, you have overlooked setting a minimum height, which could result in some columns not appearing due to missing declarations.
[class*="col-"] {
    width: 100%;
    float: left;
    min-height: 1px;
}
  1. When working with media queries, treat them like any other unit. Don't forget the unit in min-width: 768.
@media only screen and (min-width:768px){
    // Do your media
}
  1. The clearfix hack used in your .row class requires additional rules for both before and after elements. You can refer to this micro clearfix hack for more information.
.row {
    *zoom: 1;
}

.row::after {
  content: " ";
  display: table;
  clear: both;
}

.row::before {
  content: " ";
  display: table;
}

HINT: Consider looking at various css frameworks that utilize different column names for breakpoints such as col-lg- for large devices and col-md- for medium devices. It's beneficial to follow this practice when creating column layouts.

Check out this jsFiddle where I've demonstrated responsive columns.

Answer №2

I found a couple of mistakes in your code:

  1. The class names are written as <div class="col-6,sec1"> but it should be <div class="col-6 sec1">
  2. Your media query is defined as
    @media only screen and (min-width:768;)
    when it should read
    @media only screen and (min-width:768px)

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

Utilizing a CSS selector to target a button nested multiple levels deep

Currently, I am conducting E2E tests on an application that lacks clear identification for the tags. I need to click on buttons nested deeply within the structure, some of which have the same name and properties as others. The HTML code presents itself si ...

Tips for resolving the issue of CSS blocks disappearing when designing a webpage

When creating a responsive web page, the child block "overflows" from the parent block. This causes the entire page to shift to the left and an empty bar appears on the right side, moving all the content. I need to ensure that all content is positioned cor ...

What could be causing my page to appear differently in medium resolutions with Bootstrap 4?

When viewing my basic Bootstrap 4 webpage on a medium screen size, there appears to be a blank space on the right side. https://i.sstatic.net/ohV20.jpg Visit the page Thank you very much. ...

The vertical scrolling functionality of the MUI DataGrid in Safari may occasionally fail to work

Utilizing the <Box> component from MUI core and the <DataGrid> component from MUIX, along with some other components, I have created a data grid that has the following appearance: https://i.sstatic.net/Gc8sP.png When the number of rows exceed ...

JavaScript confirmation for PHP delete button

Is there a way to implement a JavaScript alert that prompts the user to confirm their action when they click the delete button? I attempted to integrate a class into an alert box: <?php //$con = mysqli_connect("localhost", "root", "root", "db"); $sql ...

Generate dynamic HTML content with variable values using dompdf

I need to set values for variables in a template view file and then load the HTML using dompdf. However, the values I set are not being evaluated and displayed. Below is my Controller function: $dompdf = new Dompdf(); $this->f3->set('u ...

Gorgeous Ladle: Extracting span tags from paragraph tags

I am facing an issue with extracting a span element from my total p element. Let me provide a specific example of one of the p elements I am currently parsing: <p id="p-9"> <span class="inline-l2-heading">H5N1 virus path ...

Using JavaScript to interact with text elements in external SVG documents

When it comes to creating an SVG within HTML and assigning specific IDs to text elements for easy access, everything works smoothly. For example, I can easily retrieve the ID using: let callQSO = document.getElementById("QSOcall").value; and th ...

Issues with NativeScript WebView displaying HTML file

Having trouble loading a local HTML file into a webview in my NativeScript (typescript) application. Despite using the correct path, it's not loading and instead shows an error. <WebView src="~/assets/content.html" /> An error message stati ...

What is the term for the blue highlighted word that assists in completing the form?

I have been curious about the implementation and name of this feature. I attempted to search online but couldn't find a specific designation. An instance can be seen on the Airbnb website AirBnB Website It involves entering a city and seeing suggest ...

Unleashing the Power of Resetting CSS Class Attributes in Twitter Bootstrap

Last year, @Andres Ilich shared a remarkably elegant solution for centering the navigation bar in Bootstrap. Here is an excerpt from the answer he posted: Visit here for more details. <div class="navbar navbar-fixed-top center"> <div class=" ...

Flipping through different pages showcasing the identical model

Exploring the world of Angular (currently Angular5) has led me to a query regarding page navigation within the same model. Consider an older project built on AngularJS. Let's take the example of a model called Customers. The pages related to this mod ...

Struggling to locate the src/site/globals/site.variables file to customize the font-family in Semantic UI React. Is there an alternative method to achieve this?

I've been attempting to modify the overall font-family for my application, but so far, I haven't had any luck. Since I'm working with Semantic-UI-React, I initially thought that could be the issue. However, when I tried to locate src/site/g ...

Unable to showcase JavaScript outcome on the HTML page

I have been working on creating a JavaScript function to calculate the Highest Common Factor (HCF). While testing my code in the VS Code console, the correct value is displayed. However, I'm encountering an issue when trying to display the result on t ...

Seeking guidance on selecting text using XPath

My HTML document contains the following HTML code: <!DOCTYPE html> <html> <head> <title>page XYZ</title> </head> <body> <p><b>bold text</b> some more text </p> <p>< ...

The browser is not displaying the HTML correctly for the Polymer Paper-Menu component

I attempted to implement a paper-menu, but I am facing issues with the rendered HTML and its interaction. When I click on a menu item, the entire list disappears due to the paper-item elements not being properly placed inside a key div within the paper-men ...

The website is not displaying CSS styles as intended

I'm currently in the process of building a website with Bootstrap 5, but I've encountered an issue where the properties from index.css are not taking effect on index.html. Specifically, when I hover over a service card, the background is supposed ...

Tips for enhancing the responsiveness of a calendar table in Bootstrap 5.2

Hello there! I need some help with adding rounded borders to tables using Bootstrap. Can anyone assist me with this? I'd be truly grateful for any guidance on this matter. Unfortunately, Stack Overflow is not allowing me to post my question, so I&apos ...

What is preventing the buttons from filling the entire space of the parent element in this case?

https://i.stack.imgur.com/kbiWi.png I'm trying to figure out how to make the Repos and Stars buttons fill the entire height of their parent container, similar to the Github icon. Unfortunately, the code below is not achieving this effect. I attempted ...

Is it feasible to incorporate the CSS and Bootstrap (CDNs) specific to an HTML component without affecting the styling of other pages?

One way I am able to recycle the HTML component is using this code: $.get("nav.html", function(data) { $("#fulloptions").replaceWith(data) }) However, there’s a conflict because nav.html uses a different version of Bootstrap than my index file does ...