Centered horizontally are images that have been floated

How can I align images with different widths when they are all floated right? I want them to be aligned vertically below each other.

For the best display, please view in fullscreen on your computer as the example window is small.

.compressor{
height: 150px;
float: right;
}
<div>

<a href="../photos/ESM250.gif" rel=lightbox[compressor1] data-title="Gardner Denver ESM250 compressor"><img src="http://matmasar.wz.cz/fotky/ESM250.gif" title="Gardner Denver ESM250 compressor" alt="Gardner Denver ESM250 compressor" class="compressor"></a>
-Screw compressors system load - unload, type <b>ESM 2-500</b>
<ul>
<li>Constant motor speed</li>
<li>Delivery volume: 0.24 - 73.60 m<sup>3</sup> /min</li>
<li>Output pressure: 5 - 13 bar</li>
<li>Power up to 500kW</li>
</ul>
</div>


<div>
-Screw compressors with frequency converter, type <b>VS7 - VS290</b>
<a href="../photos/GD_VS7.gif" rel=lightbox[compressor2] data-title="Gardner Denver VS7 compressor"><img src="http://matmasar.wz.cz/photos/GD_VS7.gif" title="Gardner Denver VS7 compressor" alt="Gardner Denver VS7 compressor" class="compressor"></a>
<ul>
<li>Variable motor speed = higher operational efficiency</li>
<li>Delivery volume: 0.41 - 42.30 m<sup>3</sup> /min</li>
<li>Output pressure: 5 - 13 bar</li>
<li>Power up to 290kW</li>
</ul>
</div>


<div>
-Oil-free screw compressors series <b>Ultima U75 - 160 PureAir</b>
<a href="../photos/UltimaU75-160_PureAir.gif" rel=lightbox[compressor3] data-title="Gardner Denver Ultima U75-U160 compressor"><img src="http://matmasar.wz.cz/photos/UltimaU75-160_PureAir.gif" title="Gardner Denver Ultima U75-U160 compressor" alt="Gardner Denver Ultima U75-U160 compressor" class="compressor"></a>
<ul>
<li>Unique design - high efficiency, low noise</li>
<li>Variable motor speed</li>
<li>100% oil-free air, ISO 8573-1 Class Zero (2010) compliant</li>
<li>Power up to 160kW</li>
</ul>
</div>

Answer №1

When utilizing the float property, the floating element does not affect the height of its parent element. The following <div> cannot utilize the full width because it is not completely positioned below the floated image from the previous <div>. In order to ensure that it starts fully below all float elements, you must apply clear: both;. I have made adjustments to your example code to illustrate this:

.kompresor{
height: 150px;
float: right;
}
.clear-both {
  clear: both;
} 
<div>

<a href="../fotky/ESM250.gif" rel=lightbox[kompresor1] data-title="kompresor Gardner Denver ESM250"><img src="http://matmasar.wz.cz/fotky/ESM250.gif" title="kompresor Gardner Denver ESM250" alt="kompresor Gardner Denver ESM250" class="kompresor"></a>
-Mazné šroubové kompresory systém zatíženo – odlehčeno, typ <b>ESM 2 -500</b>
<ul>
<li>Stálá rychlost motoru</li>
<li>Dodávaný objem: 0,24 – 73,60 m<sup>3</sup> /min</li>
<li>Výstupní tlak: 5 - 13 bar</li>
<li>Výkon až 500kW</li>
</ul>
</div>


<div class="clear-both">
-Mazné šroubové kompresory s frekvenčním měničem, typ <b>VS7 – VS290</b>
<a href="../fotky/GD_VS7.gif" rel=lightbox[kompresor2] data-title="kompresor Gardner Denver VS7"><img src="http://matmasar.wz.cz/fotky/GD_VS7.gif" title="kompresor Gardner Denver VS7" alt="kompresor Gardner Denver VS7" class="kompresor"></a>
<ul>
<li>Proměná rychlost motoru = vyšší efektivita provozu</li>
<li>Dodávaný objem: 0,41 – 42,30 m<sup>3</sup> /min</li>
<li>Výstupní tlak: 5 - 13 bar</li>
<li>Výkon až 290kW</li>
</ul>
</div>


<div class="clear-both">
-Bezmazné šroubové kompresory řady <b>Ultima U75 – 160 PureAir</b>
<a href="../fotky/Ultima U75-160_PureAir.gif" rel=lightbox[kompresor3] data-title="kompresor Gardner Denver Ultima U75-U160"><img src="http://matmasar.wz.cz/fotky/Ultima U75-160_PureAir.gif" title="kompresor Gardner Denver Ultima U75-U160" alt="kompresor Gardner Denver Ultima U75-U160" class="kompresor"></a>
<ul>
<li>Jedinečný design – vysoká efektivita, nízký hluk</li>
<li>Proměná rychlost motoru</li>
<li>100% čistý vzduch bez oleje, splňuje ISO 8573-1 Class Zero (2010)</li>
<li>Výkon až 160kW</li>
</ul>
</div>

Answer №2

To achieve a centered column layout with images on the right side of text, you can implement the following HTML markup and CSS styling.

(1) Start by adding a wrapper div.table-wrap element with a property of display: table.

(2) Set display: table-row for the child div elements inside the wrapper.

(3) Place the top line of text (title) as the first item (li) in a ul block, give it the class title, and style it accordingly. Position the a element after the ul block.

(4) Apply display: table-cell to both the ul and a elements, using vertical-align: top and text-align: center for the a element.

(5) Fine-tune the margins and padding to optimize white space distribution.

The wrapper styled with display: table facilitates centering the images in a CSS-table column. You can also choose to center the entire table if needed.

This layout offers decent responsiveness and allows control over spacing through margin and padding adjustments.

div.table-wrap {
  display: table;
  width: auto;
  margin: 0 auto; /* Optional: center the table/panels */
}

div.table-wrap div {
  display: table-row;
}

div.table-wrap ul {
  display: table-cell;
  vertical-align: top;
  margin: 0;
  padding: 0;
}

div.table-wrap ul li {
  margin-left: 20px;
}

div.table-wrap ul li.title {
  list-style: none;
  font-size: 1.00em;
  margin: 0 0 10px 0;
}

div.table-wrap a {
  display: table-cell;
  vertical-align: top;
  text-align: center;
}

div.table-wrap a img {
  height: 175px;
  padding-left: 20px;
}

div.table-wrap ul,
div.table-wrap a {
  padding-bottom: 10px; /* Affects row/panel spacing */
}
<div class="table-wrap">
  <div>
    <ul>
      <li class="title">- Lubricated screw compressors, load-unload system, type <b>ESM 2 -500</b></li>
      <li>Constant motor speed</li>
      <li>Discharge volume: 0.24 – 73.60 m<sup>3</sup>/min</li>
      <li>Output pressure: 5 - 13 bar</li>
      <li>Power up to 500kW</li>
    </ul>
    <a href="../photos/ESM250.gif" rel=lightbox[compressor1] data-title="Gardner Denver ESM250 compressor"><img src="http://example.com/photos/ESM250.gif" title="Gardner Denver ESM250 compressor" alt="Gardner Denver ESM250 compressor" class="compressor"></a>
  </div>
  <div>
    <ul>
      <li class="title">- Lubricated screw compressors with frequency converter, type <b>VS7 – VS290</b></li>
      <li>Variable motor speed = increased operational efficiency</li>
      <li>Discharge volume: 0.41 – 42.30 m<sup>3</sup>/min</li>
      <li>Output pressure: 5 - 13 bar</li>
      <li>Power up to 290kW</li>
    </ul>
    <a href="../photos/GD_VS7.gif" rel=lightbox[compressor2] data-title="Gardner Denver VS7 compressor"><img src="http://example.com/photos/GD_VS7.gif" title="Gardner Denver VS7 compressor" alt="Gardner Denver VS7 compressor" class="compressor"></a>
  </div>
  <div>
    <ul>
      <li class="title">- Oil-free screw compressors series <b>Ultima U75 – 160 PureAir</b></li>
      <li>Unique design – high efficiency, low noise</li>
      <li>Variable motor speed</li>
      <li>100% oil-free air, compliant with ISO 8573-1 Class Zero (2010)</li>
      <li>Power up to 160kW</li>
    </ul>
    <a href="../photos/Ultima_U75160_PureAir.gif" rel=lightbox[compressor3] data-title="Gardner Denver Ultima U75-U160 compressor"><img src="http://example.com/photos/Ultima_U75160_PureAir.gif" title="Gardner Denver Ultima U75-U160 compressor" alt="Gardner Denver Ultima U75-U160 compressor" class="compressor"></a>
  </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

Trouble with retrieving data from localStorage

On my webpage, I have set up multiple input fields where users can enter data. When they click a button, the data from these inputs is stored inside <span>...</span> elements (the intention being that the text remains visible in these <span& ...

Finding the data type based on the button clicked with javascript: A beginner's guide

I am trying to work with a PHP function that generates dynamically created divisions. Each of these divisions contains a different data type and a button. How can I extract the data type of a division when the user clicks on the submit button using JavaScr ...

The ng-repeat function in AngularJs does not display the data despite receiving a successful 200 response

As part of my academic assignment, I am exploring Angularjs for the first time to display data on a webpage. Despite receiving a successful http response code 200 in the Chrome console indicating that the data is retrieved, I am facing issues with displayi ...

trouble displaying strength of passwords in AngularJS

Recently, I've delved into the world of angular js and have been working on a new directive to showcase the strength of passwords. If you'd like to see what I've done so far, check out this fiddle - https://jsfiddle.net/user_123/3hruj8ce/12 ...

The code encountered an error because it was unable to access the property 'style' of an undefined element on line 13 of the script

Why is it not recognizing styles and showing an error? All paths seem correct, styles and scripts are connected, but it's either not reading them at all (styles) or displaying an error. Here is the html, javascript, css code. How can this error be fix ...

Personalizing CSS for a large user base

My website allows users to choose themes, customize background, text, and more. I am seeking the best method to save all of these changes. Is it preferable to use a database read or a file read for this purpose? Any recommendations are greatly appreciate ...

Is it possible to create floating unordered lists using Bootstrap in HTML?

Is there a way to float text left or maintain list order in the HTML code of my page while using a dense CSS from this bootstrap template? For example, I would like my list to remain organized regardless of how many items are added: However, after adding ...

Fetching data using HTML script is not possible

Struggling to retrieve data from mongoDB and send it to the client side using res, but I keep getting undefined. Can anyone offer some assistance? Thank you all! //// server.js app.get('/user/show', userController.userList); //// controller cons ...

Concealing a DIV element when the value is not applicable

I'm currently working on a website for a coffee shop product. On this site, each product has a coffee strength indicator that is determined by the database. The strength can be categorized as Strong, Medium, Weak, or n/a (for non-coffee products). If ...

Having trouble getting the image to stack in the center above the text on mobile devices

When viewing the website on a desktop, everything appears correctly. However, there seems to be an issue with responsiveness on mobile and tablet devices. Specifically, I want to ensure that the image of team members stacks above their respective bio parag ...

Utilizing D3.js: Applying Multiple Classes with Functions

My current project involves using D3.js and I've encountered a particular challenge that has me stumped. In the CSV file I'm working with, there are columns labeled "Set" and "Year". My goal is to extract values from these columns and use them a ...

Angular routing is failing to redirect properly

After creating a sample Angular app, the goal is to be redirected to another page using the browser URL http://localhost:1800/demo. The index.html file looks like this: <!doctype html> <html lang="en"> <head> <title>Sample Ang ...

Responsive design not functioning properly for Bootstrap columns on website

If my display currently looks like this with three equally distanced images at the top and two images at the bottom, how can I achieve that design? I attempted using Bootstrap by setting the top 3 images as <div className="col-md-4"> and t ...

How to Navigate Downward with the Arrow Key in Python Selenium on a Mac Operating System

I am attempting to access a Drop-Down Menu on a website and choose a specific value. I am not sure how to click on an item within a Drop-Down Menu, so my idea was to instruct the WebDriver to use the Arrow-Down Key multiple times before pressing the ENTER/ ...

Is it possible to utilize CSS alone to change the color of a certain image to white against a black background?

I specialize in crafting dark theme versions of popular websites using CSS. One challenge I often face is dealing with images like the ones below: Websites typically use background-image to showcase these images. However, when I use filter: invert(1) to ...

Using require to access an Immediately Invoked Function Expression variable from another file in Node.js

File 1 - Monitor.js var MONITOR = (function () { // Code for Monitoring return { doThing: function() { doThing(); } }; })(); File 2 - Test.js var monitor = require('../public/js/monitor.js'); I am trying to access the doThing() funct ...

I'm having trouble getting the float left to work properly in my HTML/CSS code

Currently, I am diving into the world of HTML / CSS on my own. After following some tutorials, I have taken the leap to work on my very first project. My goal is to layout three images and three text elements on a single page using CSS. The desired struct ...

Ways to adjust the size or customize the appearance of a particular text in an option

I needed to adjust the font size of specific text within an option tag in my code snippet below. <select> <?php foreach($dataholder as $key=>$value): ?> <option value='<?php echo $value; ?>' ><?php echo ...

Fluctuate the window.location with jQuery or javascript

My goal is to create a functionality where clicking an image will toggle the window.location url between '#' and '#footer'. The current code I have for this is: <script> function clickarrow(){ var rd=Math.floor(Math.random() ...

Optimize the layout with Grid CSS to allow the last two items to dynamically occupy

I've been working on a layout that looks like this: X X X X X X X X A B Currently, I have used grid-template-columns: repeat(4, 1fr); to define the columns. However, what I actually want is for the last two items to take up the full width of the rem ...