Ensure images are aligned horizontally with their captions positioned underneath

I need help with aligning two images horizontally with text below each image. This is the code I have so far:

HTML

<div class="selectGame">
  <div id="computerIcon" class = "icon">
    <img src="http://lorempixel.com" >
    <span class ="iconText"><p>VS Computer</p></span>
  </div>
  <div id="humanIcon" class = "icon">
    <img src="http://lorempixel.com" >
    <span class ="iconText"><p>VS Human</p></span>
  </div>
</div> 

CSS

.icon img{
  float: left;
  width: 40%;
}

.iconText p{
  clear: both;
}

Answer №1

Your approach was almost spot on! Just remember that when dealing with floating elements, it's important to also float the parent element, like in this example with div.icon

.icon {
    float: left;
}

Check out this JSFiddle Link for reference

Answer №2

Incorporate the float:left and width: 40% into the .icon class rather than applying it directly to the .icon img element - like this:

.icon {
  float: left;
  width: 40%;
}

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

I want to learn how to change the background image in React based on different components

Hey there! I've been learning and came across the Tomorrowland website. I really love the background scrolling effect on the homepage, where it changes depending on the component. I'm not sure how to code it myself and could really use some assis ...

connecting a JavaScript object literal to a specific address within an HTML document

I'm encountering an issue with creating an object that contains properties such as {"name":"John Doe","email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e08e818d85a0848f8d81889c8b848d8a">[email protected]</ ...

Need help displaying a file link from a server using the href attribute in a PHP echo statement?

Having some trouble creating a table with PHP. I managed to create the table, but I'm trying to link a file from an FTP server in a td tag. When I use href, it gives me an error. Can you please help me correct my code? echo "<a href = '../pub ...

Choose a Range of DOM Elements

My challenge is to select a range of DOM elements, starting from element until element. This can be done in jQuery like this: (Source) $('#id').nextUntil('#id2').andSelf().add('#id2') I want to achieve the same using JavaScr ...

Creating visually appealing transition effects like sliding in an autocomplete feature can enhance the user experience and

I have successfully implemented autocomplete functionality, but now I am looking to add a transition effect (slide down) to the suggested menu. After researching online, I found a helpful tutorial on this topic: Based on the information I gathered, I tri ...

Show Data on the Right-hand Side

Objective: Arrange the component names in two columns - left and right, with different objects like input textboxes based on a browser width of 981px. The desired layout is showcased in this link "https://jsfiddle.net/2w9kskr2/". Challenge: After impl ...

The text-center alignment in Bootstrap doesn't seem to be applying to buttons

After spending a considerable amount of time trying to center two buttons in Bootstrap, I came across the "text-center" class offered by Bootstrap. However, no matter where I include this class, it doesn't seem to have any effect on the alignment of t ...

The select menu default value is not displaying properly after the update to select2 version 4.0.3

After updating the select2 package from version v4.0.0 to v4.0.4, I noticed that the default value of the select menu was no longer appearing as expected: https://i.sstatic.net/UO3yZ.jpg For those interested, here is a link to my code on JSBin: view jsbi ...

Persistent hover effect for collapsible accordion panels when closing them

My simple accordion features a functionality where a class of .open is added to the title + content group when you open a panel for styling purposes. Everything works smoothly, but I've noticed on my phone that after clicking to close a panel, the hov ...

How to prevent mousewheel scrolling on an HTML page with the exception of a specific div using jQuery

Is there a way to prevent mousewheel scrolling on an HTML page while still allowing it on a specific element? I've tried using the code below: $('html').bind("mousewheel, touchmove", function(e) { e.stopPropagation(); return false; ...

Is there a way to make my siblings' elements turn black when hovering over an element?

Currently, I am working on CSS within Reactjs. In my project, I have two sibling elements: a logo and a text placed beside it. My goal is to have the text turn black when I hover over the logo, but so far, I have been unsuccessful in achieving this effect. ...

What is the proper way to include 'rowspan' specific CSS within an HTML table?

I have an HTML table with rowspans in it: table tr, td { border: 1px solid black; } tr:nth-child(1) { background-color: red; } tr:nth-child(2) { background-color: blue; } <table> <tr> <td rowspan=2>Section 1</td> ...

Utilize data retrieved from an API to customize the appearance of buttons through the combination of React and Sass styling techniques

I retrieved data from an API and used it to create a list of buttons. The data I received includes names and color codes. { name: "bob", colorCode: "#DC7472" }, { name: "ben", colorCode: "#69DCD1" }, { name: &q ...

Select DOM Elements Using JavaScript CSS Queries

As I delved into JavaScript in an attempt to craft my personal slider, I stumbled upon a perplexing discovery. I encountered a CSS regulation that looked like this: html.js #slideshow .slides img { position: absolute; } The explanation suggested that ...

Using Javascript to access a website from a Windows Store application

Currently, I am working on a project to create a Windows store app using HTML and JavaScript. One of the key components of my app involves logging into a specific website with a username and password. Here is an example website for reference: The process ...

What are some creative ways to customize and animate the cursor or caret within an input field?

Just to clarify, I am working with React and Material-UI. I have a task at hand where I need to modify the appearance of the caret within an input element by adding an animation to it. I have managed to change its color using caret-color and set a default ...

I am having issues with Tailwind CSS overriding the responsive padding on my website

I'm currently working on implementing responsive padding for a component. Given that Tailwind CSS follows a mobile-first approach, I have set the mobile padding to p-3, while screens at "md" and larger widths should use p-5. However, it seems like the ...

Using JavaFX to create a StackedAreaChart and implementing the setLowerBound method

I am encountering some issues with the Class StackedAreaChart and setLowerBound function. When I enable the autoRangingProperty to true, everything works fine. However, when I disable autoRanging and apply certain parameters, I encounter some bugs. imp ...

Implementing FAQs on ASP.NET MVC is my latest project

I have stored all the questions and answers in a SQL Server table, and it is fetching them perfectly. The FAQ user interface displays all the questions correctly from the table. You can see the interface in action by clicking on the following links: Questi ...

Is it appropriate to include JavaScript and CSS in views?

In my ASP.NET MVC project, I have set up a _Layout, a controller, and several views. Certain pieces of code are clearly global in nature, such as the CSS included in the _Layout file and other styles that are consistent throughout the site. However, when ...