CSS grid-box experiencing issues due to interference from bootstrap styling

When attempting to create a grid, I noticed that the first image element is not showing up in the first position as expected. Instead, it appears in the second position, leaving the first spot blank. After inspecting the issue, I realized that the styles from the bootstrap link

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
are causing my grid-box to malfunction. If I remove the bootstrap link, my navbar ceases to function.

If you'd like to review the code, you can find it here: Jsfiddle link

Any suggestions for fixing this issue would be greatly appreciated. Thank you for your help.

Answer №1

When using bootstrap 3, the use of float requires the use of pseudo elements to clear floats.

To clear floats in

.container:before{display:table;content:" "}
, a pseudo element is inserted to fill up the first cell and reset the order to place it last. https://jsfiddle.net/nhak72r1/

/* Update for fixing */

.container::before {
  display: none;  /* hide for now */
  order: 1;  /* set it as last; if order is used for other elements, set the highest value */
}

/* End of Update */

* {
  box-sizing: border-box;
}

.container {
  display: grid;
  grid-template-rows: repeat(4, auto);
  grid-template-columns: repeat(4, auto);
  grid-gap: 5px;
  align-items: center;
}

.container > img {
  width: 100%;
  border-radius: 20px;
}

.container > img:nth-child(6) {
  grid-row: span 2;
  grid-column: span 2;
  width: 100%;
}
<!DOCTYPE html>
<html>

<head>
  <title>Chairs</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <link href="https://fonts.googleapis.com/css2?family=Karla:wght@700&display=swap" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="styling.css">
</head>

<body>
  <nav class="navbar navbar-inverse">
    <div class="container-fluid" id="head">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
        <a class="navbar-brand" id="brand-name" href="3">Chairs<span id="dot">.</span></a>
      </div>
      <div class="collapse navbar-collapse" id="myNavbar">
        <ul class="nav navbar-nav">
          <li class=""><a href="#">Home</a></li>
          <li class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#">News<span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">What's New?</a></li>
              <li><a href="#">Updates</a></li>
              <li><a href="#">New Discounts</a></li>
            </ul>
          </li>
          <li><a href="#">Features</a></li>
          <li><a href="#">Shop</a></li>
          <li><a href="#">News</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
          <li><a href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
          <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
        </ul>
      </div>
    </div>
  </nav>
  <div class="container">
    <img src="https://i.pinimg.com/564x/2c/6e/3f/2c6e3f6d0cfbe5038a0ca7659c0eab46.jpg">
    <img src="https://i.pinimg.com/564x/e1/82/25/e1822536694c06c60d0df0897d7117e5.jpg">
    <img src="https://i.pinimg.com/564x/2c/6e/3f/2c6e3f6d0cfbe5038a0ca7659c0eab46.jpg">
    <img src="https://i.pinimg.com/564x/e1/82/25/e1822536694c06c60d0df0897d7117e5.jpg">
    <img src="https://i.pinimg.com/564x/2c/6e/3f/2c6e3f6d0cfbe5038a0ca7659c0eab46.jpg">
    <img src="https://i.pinimg.com/564x/e1/82/25/e1822536694c06c60d0df0897d7117e5.jpg">
    <img src="https://i.pinimg.com/564x/2c/6e/3f/2c6e3f6d0cfbe5038a0ca7659c0eab46.jpg">
    <img src="https://i.pinimg.com/564x/e1/82/25/e1822536694c06c60d0df0897d7117e5.jpg">
    <img src="https://i.pinimg.com/564x/2c/6e/3f/2c6e3f6d0cfbe5038a0ca7659c0eab46.jpg">


  </div>
</body>

</html>

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

script to pause video using jQuery

I have a script that works perfectly, but currently it only stops an instance of a playing video if a new video is started. I want to modify the script so that ALL instances of playing videos are stopped when the function stopAllButMe(); is called. Can s ...

Enhance Your Website with HTML and JavaScript

Here is the code snippet I am working with: sTAT **javascript** var acc = document.getElementsByClassName("item-wrapper"); var i; for (i = 0; i < acc.length; i++) { acc[i].onclick = function(){ this.classList.toggle("selected"); this.nextElementS ...

How can we eliminate the modal-open class in Angular when transitioning to a different URL?

Currently, I am facing an issue with a bootstrap modal. There is a button inside the modal which upon clicking should navigate the current component to another component named 'questions'. The problem arises when the new component is loaded, as t ...

Dropdown trigger changing image with AJAX

When a color is selected from one dropdown menu, it triggers a change in another dropdown menu and the image displayed. The ID for the dropdown affected by the color selection is "style_code". <script> function getState(val) { $.ajax({ ...

Python: encountered an issue when attempting to retrieve the complete text within every <span> tag using BeautifulSoup

I have been searching through various sources but have not yet found a solution that works for me. Below is the HTML file I am trying to work with: ......<span ><span class='pl'>Director </span>: <span class='attrs&apos ...

A guide to retrieving all image URLs when a checkbox is selected using Javascript

My goal is to extract only image URLs from the concatenated values of price and picture URL. However, when I check different images using checkboxes, it always displays the URL of the first selected image. When I try to split the value, all the prices and ...

Tips for incorporating error messages based on specific errors in HTML

In the current setup, a common error message is displayed for all errors. However, I want to customize the error messages based on the specific type of error. For example, if the password is invalid, it should display "invalid password", and for an invalid ...

Excessive content within the div element causing overflow

In my Laravel project, I am facing an issue with the patient history form. The content overflows under a div as shown in the image below. View first image To address this problem, I tried using overflow:hidden in the CSS section. However, this caused my ...

Creating an animated Gif using HTML and CSS styling

I am trying to create an effect where a .gif animation plays once when the mouse hovers over a specific image. I have one static image in PNG format and one animated gif. The goal is for the gif to play every time the mouse is hovered over the png image. ...

Tips for showing an inline <span> within <div> elements

Is there a way to showcase inline spans within a div element while ensuring they are displayed equally in size and space, based on the user's screen? And how can I ensure that these spans are positioned behind other div elements? body { width: au ...

What is the best way to attach an event listener to detect the coordinates where a click occurs inside a div element?

Imagine a situation where you have a div container measuring 200px by 500px. The goal is to implement an event listener that can identify the x and y coordinates within this div when it is clicked. What would be the approach to achieve this in React? ...

Adjusting the width of input textboxes for alignment

I currently have a set of input textboxes that I have attempted to align using CSS with the {width: xxx px;} property. However, this method is unreliable as it does not consistently ensure proper alignment. <style> #left_col p { margin-top: 15px ...

Deleting content from cells in table for all even td items

This problem has been causing me frustration; I've attempted various methods using jquery and CSS, but to no avail. Essentially, I have the following table structure: <table id="mainTable"> <thead> <tr> <th>Arrival ...

Differences in disabled option value selection between jQuery legacy and updated versions

Recently, I upgraded the jQuery version in my project from 1.7.2 to 2.1.1 and included jquery migrate for fallback support. During testing, I encountered an issue with the value of a select element in jQuery versions 2.1.1 and 1.7.2: For version 1.7.2, t ...

How can we consolidate an excess of menu items into a condensed, collapsed menu?

I have a navigation bar displaying category items, but if the menu items exceed the navbar width, how can I condense them into a drop-down menu using Bootstrap 3.0? Currently, my navbar only shows 10 items due to limited space. However, I have more items ...

How to Transform a Navigation Bar into a Carousel

I am creating a website that is designed to be responsive. Currently, I have a horizontal navigation bar which collapses into a drop-down menu when the screen size decreases. When each tag in the menu is clicked, a different image loads into a designated ...

Using CSS Zoom / Transform with the iframe Tag in HTML

I'm currently working on embedding a child web page (a plain HTML/PHP file) into a parent web page built on WordPress. The challenge I'm facing is that the parent web page has a width of only 800px, whereas the child web page has a width of appro ...

Creating a CSS animation to repeat at regular intervals of time

Currently, I am animating an SVG element like this: .r1 { transform-box: fill-box; transform-origin: 50% 50%; animation-name: simpleRotation,xRotation; animation-delay: 0s, 2s; animation-duration: 2s; animation-iterat ...

Is there a way to horizontally navigate a pallet using Next and Prev buttons?

As someone new to development, I am looking for a way to scroll my question pallet up and down based on the question number when I click next and previous buttons. In my pallet div, there are over 200 questions which are dynamically generated. However, th ...

Steer clear of altering line spacing in CSS

Here is the HTML structure that I am working with: <div id="id1"> <h1>my name </h1><h3><a href="mailto:myemail_id"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff92869a929e9693969bbf878685d19 ...