Position the text at the top edge of the image

Greetings,

I have the following images:

My goal is to achieve this look:

I have floated the flags to the right and set individual images to float left in my CSS style. However, I am struggling to add text-boxes on top of the images. Any tips or suggestions would be greatly appreciated.

#flagLine {
   float: right;
   padding-right: 50px;
   padding-left: 10px;
   padding-bottom: 10px;
}

#flagLine a img {

    float: left;
    position: relative;
    margin: 10px 10px 10px 10px;
    border-style: solid;
    border-color: black;
    border-width: 1px;

}

#flagLine h4 {
    vertical-align: top;
}

<div id="flagLine">
  <a href="https://internal.cs.ncl.ac.uk/modules/2013-14/csc1026/flags/letters/100_ICS_Alpha.svg.png"><img src="1.png" title='"I have a diver down; keep well clear at slow speed."' /></a><h4>A-Alpha</h4>
  <a href="https://internal.cs.ncl.ac.uk/modules/2013-14/csc1026/flags/letters/100_ICS_Bravo.svg.png"><img src="2.png" title='"I am taking in, or discharging, or carrying dangerous goods."'/></a><h4>B-Bravo</h4>
 <a href="https://internal.cs.ncl.ac.uk/modules/2013-14/csc1026/flags/letters/100_ICS_Charlie.svg.png"><img src="3.png" title='"Affirmative."' /></a>

Thank you in advance for any assistance provided.

Answer №1

Issue :

The current problem is caused by floating only the images to the left, resulting in an incorrect layout.

Resolution :

To solve this issue, you should enclose the images with their titles in a div and float that wrapping div to the left.
By doing so, your images and titles will remain aligned and floated together.

Demonstration FIDDLE

HTML:

<div class="wrap">
    <p>Flag Name</p>
    <img src="http://placekitten.com/g/200/200" />
</div>
<div class="wrap">
    <p>Flag Name</p>
    <img src="http://placekitten.com/g/200/200" />
</div>
...

CSS :

.wrap {
    float:left;
}
.wrap img {
    width:200px;
    height:200px;
}

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

Why are my video files exhibiting inconsistent behavior?

I've encountered an issue with the code on my website where I'm trying to display a 40-second video. The video converter I used seems to have added extra video types, which may be causing the problem. Here's what the HTML code looks like: ...

CSS Code Failing to Adjust Inner Components Width in Variable Table

I'm facing an issue while trying to create an excel-style table using HTML and CSS. The problem arises when I attempt to have a varying number of columns in different rows, as the table exceeds the border limit and expands on its own. My goal is to re ...

What is the best way to ensure a div stays inline with the main product box?

https://i.sstatic.net/KM3T2.png https://i.sstatic.net/tcUDg.png .product-row { margin: 0px 0px 0px 0px; } .product-box { display: flex; flex-direction: column; width: 300px; padding: 15px; margin: 0px 26px; position: relati ...

The CSS dropdown navigation bar designed for mobile devices functions properly, however, it is not visible on iPhones

After building this website from scratch using only HTML and CSS, I encountered an issue with the dropdown menu not appearing on iPhones. Despite testing it extensively across different browsers and devices, the problem persists on Apple products. While i ...

Tips for manipulating the DOM: Pushing existing elements when new ones are dynamically created with JavaScript

I have a pre-existing DOM element (let's say a div) and I am using JavaScript, specifically React, to create a new element - another div which serves as a sidebar. The goal is for the sidebar to seamlessly shift the previous element without overlappin ...

The alignment of text in the flex column is incorrect on the right side

The flex column I created is having an issue with the arrow on the right side. It's not displaying properly and is hidden. The arrow should be similar to the one on the left and point to the left direction. I have used left: 0; for the left side and ...

Challenging design with CSS shapes

Can this specific shape be created using just one HTML element? I am looking to use it for image cropping purposes, so having only one element would make the process easier ...

Custom property fallback values do not function properly with CSS Variables

I defined a custom property in the :root selector as shown below, but for some reason my color is not rendering correctly. Can someone please help me identify what I am doing wrong? :root { --color-primary: var(--color-primary, #ffc107); } body { ...

Is there a way to modify the way a screen-reading tool pronounces a specific word in a sentence without causing interruptions in the middle of the sentence?

Imagine I have the following sentence written in HTML: <p>Please input your licence number</p> An issue arises when a screen-reader pronounces the word 'licence' as "liss-ens" instead of "lice-ens." To resolve this, I aim to provide ...

Space allocation among the columns' borders

My layout consists of 3 columns in a row, each with the class col-xs-4, covering the entire row. I am trying to add a border to each column without them overlapping. Currently, I have applied the border but there is no spacing between the columns. I want ...

The content loses functionality once I add an overlay color to the background image div

I'm facing an issue with a div that has a background image, text, and a button in the center. Whenever I add an overlay color on top of the background image, the text and button seem to be disabled or unclickable. My goal is to ensure that the Read M ...

Several target elements on a single page

I am currently facing a problem with maintaining the active state of one anchor tag's target while clicking another button within the main identifier. Upon clicking the INTEL button, its opacity changes from 0 to 1. However, upon clicking Data Histor ...

Utilizing Flask to insert data into a MySQL database table

Hey there, I'm running into some trouble with inserting values into my database. While I can successfully log in using the same method on the sign-up page, I've tried various options without success. Below is my Python code: from flask import F ...

Arranging three buttons in a row with a larger button positioned on top

I'm struggling to implement my image button webpage. I can't seem to properly align three buttons at the bottom of the page. .fullwidth { width: 100%; height: 80%; margin-left: 0; margin-right: 0; ...

Downsampling and then upsampling images can result in mismatched image sizes

When trying to resize an image for faster processing, I encounter issues with mismatched dimensions due to rounding errors. What is the most effective way to address this problem? Forward pass original_size = (192, 192, 299) original_spacing = (3.645833 ...

CSS: The button appears to be slightly lower than the label

For more information, check out this GitHub link Here is the HTML code snippet: <div class="col-md-12"> <div class="col-md-2"> Processing </div> <div class="col-md-4"> <button class="btn btn-primary">Hello</ ...

Guide to Aligning col-md-3 to the Right Side in HTML Bootstrap 4

Is there a way to align one div on the right side, but within the same row? I am trying to place the value 172.21 on the right side of the row. Check out the screenshot here: https://i.sstatic.net/eg3K5.png Here is the HTML: <div class="row" ...

The horizontal overflow is malfunctioning, resulting in only a limited number of columns being visible on the screen

I am facing an issue with the CSS for my table. Despite using overflow-x: scroll, only half of the columns are being displayed on the screen out of the 15 total columns. Can anyone provide assistance with this problem? .table { font-family: Roboto,"He ...

CSS - Issues with transition smoothness on Safari

I am facing an issue with a simple font-size transition in Safari, causing stuttering while it works smoothly in Chrome and Firefox. I'm not sure if this is a Safari problem, a Webkit issue, or something else entirely. Any workaround suggestions would ...

Ways to position a container div below a menu through CSS

I'm having trouble getting the container div to display below the menu instead of alongside the header. Can someone help me fix this issue? Here is my HTML and CSS code: <!DOCTYPE html> <head> <meta charset="utf-8" /> <title>R ...