Photos appearing outside the border

My current border has a vertical flow like this: https://i.sstatic.net/CdUm6.png
(source: gyazo.com)

However, I want the content to flow horizontally from left to right instead of top to bottom.

When I apply float: left; to the controlling div, it results in the following layout: https://i.sstatic.net/ikBsJ.png
(source: gyazo.com)

The images are now positioned outside of the border. Here is a snippet of the current code for the content:

<div class="courses">
                <figure>
                    <img src="http://atlanta.eat24hours.com/files/cuisines/v4/chinese.jpg" alt="Asian" height="300px" width="300px" />
                    <figcaption>Bok choi</figcaption>
                </figure>
        </div>
        <div class="courses">
        <figure>
                    <img src="http://atlanta.eat24hours.com/files/cuisines/v4/chinese.jpg" alt="Asian" height="300px" width="300px" />
                    <figcaption>Bok choi</figcaption>
                </figure>
            </div>

If possible, please check the jsfiddle that demonstrates the issue. Additionally, any tips on how to ensure that the text remains on the right side of the image even when the page is resized too small would be greatly appreciated. In the jsfiddle, you can observe that the text shifts below the image when the page size decreases.

Answer №1

The root of this problem lies in the failure to properly clear the float property when styling elements with `float: left`. Floating an element removes it from the normal document flow, causing layout issues. To resolve this, you must clear the float for the containing element (for instance, adding a clear property to the parent element of the floated element).

There are several methods to achieve this:

  1. One workaround is to apply `overflow: hidden;` to the parent container with the class `.wrapper`.
  2. You can also change the display property of the parent container to `inline-block` by setting `display: inline-block;` on the `.wrapper`.
  3. To properly clear the float, you can add a pseudo-element to the `.wrapper`, like so:

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

Answer №3

Here is some CSS code that might help solve your issue. I am fairly new to stackoverflow and still learning about php and javascript.

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

There are many different approaches to solving this problem, but it's best to avoid posting complete code blocks due to stack overflow policy.

Answer №4

One way to handle overflowing content is by applying the overflow:hidden property to the .container class. Another approach could be to utilize the display:inline-block property for the .lessons class instead of opting for float:left.

Answer №5

Whenever you set all elements to float inside a specific element, that same element will collapse.

To resolve this issue, consider adding overflow:hidden; to the wrapper. This is a commonly used fix for such situations.

Alternatively, you can implement the following solution:

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

By doing this, the :after pseudo element of the wrapper can effectively clear the container without encountering any potential problems typically associated with using overflow:hidden;

Answer №6

give this a shot!

.container{
    background-color: #ffffff;
    width: 80%;
    display: flex;/*modified*/
    border: 1px solid #000000;
    justify-content: center;
}
.classes{
    float:none;
}

Answer №7

use custom styles

.container{
    background-color: #f2f2f2;
    width: 90%;
    border: 1px solid gray;
    text-align: center;
    overflow: hidden;
    margin: 0 auto;
}

create a webpage layout

<div class="container">
        <header>
            <h1>Sophie's bakery</h1>
            <nav>
                <ul>
                    <li>breakfast</li>
                    <li>lunch</li>
                    <li>dinner</li>
                    <li>desserts</li>
                </ul>
            </nav>
        </header>

        <div class="items">
                <figure>
                    <img src="http://example.com/bakery.jpg" alt="Bakery Items" height="250px" width="250px" />
                    <figcaption>Croissants</figcaption>
                </figure>
        </div>
        <div class="items">
        <figure>
                    <img src="http://example.com/bakery.jpg" alt="Bakery Items" height="250px" width="250px" />
                    <figcaption>Cupcakes</figcaption>
                </figure>
            </div>

    </div>

Answer №8

In order to streamline your images, consider consolidating them within a single division and adjusting the CSS for your class. This way, all images will be contained within one division rather than each having its own separate division.

<div class="courses">
                <figure>
                    <img src="http://atlanta.eat24hours.com/files/cuisines/v4/chinese.jpg" alt="Asian" height="300px" width="300px" />
                    <figcaption>Bok choi</figcaption>
                </figure>
        <figure>
                    <img src="http://atlanta.eat24hours.com/files/cuisines/v4/chinese.jpg" alt="Asian" height="300px" width="300px" />
                    <figcaption>Bok choi</figcaption>
                </figure>
            </div>

Here is an example of what the CSS could look like:

.courses{
any style you want for figcaption and figure.

}

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

Winning opportunities created by using credits in the slot machine

**Greetings, I have created a slot machine using JavaScript, but I am looking to enhance the player's chances based on their credits. Can anyone guide me on how to achieve this? Essentially, I want the player's odds to increase proportionally wit ...

The input field will be in a read-only state if it contains a value from the database. However, it will be editable if the value

Hello everyone, I am a newcomer to this community and would greatly appreciate your help. I am encountering an issue with the following lines of code: <input type="text" class="form-control" id="fines" name="fines&quo ...

Instructions on displaying the main page even with just inputting the default directory in the URL

One scenario is when I input file:///C:/xampp/htdocs/At/html/ in the URL. My desired outcome is for file:///C:/xampp/htdocs/At/html/pages-login.php to be displayed instead. How can I achieve this? ...

What could be causing the issue with my linear gradient not displaying correctly on top of my background image in Rails and Sass?

I am struggling to get a linear gradient to display over a background image. Despite trying various solutions from other questions, I still can't get it to work with my current code... .bottom-pic { width: 100%; height: 425px; ...

The 'refresh' function in jQM listview is causing issues with inset lists

For some reason, I am struggling to understand why this issue is occurring: In jQuery Mobile, I have an unordered list with data-inset="true". Initially, it displays perfectly with rounded top and bottom edges. However, on dynamically adding new elements t ...

When the user clicks, show a designated search result in a separate container

I've been developing my Angular cocktail application, and I've reached a point where I can display all the cocktails in my database (only showing names). Now, I want to implement a feature where if I click on a specific cocktail, its full content ...

Breakpoint for mobile menu in FoundationCSS

When the browser is resized, the mobile menu appears at 568x320, which is the default breakpoint. https://i.sstatic.net/ZSbiq.jpg I would like to create a breakpoint around 900px to address the issue with the menu being too large as shown in the image be ...

Stylish Pop-up Box appears hidden behind a different element

Is there a way to fix the issue of the FancyBox plugin being blocked by some part of the HTML on the page when trying to load a Vimeo movie into a popup? Here is the live link: click here : it's when you click on the slider image underneath the yello ...

Creating a video game HUD effect using JavaScript and HTML5

In an attempt to recreate a video game HUD using HTML5, I have styled a div with CSS properties to resemble a game overlay. When a navigation link is clicked, the div should transition from a hidden state (display:none), then flash twice rapidly before fad ...

How to set the value of an `<input type="date"` in jQuery

Having trouble figuring out why this code isn't functioning properly. The input field I'm using is a simple 'input type="date"' setup like this.... <input type="date" name="Date"/> I am attempting to have the value automatically ...

Tips for transferring information from Angular 6 to Node.js

Having recently delved into Angular 6 for the first time, I find myself tasked with sending data to a Node.js server. The code snippet below illustrates my approach within an Angular function: import { Component, OnInit } from '@angular/core'; ...

Using jquery to dynamically set the value of a drop down menu

I am struggling with a dropdown list that is being generated dynamically using ajax when the page loads. Additionally, I have a PHP variable that holds the default selected value. However, despite my attempts to select this value, it does not work as expec ...

Generating pop-up upon loading with CSS3

I have searched through numerous threads and forums in the hopes of finding a solution, but I haven't been successful. My issue lies with triggering a popup on my website. I followed online tutorials to create a popup window, which I was able to do su ...

Bootstrap 5's h-100 feature functions flawlessly in Chrome, however, it encounters issues when used with a group

Can you please refer to this question: Issue with Aspect Ratio of Images in Bootstrap 5 due to Padding After applying the h-100 solution, everything looks great on Chrome. Unfortunately, when I check it in Safari, the aspect ratio of the image gets distor ...

Adjust the size of the child div to fit the remaining space within the parent div

I'm dealing with a situation where there are two child divs inside a parent div. The first child div takes up 32% of the width, while the second child div takes up 68% of the width. If I were to set the display of the first child div to "none", how ca ...

Positioning of buttons in Bootstrap 5 tables

I am working on a table that represents a CRUD application with details of a person and edit/delete buttons. The goal is to have these buttons displayed side by side, even on smaller screen sizes where they currently stack on top of each other. How can I ...

generating the <tr> element within a loop

I've been working on creating a calendar, but I'm facing an issue with the way the days are laid out horizontally. Here's how it currently looks: https://i.sstatic.net/PWcCi.png As you can see, only the <td> tags have been created. I ...

Implement input validation in React by enhancing the functionality of HTML input tags

Below is the input provided: const REGEX_EMAIL_VALIDATION = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}&bsol ...

Incorporating custom CSS and HTML into the link is essential for enhancing the appearance of KnpMenu

I'm working with the KnpMenuBundle and I need to customize a link that has the route 'uri'=>'#'. How can I achieve this? The desired link should be styled like this: <a href="#" class="js-sub-menu-toggle"> &l ...

Learn how to display two rows of div elements within a single div container

In my program, I am using a for loop to display multiple div elements in one row. The first div is showing up correctly, but I am having trouble inserting a new div that looks the same as the first one. How can I achieve this? Thank you in advance. "first ...