Guide on aligning two images side by side

Is there a way to align two images side by side and then include a <div> with a smaller width and apply overflow: hidden?

Similar to a slider. I keep getting images stacked on top of each other (block level), but I want them inline.

* {
    margin: 0;
    padding: 0;
    box-sizing:border-box;
}

.slider div {
    background-color: red;
    position:relative;
}
img {
    width: 600px;
    height: 300px;
    position:relative;
    display:inline-block;
}
<div class="slider"><div>
        <img src="https://lh3.googleusercontent.com/proxy/Lg1sxGxpUtviON3zqYv_Pjz_gLMf2YhlOvuFPe1-zfusYQum6pOfMrXRCxR6MfnUoJ7IK2VAihsNxJkL0qhmRVRo1vxTpClk_970lE6gp5XQ" alt="">
        <img src="https://imgcomfort.com/Userfiles/Upload/images/illustration-geiranger.jpg" alt="">
</div>
</div>

Answer №1

Using flexbox is a versatile solution.

Flexbox allows you to easily arrange items in either a row or column layout. All elements within a flex container are positioned next to each other in the specified direction, with the default being a row. By utilizing the flex-direction property, you can customize this layout further. For more detailed instructions, refer to this comprehensive guide: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Don't forget to set overflow: auto for scroll functionality when the container size is smaller than its contents.

* {
  margin: 0;
  padding: 0;
  box-sizing:border-box;
}

.slider {
  display: flex;
  overflow: auto;
}

img {
  width: 600px;
  height: 300px;
}
<div class="slider">
  <img src="https://lh3.googleusercontent.com/proxy/Lg1sxGxpUtviON3zqYv_Pjz_gLMf2YhlOvuFPe1-zfusYQum6pOfMrXRCxR6MfnUoJ7IK2VAihsNxJkL0qhmRVRo1vxTpClk_970lE6gp5XQ" alt="">
  <img src="https://imgcomfort.com/Userfiles/Upload/images/illustration-geiranger.jpg" alt="">
</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

Ways to extract information from a URL when utilizing JQuery code

Code snippet: $(document).ready(function(){ $(".uni_type").click(function(){ uni_type = this.id; location.href = "filter-colleges.php?uni_type="+uni_type; }); }); HTML code: <ul> <li class="uni_type" id="central univ ...

Steps for implementing overflow scroll on a div with an unspecified height

The layout I'm working with looks like this: .page { width: 360px; height: 704px; border: 1px solid red; } header { height: 10%; width: 100%; display: flex; align-items: center; justify-content: center; background-color: lightblue; } ...

Issues with image sizing on mobile devices

After finalizing my header design, I encountered an issue with the mobile version of the website. The images in the header are not responsive and do not adapt well to different screen sizes. I need assistance converting the header design into functional co ...

"Exploring the versatility of Flask, Python, and dynamic css

Currently, I am working on developing an online random color generator using Python and Flask. I have successfully created a function that generates a random hex color code. However, I am facing difficulty in passing this color code into the CSS background ...

Initiate movement upon scrolling

I would like to activate this box animation once the user scrolls down by adding a class. I'm having trouble getting this to work, it seems like I might be missing something crucial. Here is my current code, can someone point out where I am going wro ...

Align an image in the center of a div without using absolute positioning

I'm currently facing an issue where I need to align an image at the center of a div without using absolute positioning. This is necessary because the image spills over into any adjacent divs on the page. Specifically, I have a previous div containing ...

Extract information from the document and adjust the size of the extracted portion to fit into another div

My main goal here is to create a tool that can crop any part of an HTML document (such as an image or white background) and then scale that cropped area to fit into the red square at the bottom of the interactive demo. This is the final step in developing ...

Problem with Firefox full screen slider

Welcome to my website where I have created a full-screen slider for you to enjoy. If you'd like to check it out, just click on the website link. The slider functions perfectly on Chrome and IE, but unfortunately on Firefox, it only shows half of the ...

Attempting to modify header color in various website sections without success

I've been struggling to figure out this code: <script> window.onload = function() {myFunction()}; window.onscroll = function() {myFunction()}; function myFunction() { const top1 = document.getElementById("big-landing ...

Unable to get 'div' content to display using jQuery when using third party modules such as Angular

I am currently facing an issue where I am trying to display the content of a <div id="right"> when hovering the mouse over another div. The #right div contains a graph from Angular-charts (). Below is my jQuery code: <div> ...

Store various images in a database by inputting each image's path into a distinct column in MySQL

Welcome Everyone, Presenting my HTML Form: <form action="" id="uploadForm" class="col-md-8 col-md-offset-2" > <h2 class="bold text-uppercase"></h2> <br> <div> <div class="input-grou ...

Is the Paypal button causing issues with the navigation bar?

I recently encountered an issue while trying to integrate the Paypal smart button into my first project. Whenever the Debit or Credit card button is clicked, the text above it overlaps with the navbar. I attempted to add extra space to the background image ...

Issue encountered with jQuery nested hover events and the removeClass() function being triggered on mouseleave

I have a nested list structure that I am working with: <ul class="menu-wrapper"> <li> <a href="#">Menu item</a> <ul class="sub-menu"> <li> < ...

Efficiently formatting text in a div container

How can I ensure that the text within a span is word-wrapped inside a div? https://i.sstatic.net/W691d.png Here is the code snippet: <div class="col-xs-6 choice btn btn-default" > <span class="pull-left">(Kepala) Bagian Purchasing (not lis ...

Tips on aligning two bootstrap columns side by side

Having trouble aligning my two columns side by side. Despite my efforts, the second column (col-11) keeps appearing below col-1. The image inside col-1 should be on the far left with the other column right next to it. <div class="container col-md-12 wm ...

Updating the UpdatePanel causes duplication of CssClass

In my ASP.NET Webforms project, I have created a user control that inherits from the LinkButton. This user control has a property to adjust the size by adding predefined CSS classes to the control. Protected Overrides Sub CreateChildControls() Dim Siz ...

React - Highcharts Full Screen dark overlay

I am currently working on integrating highcharts/highstock into my application, and I have encountered an issue with the full screen functionality. The challenge I am facing is setting a fixed height for my charts while also enabling the option to view ea ...

Creating a multi-file upload feature in Django

Looking for a way to achieve multiple file uploads in Django with two models? I have one form but need to handle data for two separate models models.py class Advertisement(models.Model): title = models.CharField(max_length=85, blank=False) class Ima ...

Issue with Selenium WebDriver: Expectation failure while waiting for element visibility at specified location(..)

I'm facing a little issue with my automated test. Whenever the test encounters an error like this: Expected condition failed: waiting for visibility of element located by(...) I find it difficult to pinpoint the exact problem. @BeforeMethod pub ...

Utilizing multiple visuals in one post: Mastering Core Data with Swift

I am currently developing a Swift Core Data application for a diary-like app that allows users to input entries with both a title field and an image picker. At the moment, I have only included one image attribute of type Binary Data. I would like to enab ...