Looking for assistance with positioning an image at the bottom left corner of a box DIV

I'm trying to add another image to the bottom right of this page with text on the left side. Currently, there's an image at the top left with text on the right side. Is there a way to vertically center the text with the image as well? I know it might look messy, but this is my first attempt at coding a website.

Below is the code snippet I've been working on:

<!DOCTYPE html>    
<html>   
<style>
   /* CSS Styling here */
    /* Some more styling... */
</style>
<body>
   /* HTML body content here */
    /* More HTML content... */
</body>
</html>

Answer №1

After making some adjustments to your code, I believe this is what you are looking to achieve. Check out the updated version here.

To accomplish this, you will need to assign a specific class to each image element.

img.img-1{
  float:left;
}
img.img-2{
  float:right;
}

You also have the option to define these styles inline if needed.

If you want to center both the image and the text, you can use the following CSS properties:

margin:0 auto;
/*for the img*/

and

text-align:center;
/*for text*/

Answer №2

Solving this issue is actually easier than you may imagine. To have multiple elements appear on the same line, it is best to utilize display: inline; or display: inline-block;. Usually, elements are set with display: block;, which creates a new line for each element. However, there are exceptions that can be surprising as not all elements behave this way. For instance, the <span> element does not impact styling unless specific attributes are added. But let's get back to addressing your question.

#im1 {
float: left;
display: inline;
margin: 0px;
}

#text1 {
float: right;
margin: 0px;
display: inline;
}

#im2 {
float: right;
margin: 0px;
display: inline;
}

#text2 {
float: left;
margin: 0px;
display: inline;
}
<!DOCTYPE html>
<html>
<head>
<!-- It is recommended to link external css files here or use <style> tags in the document. External files make management easier. Tutorials are available on w3schools-->

<title>title</title>
</head>
<body>

<img id="img1" width="25%" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png">

<span id="text1">Here is the accompanying text</span>
<br><br>
<img id="img2" width="25%" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png">
<span id="text2">Is this additional text?</span>


</body>
</html>

Setting the margin to 0 pixels is unnecessary since we've made them inline elements, but I like to include it just for clarity :). The margin controls the space around an element. Additionally, by floating the elements either left or right, they are pushed in that direction without impacting other elements. Float only has left and right options, and z-indexing can help manage overlapping elements (refer to w3schools for more information).

Remember, everyone starts as a beginner. Keep learning and exploring beyond websites - there's so much more waiting for you to discover!

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 noticed that my jquery code is injecting extra white space into my HTML5 video

Ensuring my HTML5 background video stays centred, full-screen, and aligned properly has been made possible with this jQuery snippet. $(document).ready(function() { var $win = $(window), $video = $('#full-video'), $videoWrapper = $video. ...

Using JSON strings in an HTML data attribute isn't functioning as expected

I am working with checkboxes that have a data attribute called data-route. However, when hovering over them and trying to alert the values, I only get one letter or symbol. Here is my code snippet: foreach ($this->coords as $index=>$val ...

Avoid refreshing the page and maintaining the most recent data inputted

On my HTML page, I am trying to implement a button that submits a form using a function. I have set up field validations, and when I click the submit button, it shows an error message but clears out the values I entered and refreshes the form. What I want ...

jumbled webpage design

I have created an HTML page with a specific layout in mind, but the output appears cluttered. I'm seeking help to identify the mistake. Here's a summary of the design I want: A main div element (container). A header div with a margin auto and ...

Positioning elements vertically and float them to the left side

I'm struggling to grasp the concept of the float attribute. Here's the code that is causing me confusion: #p1 { border: solid black 3px } <p id="p1" style="float:left">Paragraph 1</p> <a href="https://facebook.com" style="floa ...

What is the best way to align text in the center of a button?

When creating custom buttons in CSS using <button>, I noticed that the text appears to be centered both horizontally and vertically across all browsers without the need for padding, text-align, or other properties. Simply adjusting the width and heig ...

The process of transmitting messages back and forth between a popup script and a content script

I am in the process of developing a Chrome extension that involves sending data requests from a popup script to a content script (via a background script), analyzing the request on the content script, and then sending back a response (again through the bac ...

CSS not being applied properly in Devise(Rails) emails when sent to Gmail addresses

Upon a user signing up, I send a confirmation email using Devise's mailer view. While everything else appears to be functioning properly, the CSS for CONFIRM ACCOUNT doesn't seem to be applied at all. I've read that CSS classes cannot be use ...

Ways to include ".com" content statically in HTML on a website with a .org domain

I need to modify the content of a webpage in HTML. Example 1: Whenever I change the domain name to end with .com, the URL within my content automatically updates to www.example.com. Here is an example: dotCOM Example 2: Similarly, if the domain name en ...

Issue with JSON/Java not refreshing innerHTML when onClick event occurs

I'm having an issue with my JavaScript code: <script type="text/javascript"> $(document).ready(function() { $('#domaincheckbutton').click(function() { var finalMessage = document.getElementById('finalMessage'); ...

The appearance of the Bootstrap button is not displaying correctly

My current button looks like this: https://i.sstatic.net/PyP8v.png As seen in the image above, there is something strange at the back of the button. How can I resolve this issue? I am working on a small project using Django and Bootstrap. Thank you in a ...

Are there any illustrations of a Keygen available?

I have been searching for a practical example showcasing the utilization of the keygen element, but all I come across is just echoing back the public key. Is there an actual demonstration available? Perhaps something like real authentication? ...

Swapping out a character on a webpage using jQuery

Can someone help me remove the colon from this code snippet on my webpage? <h1><b>Headline:</b> something</h1> I'm looking for a simple solution using jQuery, as I am a beginner in JavaScript. Please include the complete code ...

Attempting to use jQuery AJAX to submit data without navigating away from the current webpage

Trying to implement the solution provided in this post where I am trying to send data to a PHP page and trigger an action, but unfortunately, it seems to just refresh the page without any visible outcome. Even after checking the network tab in the element ...

What is the best way to manage fonts in bootstrap-sass and compass? Are there any specific guidelines for properly integrating fonts into a webpage?

Within my Node.js application, I utilize bootstrap-sass in conjunction with Compass. Omitting the use of gulp-compass and related tasks, specifically relying on Compass itself, I have placed the Compass config.rb file in the root directory of my app. To co ...

The Bootstrap 5 navigation bar fails to expand properly on mobile devices

I am currently developing a website using Bootstrap 5, but I am facing an issue with the navbar. The problem occurs when viewing the website on mobile devices as the navbar does not expand properly. @import url('https://fonts.googleapis.com/css2?famil ...

Vanishing Submit Button with CSS

In my input submit button, I have included the following code: <input class="buttons" type="button" onclick="javascript:jQuery(xxxx)" style="font-size: 12px;" value="Invite to Bid"> Additionally, there is a CSS function that adds an elegant "Go" im ...

What is causing the gap to appear between the image and the div element underneath?

I recently encountered an issue where I set up an image to scale to full width, but it was always cut off at the bottom when it extended too high. Here is my current setup: div, img, body { margin: 0; padding: 0; } #image { width: 100%; he ...

Hovering over a class list will modify various element IDs

Is there a way to change the height of an element with id = "header_nav" when hovering over the class "header_nav" li element? Here is the HTML Code: <div class="header_nav" id="header_nav"> <ul id="header_nav_mainmenu"> & ...

Tips for invoking a JSP function from an HTML page

Is there a way to access a function written in a JSP file from an HTML page? I currently have a function set up that loads an image from the server on a JSP page. My goal now is to display this image on a separate HTML page by invoking the JSP function w ...