How can I align an image and text alongside another image using HTML and CSS?

Having some trouble positioning an Image and Text next to another Image. Check out an example here:

I attempted using floats, but it doesn't seem to be working. Here is the code I have:

.left {float: left;}
.right{float: right;}

<div class="left">
<img src="img/image1.png" />
<p>Text</p>
</div>

<div class="right">
<img src="img/image2.png" />
</div>

Answer №1

Are you looking for something like this?

<body>

<div id="Navigation">
  <img src="image"/>
  <h3>Text</h3>
</div>

<div id="Content">
  <h3>Main Content Section</h3>
</div>

body, html {
  width:100%;
  height:100%;
  margin:0;
  color:black;
}

#Navigation  {
  background-color:green;
  height:50%;
  width:20%;
  position:relative;
  top:50px;
  float:left;
}

#Content {
  height:50%;
  width:80%;
  background-color:red;
  position:relative;
  top:50px;
  float:right;
}

Answer №2

Here is a sample code snippet for a responsive webpage layout:

.container {
    width:100%;
    height:500px;
}

.left, .right{
    position:relative;
    height:100%;
    width:50%;
    float:left;
}

.img1{
    width:100%;
    height:50px;
}


<div class='container'>
    <div class="left">
        <img src="http://www.ancestry.com/wiki/images/archive/a/a9/20100708215937!Example.jpg" alt="img 1" class='img1'/>
        <p>Sample text here</p>
    </div>
    <div class="right">
        <img src="http://www.ancestry.com/wiki/images/archive/a/a9/20100708215937!Example.jpg" alt="img 1" />
    </div>
</div>

Click here to view the code in action

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

Tips for effectively interpreting a json string

Trying to extract specific fields from a JSON string and display them on an HTML page, but encountering the following error: SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data This is the JSON being sent: { "Order0& ...

Determining the file path in HTML5

Can anyone help me with retrieving the file path using html5 javascript once a user selects a file? I require the file path for a specific scenario: In this case, the user uploads a file and pauses it (currently only supported by Mozilla browsers), then c ...

How can I make two flexbox items in a row stack on top of each other as a column?

I'm currently working on a layout that involves a parent flexbox containing multiple sections. My challenge lies in getting two specific sections to stack vertically while the rest of the layout remains horizontal. At the moment, I have two sections ...

Moving a popup div along with a marker in Leaflet can be achieved by using the set

After creating a map using leaflet and adding markers to different locations, I implemented code that displays a popup div with a message when a marker is clicked. Here is the code snippet: markers.on("click", function(d) { div.html("This is Some info ...

Prevent individual elements from shifting around on browser resizing within a React form

Having issues with a React form that includes an image gallery and input fields. import React, { Component } from 'react'; import ImageGallery from 'react-image-gallery'; import { Container, Row, Col, InputGroup, Button, FormControl, ...

Concealing Website Elements with javascript based on class assignments

Despite my hesitation, I have to ask this question after unsuccessful searches in related articles. In my code, I have 7 nav links all with the same class. Due to the length of the HTML, I am looking for a way to hide contents until the link is clicked, an ...

embedding fashion within offspring component in vue

Looking to apply inline styles to a child component? I am trying to pass properties like height: 200px and overflow-y: scroll. I attempted passing it this way: <Childcomponent style="height: 200px; overflow-y: scroll;" /> but had no luck. ...

Trouble with Click event not working in Electron and mouse cursor not changing when hovering over an HTML button?

I'm in the midst of a project that involves using the electron framework. Within my project, I have an HTML file, a CSS file, and a Javascript file. The issue at hand is that when I hover over a button, the expected hand pointer icon fails to appear d ...

Utilizing the WebSocket readyState to showcase the connection status on the application header

I am currently in the process of developing a chat widget with svelte. I aim to indicate whether the websocket is connected or not by utilizing the websocket.readyState property, which has the following values: 0- Connecting, 1- Open, 2- Closing, 3- Close ...

What is the NOT selector used with the CSS contains function for?

I have a question regarding my Selenium code. I am currently using the following snippet: WaitForElement(By.CssSelector("#document-count:contains(<number greater than 0>)")); The part where I'm stuck is specifying number greater than 0. Is the ...

Manipulate elements by adding and removing classes sequentially based on an array

Previously, some had difficulty understanding my question. I have an array of variables representing the ids of 5 divs. My goal is to change the color of each div sequentially for a brief moment before reverting back, mimicking the behavior of traffic ligh ...

Larger icon graphics

Is it possible to increase the size of Glyphicons in Twitter Bootstrap 3.0 without using the btn-lg class? I found this code that makes glyphicons big: <button type="button" class="btn btn-default btn-lg"> <span class="glyphicon glyphicon-th- ...

Responsive navigation menus can create confusion when hover and click events overlap

Check out my HTML5 responsive, 2-level menu by clicking HERE. The menu displays submenus on hover for wide screens and on click for narrow screens (less than 768px). The JavaScript function responsible for switching the events is shown below: function ho ...

Tips for fading the text of list items when their checkbox is marked as done?

I am trying to figure out how to gray out a list item when its checkbox is checked. The code I currently have takes text input from a textbox and adds it to an unordered list when the add button is clicked. Each list item contains a checkbox within it. My ...

Combining two XPaths into a single XPath can be achieved by using various

HTML <li class="wdappchrome-ai" data-automation-id="searchInputAutoCompleteResult" tabindex="-2" aria-posinset="1" aria-setsize="3"> <span data-automation-id="searchInputAutoCompleteResultFullText"> <span style="font-weight:500"> ...

Basic jQuery Slideshow Counter

I'm having trouble implementing a text-based horizontal slider on my website that scrolls left and right with mouse control. I want to display the current index of each slide along with the total number of slides (e.g. 1/4) and update the index as use ...

Attempting to utilize jQuery for altering the background URL leads to the unexpected removal of the -webkit-background-clip:text; effect

Can the -webkit-background-clip:text; effect be preserved when using jQuery to switch the background url? I am experiencing issues where changing the URL removes the text clipping effect. jQuery(function($) { var whatToSwitch = $('.homepage_ove ...

Creating a new row with a dropdown list upon clicking a button

I want to include a Textbox and dropdown list in a new row every time I click a button. However, I seem to be having trouble with this process. Can someone assist me in solving this issue? Thank you in advance. HTML <table> <tr> ...

What is the process for extracting a numerical value from a text box and using it to update a database?

Trying to figure out how to add a numerical value entered into a text box to a value in a database table when the submit button is clicked. Let's say there's a table called customers in the database, with columns for name and balance. The goal i ...

Using jQuery to dynamically change the CSS color based on the background-color of a checkbox label

When a checkbox is selected, the function below runs to change the text color to white or black based on the darkness of the background color. However, the third checkbox should trigger this change to white but currently does not. function isDark(color) { ...