Just starting out with Boostrap; looking for ways to tidy up this code and achieve the intended effect

UPDATE: Check out the revised JS Fiddle link at the end of this post; I managed to achieve the desired result, but I believe there's room for improvement in the code!

After experimenting with HTML/CSS for some time, I'm now working on my first layout using Twitter-Bootstrap. This is my initial inquiry, and any input is greatly appreciated.

I think the section of code I'm sharing can be streamlined further. While it looks mostly as I want it to, I sense there may be a simpler way to achieve my goal.

View this JS Fiddle.

The objective is to have two rows of diamonds on md+ screens, with 4 in the first row and 3 in the second. On small or x-small screens, the diamonds should transition to three rows, with 3 in the first row, 2 in the second, and 3 in the third, slightly spaced apart. Although the JS Fiddle appears as intended on md+ screens, I'm struggling to align rows 1 and 3 properly on small and x-small screens with the second row.

What would be the most efficient approach to achieving this? My current method feels convoluted. I'd prefer using only HTML/CSS to cater to users with JavaScript disabled. THANK YOU. :)

<section class="container-fluid diamonds">
<div class="row">
  <div class="col-md-10 col-md-offset-1">
      <div class="xsrow1">
        <div class="col-md-3 col-xs-6 xsright no-padding"><img src="http://i57.tinypic.com/o5565j.png"></div>
        <div class="col-md-3 col-xs-6 no-padding"><img src="http://i57.tinypic.com/o5565j.png"></div>
      </div>
      <div class="xsrow2">
        <div class="col-md-3 col-xs-4 no-padding"><img src="http://i57.tinypic.com/o5565j.png"></div>
        <div class="col-md-3 col-xs-4 no-padding"><img src="http://i57.tinypic.com/o5565j.png"></div>
      </div>
    </div>
  <div class="col-md-8 col-md-offset-2 mdrow2">
      <div class="xsrow2">
    <div class="col-md-4 col-xs-4 no-padding"><img src="http://i57.tinypic.com/o5565j.png"></div>
      </div>
      <div class="xsrow3">
    <div class="col-md-4 col-xs-6 xsright no-padding"><img src="http://i57.tinypic.com/o5565j.png"></div>
    <div class="col-md-4 col-xs-6 no-padding"><img src="http://i57.tinypic.com/o5565j.png"></div>
    </div>
  </div>
</div>
</section>


.no-padding {
  padding: 0!important;
  padding-right: 3px!important;
  padding-left: 3px!important;
  margin: 0!important;
}

.diamonds {
  position: relative;
}

.diamonds img {
  width: 100%;
  height: auto;
}

@media (max-width: 991px) {
  .xsrow1 img, .xsrow3 img {
    width: 66.66667%!important;
    height: auto;
  }
  .xsright {
    text-align: right;
  }
}

@media (min-width: 992px) {
  .mdrow2 {
    position: absolute;
    top: 51%;
    left:0%;
    padding-left: 3%;
    padding-right: 3%;
  }
}

UPDATE: I've come up with a solution that works for me, though I still find it somewhat messy. You can view the updated JS Fiddle here. If anyone has a cleaner method, please share it. :)

Answer №1

To enhance the structure, consider utilizing a preprocessor, incorporating additional semantic classes into the code, and eliminating layout-specific classes such as "col". You can also merge styles using mixins to customize specific classes.

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

What is the best way to ensure my background image adjusts properly for both iPhones and Android devices to be responsive?

I have set the background image in my CSS to fit perfectly without any need for adjustments. The goal is for the image to resize itself when viewed on mobile devices or tablets. .intro { display: table; width: 100%; height: auto; padding: ...

Ways to showcase a div exclusively on UC mini browser

I'm looking for help to create a script that will only display a div with the class "info-box" in UC Mini browser. This div should be hidden in all other browsers. Can someone assist me with this? <!doctype html> <html> <head> <m ...

Exploring the depths of HTML 5, harnessing the power of

As I embark on a new website project, I am excited to incorporate HTML5 for a fresh and dynamic look. To address potential compatibility issues with Internet Explorer, I have decided to utilize the resources provided by the HTML5 Boilerplate project. In m ...

Rendering EJS templates and smoothly scrolling to a specific section on a webpage

I need to display my index page and automatically scroll down to the form section. One way I thought of doing this is by: app.post('/rsvp', (req, res) => { res.render('index/#rsvp', { errors: { email: 'Your email has already ...

Display the initial page and activate the first navigation button when the page loads

Greetings to everyone. I am new to the world of jquery and currently in the process of learning. This is my script: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"> </script> <script> $(function () { $ ...

Is there a way to track the amount a user scrolls once they have reached the bottom of a page using Javascript?

It's a popular UI pattern on mobile devices to have a draggable element containing a scrollable element. Once the user reaches the end of the scrollable content, further scrolling should transition into dragging the outer element. For example, in this ...

Using jQuery to remove the td element from an HTML table

Hello everyone, I have a query. I am trying to remove a specific td from a table using JavaScript, but the remove() function is not working. Here is my code: $('.btnEliminarLicencia').off('click'); $('.btnEliminarLicencia&apo ...

Generating Speech from Text using jQuery API in HTML

Can a website be created to detect textbox text upon longClick by the user, and function across various browsers? The site should also have mobile compatibility. Appreciate any help! ...

Modify the title attribute within a span tag in PHP using AJAX

I'm currently working with Zend Framework 2 and I have a requirement to translate a string in my index.html file, which displays a tool tip when hovering over a span tag. The challenge I face is that this value needs to change dynamically after perfor ...

Incorporate pug and sass into your React project for a more

Are pug/jade and sass compatible with react? I enjoy organizing my code by separating files, and the functionality that sass and pug provide is great for this purpose. Is there a way to integrate pug and sass into a react project? Pug example: doctype ...

What is the best way to vertically center a div that has a fixed position and a specific width in pixels

Is there a way to center a fixed position div with a specified width of 300px, rather than in percentage? <div class="mainCont"> <div class="childCont"> </div> The childCont div has a fixed position and width of 300px. How can I ensur ...

Is it possible to dynamically add elements in AngularJS without relying on directives?

As a newcomer to Angularjs and not very fluent in English, I embarked on the journey of adding <li> using directives. You can see the result of my first attempt at this link. Next on my list was mastering two-way binding by passing values between th ...

Presenting a data table in Angular

I'm new to using Angular and need help creating a table to organize my data, which is being fetched from a JSON file on the server. Here's the content of data.component.html: <div class="container"> <h1>Search history</h1> ...

css Sibling elements restricted within parent container

Encountering an issue with a star rating css example when more than one fieldset is added. The current CSS code seems to be working fine, but it fails when multiple instances of the same elements [fieldset] are present. I've been struggling to find a ...

Ways to extract information from a table cell located next to a table cell with colspan

As a beginner in web scraping, I am gradually making progress. However, I'm facing a tough challenge with this particular task. My goal is to extract data from the ESPN NBA boxscore website: I aim to scrape the names of players labeled as "DNP" (Did ...

Find the dominant color within the project's style sheets

Is there a method to extract the main color from an angular material theme and apply it in the css files of an angular project? Within a project, we can specify the primary color in a *.scss document as shown below: @import '~@angular/material/themi ...

Adding text with jQuery

Currently, I am utilizing the Jquery text editor plugin known as JqueryTE. While adding some functions to it, I have encountered a roadblock. Specifically, I am attempting to insert additional text into the source of the textarea but have been unsuccessfu ...

Altering the innerHTML of a <p> tag with a smooth transition

I am a beginner in the world of web design. I am currently working on a project where I need to continuously change the text inside a <p> element with a transition effect similar to a slideshow. Below is the code I have so far: <p id="qu">S ...

The flickering problem with HTML5 DOM

I created a HTML5 game using canvas and DOM elements, but I'm facing an issue with flickering DOM elements while playing. The problem seems to be more prevalent in mobile browsers, particularly Chrome. My game includes a full screen canvas with vario ...

Finding the Perfect Placement for an Element in Relation to its Companion

Is there a way to achieve an effect similar to Position Relative in CSS using jQuery? I have developed a tooltip that I want to attach to various objects like textboxes, checkboxes, and other text elements. My code looks something like this: <input i ...