"Overflowing with images: the boundless potential of Bootstrap

I'm facing a challenge with creating an image gallery using the Bootstrap grid layout:

https://i.sstatic.net/SATdi.png

Unfortunately, I am struggling to make the last image on the second row overflow into the first row...

Here is the HTML code snippet I am working with:

.gal-container {
    display: block;
    width: 100%;
    padding: 16px;
}
    
.nopadding {
    padding: 0 !important;
    margin: 0 !important;
}
    
.box {
    padding: 32px;
}
    
.row img {
    max-width: 100%;
    max-height: 100%;
}
<section>
    <div class="gal-container">
        <div class="box">
            <div class="row">
                <div class="col-sm-6 nopadding"><img src="img/image1.jpg"></div>
                <div class="col-sm-3 nopadding"><img src="img/image2.jpg"></div>
                <div class="col-sm-3 nopadding"><img src="img/image3.jpg"></div>
            </div>
            <div class="row">
                <div class="col-sm-3 nopadding"><img src="img/image4.jpg"></div>
                <div class="col-sm-3 nopadding"><img src="img/image5.jpg"></div>
                <div class="col-sm-6 nopadding"><img src="img/image6.jpg"></div>
            </div>
        </div>
    </div>
</section>
    

Upon implementing this code, the resulting layout is as follows:

https://i.sstatic.net/4orDD.jpg

Could someone kindly assist me in placing the Stranger Things image at the bottom of the two smaller pictures? Thank you!

Answer №1

There is no need for custom CSS, as this can be achieved with minimal code using only native Bootstrap 4 classes:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">

<section class="container">
    <div class="row no-gutters">
        <div class="col-sm-6">
            <div class="row no-gutters">
                <div class="col-12"><img src="img/image1.jpg"></div>
                <div class="col-sm-6"><img src="img/image2.jpg"></div>
                <div class="col-sm-6'><img src="img/image3.jpg"></div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="row no-gutters">
                <div class="col-sm-6"><img src="img/image4.jpg"></div>
                <div class="col-sm-6"><img src="img/image5.jpg"></div>
                <div class="col"><img src="img/image6.jpg"></div>
            </div>
        </div>
    </div>
</section>

Answer №2

Your code structure doesn't align with the desired layout you mentioned. To achieve the layout you want, consider using the following markup:

<div class="box">
        <div class="row">
            <div class="col-sm-6 nopadding">
                <div class="col-sm-12 nopadding">
                    <img src="img/image1.jpg">
                </div>
                <div class="row">
                    <div class="col-sm-6 nopadding">
                        <img src="img/image2.jpg">
                    </div>
                    <div class="col-sm-6 nopadding">
                        <img src="img/image3.jpg">
                    </div>
                </div>
            </div>
            <div class="col-sm-6 nopadding">
                <div class="col-sm-12 nopadding">
                    <img src="img/image4.jpg">
                </div>
                <div class="row">
                    <div class="col-sm-6 nopadding">
                        <img src="img/image5.jpg">
                    </div>
                    <div class="col-sm-6 nopadding">
                        <img src="img/image6.jpg">
                    </div>
                </div>
            </div>
        </div>
    </div>

Make sure to include overflow:hidden in elements with the class "nopadding". Hopefully, this resolves the issue!

Answer №3

To achieve the desired effect, simply rearrange the positioning and wrappers in your code.

Remember to account for paddings and widths as they will impact the alignment of elements.

For a full screen demonstration, adjust the sizing accordingly

.gal-container {
  display: block;
  width: 600px;
  padding: 16px;
}

.nopadding {
  padding: 0 !important;
  margin: 0 !important;
}

.box {
  padding: 30px;
}

.row img {
  max-width: 100%;
  max-height: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="gal-container">
  <div class="row">
    <div class="col-sm-6 nopadding">
      <div class="col-sm-12 nopadding"> <img src="http://via.placeholder.com/300x150"> </div>
      <div class="col-sm-6 nopadding"> <img src="http://via.placeholder.com/150x100"> </div>
      <div class="col-sm-6 nopadding"> <img src="http://via.placeholder.com/150x100"> </div>
    </div>

    <div class="col-sm-6 nopadding">
      <div class="col-sm-6 nopadding"> <img src="http://via.placeholder.com/150x100"> </div>
      <div class="col-sm-6 nopadding"> <img src="http://via.placeholder.com/150x100"> </div>
      <div class="col-sm-12 nopadding"> <img src="http://via.placeholder.com/300x150"></div>
    </div>
  </div>
</div>

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

Adjust the SVG to match the dimensions of the label, which may vary in both

How can I efficiently resize and embed SVG images into checkbox labels without using a viewbox attribute? Each SVG varies in height and width, making it challenging to find the best solution. .check__button { display: none; } .check__icon { display ...

Is it necessary to update the HTML lang attribute when switching between languages dynamically?

I have a one-page website that loads an AngularJS application supporting multiple languages. All the pages on the site are generated in the browser using JavaScript after the initial HTML is fetched from the server. I'm aware of the importance of se ...

Display a popover next to an icon using Bootstrap

I am using an information icon from Bootstrap: <div class="input-group-addon border-0 bg-white" id="snippet"> <span style="cursor:pointer;" class="fa fa-info-circle watiseenSnippetButton" aria-hidden="true"></span> </div> Addi ...

Is there a way to update the parent value when the child is activated?

I need to create a dropdown menu for users to select their email provider - either gmail, hotmail, or outlook. Once they make a selection, I want the button text to update accordingly. The catch is that I can only use bootstrap for this project and cannot ...

Sideways collapsing navigation bar with links sliding to the right

As I work on developing a horizontal menu, I encountered an issue with the expanding animation when clicking on the bento menu. Instead of smoothly transitioning to the right, the links are initially stacked up and then eventually align in a single line ...

Discover every DropDown that has a checkbox selected

I have a straightforward setup displayed below. My goal with jQuery is to locate all dropdowns where the checkbox is ticked. <table> <tr> <td> <asp:DropDownList ID="ddDurationHours" runat="server"/> <td> <t ...

Issue with CSS Media Queries: Preventing an Element From Being Affected

As a complete beginner in HTML and CSS, I have a question that may seem silly. Recently, I created this HTML code: * { margin: 0px; padding: 0; box-sizing: border-box; } p { font-size: 14px; font-family: 'Work Sans', 'sans seri ...

What is the process for adjusting the color of the underline in Material UI input fields

I am facing an issue with a Material UI Select component that is on a dark background. I want to change the text and line colors to white just for this particular component, while keeping the rest of the Select instances unchanged. Although I have managed ...

Using Node.js to Send Emails via API

I've been grappling with an issue for over a week while trying to develop a web application that sends welcome emails to new subscribers. Despite my API code working perfectly, I cannot seem to get any output on the console indicating success or failu ...

<Select> Placeholder customization

For my react project, I am utilizing material-Ui and I am looking to have a placeholder that stands out by having grey text instead of black when compared to the selected item. <Select name="answer" value={values.answer} onChange={handleChange} onBlur= ...

Guide on configuring href tags in single-page JavaScript/HTML5 apps

After developing a "small" single page web application using python/django/backbone, similar to a basic Todo List app, a challenge arose regarding maintaining SEO-friendly href attributes without forcing users' browsers to reload the entire app at a n ...

Differentiate between chrome and chromium with the help of Javascript programming

Can we differentiate between Google Chrome and the open-source Chromium browser using JavaScript? It appears that the navigator.userAgent property is the same in both browsers. ...

Can anyone help me identify the issues in my PHP code?

My PHP code doesn't appear to be functioning correctly. Instead of displaying any errors, it simply shows a blank page. Can you identify what I might be doing incorrectly? <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_ ...

What is the reason my favorite icon is no longer functioning in Chrome?

My favicon was initially displaying on Chrome Canary, but after updating it disappeared. Here is the code I am using: <html> <head> <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" /> <title>Wr ...

Utilizing Bootstrap 4: Opting for <select> over tabs (<li>)

Is there a way to customize the appearance of Bootstrap tabs by replacing them with a dropdown select menu instead of the standard tab layout created with <ul> and <li> elements? I am working with a relatively small area (such as col-3) where ...

Positioning elements in CSS relative to a specific div container

Looking for advice on how to position two images within a div using percentages relative to the parent div. Check out this fiddle for reference: http://jsfiddle.net/b9ce626s/ I experimented with setting position: absolute; on the image, but it seems to b ...

Choose the Nth option in the dropdown list using programming

Currently, I have a script that dynamically populates a select box with unknown values and quantities of items. I am looking to create another script that mimics the action of selecting the Nth item in that box. Despite my research, I have been unable to ...

DIV collapsing in reverse order from the bottom to the top

Looking for some help on how to create two links that, when clicked, will scroll a hidden <div> up to fill the full height of its parent container. I've been having trouble with the element using the full height of the <BODY> instead. ...

Displaying buttons on each row in an ngx-datatable based on a condition using *ng

In my table, there is a column with a hidden element that appears when a show button is clicked. Currently, clicking the button reveals all hidden fields at once. I want to modify this so that only the input field for the specific row appears when the butt ...

How to style the background color of the selected option in a <select> element using

Is there a specific style I can use to change the color of a selected option in a dropdown menu? For example: <HTML> <BODY> <FORM NAME="form1"> <SELECT NAME="mySelect" SIZE="7" style="background-color:red;"> <OPTION>Test 1 &l ...