Adjusting Images in HTML

I'm struggling to display 4 images on a single page in the desired sequence, similar to the example below: https://i.sstatic.net/3V1Ru.png

Currently, my code only aligns the images to the left-hand side. Here is a snippet of my code:

<style>
img {
    max-width: 100%;
    max-height: 100%;
}

<div class="4_page" style='height: 50%; width: 25%;text-align: center; object-fit: contain'>
    <img src="hebahan New material.png">
</div>


<div class="4_page" style='height: 50%; width: 25%;text-align: center; object-fit: contain'>
    <img src="logo_test.png">
</div>

<div class="4_page" style='height: 50%; width: 25%;text-align: center; object-fit: contain'>
    <img src="logo_test.png">
</div>

<div class="4_page" style='height: 50%; width: 25%;text-align: center; object-fit: contain'>
    <img src="logo_test.png">
</div>

</style>

I would appreciate any guidance on how to resolve this issue. Thank you.

Answer №1

Make sure to keep the <div> tag outside of the <style></style> tags. See if this resolves your issue. Alternatively, you can structure it like so using a table instead --

The primary index.html file:

<!DOCTYPE html>
<html>
   <head>
      <title>YourTitle</title>
      <link rel ="stylesheet" href="style.css">
      <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!--For responsiveness-->
   </head>

   <body>
      <table class="img-cont"> <!-- Images will be arranged based on specified height. Always enclose table in a <div> when displaying additional information. --> 
         <tr>
             <th><img src="hebahan New material.png"></th>
             <th><img src="logo_test.png"></th>
         </tr>

         <tr>
             <th><img src="logo_test.png"></th>
             <th><img src="logo_test.png"></th>
         </tr>
      </table>
   </body>
</html>

In my external style.css, I have:

.img-cont {
   width:100%;
   height:100%; /* Set height to 100% only if showing images exclusively */
}

img {
   max-width:100%; /* Adjust as needed */
   max-height:100%;
}

This streamlined approach reduces code and boosts performance. Please mark this as the solution if successful. 🙂🙂

Answer №2

  1. Consider utilizing CSS instead of inline styling for better organization.

  2. Avoid starting class names with a number for compatibility reasons.

  3. Modify the height according to your specific needs and design requirements.

.col-25{
border:2px solid yellow;
display:inline-block;
height: 400px;
width: 49%;
box-sizing:border-box;
text-align:center;
margin-bottom: 10px;
}
<div class="col-25">
    <img src="hebahan New material.png">
</div>


<div class="col-25" >
    <img src="logo_test.png">
</div>

<div class="col-25" >
    <img src="logo_test.png">
</div>

<div class="col-25" >
    <img src="logo_test.png">
</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

Numerous toggles available for the mobile version

Hey there, I need some help! I have a footer navigation on my desktop website with 3 Ul elements. I want to turn each Ul into a toggle for the mobile version. Can anyone assist me with this? Thanks in advance! <footer class="footer"> <d ...

Consecutive pair of JavaScript date picker functions

My issue involves setting up a java script calendar date picker. Here are my input fields and related java scripts: <input type="text" class="text date" maxlength="12" name="customerServiceAccountForm:fromDateInput" id="customerServiceAccountForm:from ...

Adjust the arc angle on the canvas

I am currently working on creating a Semi Arc using Canvas. My question is regarding changing the overall angle of the arc to match the expected image. Expected Image Below is the HTML code for the Semi arc: <canvas id="myCanvas" width="578" height=" ...

Add Your Logo to the Navigation Bar using CSS

Can someone please assist me with adding a logo to my CSS navbar? I am struggling to figure out how to do this and would appreciate any guidance or tips on how to successfully implement a logo in the navbar. body { margin: 0px; } ul { list-style-ty ...

Are there any jQuery plugins available that can display a loader image while a page is loading?

After extensive research on Google, I have been unable to find the plugin I need. If you are aware of any suitable plugins, please let me know. Thank you in advance! ...

Unable to interpret the JSON reply from the server

I am currently developing a web application that sends data to a website, which then updates its database and returns a JSON array to replace my web app page. I am using AJAX for this query, but I am facing an issue with preventing the overwriting of my we ...

Show a div pulsating while simultaneously animating another div

After coming across this query on Stack Overflow about adding a class without jQuery if hovering over another class I encountered an issue with a div element that displays upon hovering over a span, which was functioning correctly. However, I also have a ...

Incorporating user input into a div element

So, I'm in the process of building my own Task Tracker using JavaScript to enhance my skills, but I've hit a roadblock. I successfully implemented adding a new div with user-inputted tasks, however, there's no styling involved. <div cla ...

What is the best way to serialize data from non-form elements and make it easily accessible through params[:model]?

I have developed a unique Sinatra application that leverages an external API to load data and exhibit it on a page. Utilizing Sinatra, the information is retrieved and stored in a temporary model instance (which is NOT saved) for seamless access to all its ...

Imitate the act of pasting content into a Textarea using JavaScript

When data is copied from the clipboard and pasted into an html textarea, there is some interesting parsing that occurs to maintain the formatting, especially with newlines. For instance, suppose I have the following code on a page that I copy (highlightin ...

CSS3 Animation for Marquee Image

I'm struggling to create a CSS3 animation for an image. My goal is to have the image continuously wrap around and scroll across the page, but I can't get it to work as intended. Here's a simple snippet of my HTML: <div id="space" class=" ...

Press the Concealed Button Enclosed in a div Using Selenium with Python

Currently, I am in the process of automating the login on the Workday portal by utilizing Chrome WebDriver in Selenium. My main challenge lies in figuring out how to click on a hidden sign-in button with the following properties: <div class="css-1s ...

How can I use jQuery to identify the numerical range within class/td/div elements and modify their CSS styles?

1# I need assistance in changing the CSS properties of a TD, Class, and div using a selector that specifies a specific number range. Specifically, I am looking to modify the css of torrent results with a seed count between 250-25000. Any torrents with a se ...

Tips for showing an image in a pop-up window using Window.open

I'm attempting to show an image in a popup window using the following JavaScript code: function newPopup(url) { popupWindow = window.open( url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=no,t ...

How to send parameters to the jQuery delete button click event handler

Here is the jQuery code I am working with: $('#btnDelete').click( function() {//Do the delete here via jquery post}); In my table, each row has a delete button like this: <a id="btnDelete">Delete</a> I need to pass parameters to t ...

What is the method for emphasizing links in the navigation bar with Bootstrap 3?

I am currently working on applying custom CSS styles to the Bootstrap navbar in order to have the link text underlined when hovered over, with a fade-in effect as well. To see what I have accomplished so far, you can view it here: https://jsfiddle.net/xfd ...

What is the appropriate conversion for a CSS property name starting with -webkit when working with React?

For example, using `-webkit-text-fill-color` resulted in an error when setting it to `'red'`, stating "Using kebab-case for CSS properties in objects is not supported. Did you mean WebkitTextFillColor?" I have attempted `WebkitTextFillColor`, `w ...

The Send.php script is missing the input fields for Name and Email

Running my own website at CrystalVision.com, I have some challenges with my PHP skills. The issue lies within my send.php file. Although the email functionality works fine and I receive messages, the Name and Email fields filled in by users are not display ...

What is the best way to centrally position a <mat-card> on the screen using Angular 9?

* I'm struggling to center a <mat-card> on the screen, specifically within the toggle-device-toolbar. It's intended for mobile phones and I could use some guidance. I'm working with angular-material and ng-bootstrap* Here is the code ...

Is there a way in CSS to apply multiple colors to individual letters within a word?

Is it possible to add random colors to every pixel of a letter or multiple colors to a letter using CSS? Check out this example. ...