Align an image with text using CSS and HTML

I'm having trouble with my CSS and HTML code. I want to align the text to the right of an image in a grid format, but it keeps appearing below the image instead. Here is the code snippet:

<html>
<head>

<style type="text/css">
#container { font-size: 12px; font-family: 'Lucida Grande',Verdana,sans-serif; text-align: center; }

#container a.name_link{
    text-decoration: none;
    color: #8E190B;
    font-weight: bold;
    padding-bottom: 8px;
}

#image { width:100px; height:104px; border: 2px solid #e9e3dd; float:left;}
#text {  padding-top: 5px; padding-bottom:5px; }  

.horizontal_banner {float:left; margin: 2px; padding: 4px 2px 10px 10px;  }

</style>
</head>

<body>

 <div class="horizontal_banner">
   <div id="container">
    <a href="details.php?id=42">
    <img src="uploads/Lisa.jpg" id="image" title="Lisa"/></a> </div>
    <div id="name_container">
    <a class="name_link" href="details.php?id=42">Lisa</a> </div>

    <div id="text">Not available</div>

     <div id="text">Not Specified</div>
    <div id="text">Female</div>

    </div>


    <div class="horizontal_banner">
    <div id="container">
    <a href="details.php?id=23">
    <img src="uploads/Lucky.jpg" id="image" title="Lucky" /></a>    </div>  
    <div id="name_container">
    <a class="name_link" href="details.php?id=23">Lucky</a> </div>

    <div id="text">Employed</div>

     <div id="text">25 Years</div>

    <div id="text">Male</div>

    </div>
    </body>
</html>

If anyone can assist me with this issue, I would greatly appreciate it.

Answer №1

In order to achieve this, it is crucial to set a specific width for .horizontal_banner. I found that setting it to 200x worked perfectly in the scenario you provided.

Answer №2

Is this what you had in mind? http://jsfiddle.net/CvZWG/

I made some changes to the CSS rules for .horizontal_banner so that they float left. Additionally, I noticed that you're using the same text id on multiple divs in your HTML. IDs should be unique, so consider using the class attribute instead of id if you want to apply it to multiple elements.

Answer №3

If the length of the text varies, there are several options available to you.

Upon reviewing your code, my suggestion would be to convert all the IDs into classes instead. Using multiple IDs with the same name can cause issues, which is the first problem to address.

The second issue involves floating the to the left as a block element, and specifying both height and width values. It's best practice to define the dimensions of any floated elements so that the browser can render them correctly. Also, remember to consider clearance for margins and padding, and perhaps incorporate some reset.css rules if you haven't done so already.

For the third issue, you may need to float those "text" divs to the right. Alternatively, you could explore using or tags, especially if all the data appears similar and belongs to the same class.

Best of luck with your implementation.

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

Is it possible to customize the Angular Kendo Grid to be non-scrollable and automatically adjust its height to fit the row contents?

I'm trying to create a Kendo Grid in Angular that is Non-Scrollable and adjusts its height to fit the row contents. However, my current implementation is not working as expected, as it still gives me a fixed height. <kendo-grid [data]="propertyVie ...

The HTML code on the page does not match the code I see when inspecting it

I need to extract the cost savings and frequency of interruptions information from the table on https://aws.amazon.com/ec2/spot/instance-advisor/ using Python. After inspecting the website using Chrome's 'Inspect' feature, I discovered that ...

What is the best way to allow a number to be editable when clicked on in a React application

Currently, I am trying to find a solution for making a number editable when clicked without having to use form inputs or other React libraries that don't fit my requirements. The provided screenshots showcase the desired interface. https://i.stack.im ...

ms-card malfunctioning due to data issues

I'm facing difficulties in transferring the data to the template. Although I can access the data in HTML using vm.maquinas and maquina, I am unable to pass it to the TEMPLATE through ng-model. Information about ms-cards was not abundant. Module ang ...

Creating a child div that is half the size of its parent

Is there a way for a child div to inherit half the width and half the height of its parent div without using specific values or viewport units? ...

Can someone please provide me with a Javascript code snippet that accomplishes the same function

<script> document.addEventListener('DOMContentLoaded', function () { const menuItems = document.querySelectorAll('.headmenu li'); menuItems.forEach(function (menuItem) { menuItem.addEventL ...

Changing Meteor Template to a Node.js/AngularJS Conversion

My current website is built with Meteor using templates structured like this: <body> {{>section1}} {{>section2}} {{>section3}} </body> <template name="section1"> <h1>This is Section 1</h1> </template> ...

vertically centering a div specifically on laptops

What is the best way to vertically center a div on lap-tops? (...) body {padding: 4% 16%;} body {top:0px; left:0px; bottom:0px; right:0px;} body {border: 12px solid darkred; border-style: double;} body {background-color: #FAFCB4;} p {font-size: 80%; text- ...

Exploring the utilization of attributes with slots in Vue.js

Can attributes be set on a slot so that the element from the parent inherits those attributes? Parent <vDropdown> <button slot="button">new button</button> <ul>content</ul> </vDropdown> Dropdown.vue <d ...

opinions on a product in angular from a user's perspective

user schema: var UserSchema = new Schema({ review_likes : [{type:String}], review_dislikes : [{type:String}] }); review schema: var ReviewSchema = new Schema({ productID:{type: String, required: true}, numoflikes:{type:Number, re ...

What prompts certain individuals to convert their asp.net pages into HTML pages before publishing?

Recently, I was informed that there is a possibility of working on a project involving ASP.NET 3.5 and C#. A colleague suggested that when we publish the site, we should convert all pages to HTML. This means instead of www.test.com/Page.aspx, it would be w ...

What is the trick to showing text underneath a font awesome icon?

My HTML code contains font awesome icons, and I'm looking to have text appear below each icon instead of next to it. Currently, the text is displayed midway to the right of each icon. <div class="icons"> <span class="fa-stack f ...

What is the best way to retrieve data from within HTML tags using PL/SQL?

Within my Oracle PL SQL project, I am dealing with an html file that contains the following comment tag. I need to figure out how to retrieve the value between these comment tags. <comment label="Comments">Text_to_Extract</comment>&l ...

Incorporating styling preferences within a directive's template

One of the directives I am currently working on looks like this: app.directive('MessageChild', function($timeout) { return { restrict: 'E', scope: { pos: '=?', msg: '=' ...

Steps for adding a row as the penultimate row in a table

There aren't many solutions out there that don't rely on jQuery, but I'm looking to avoid it. The row content needs to be generated dynamically. Here is my flawed approach: function addRow() { let newRow = '<tr><td>B ...

How can divs be styled to mimic the behavior of tables in IE6 using just CSS and HTML?

Can div elements be styled to resemble tables in IE 6 using just CSS and HTML? Unfortunately, the display properties like table, table-row, or table-cell do not work in IE 6 If it is feasible, what strategies can be employed? ...

Using JQuery Mobile to Incorporate Links into List Elements

Creating a mobile webpage tailored for college students involves assigning each student a unique id and an additional field. Both fields can be treated as strings, with the unique id being guaranteed to be unique, while the second field may or may not be u ...

Integrate CSS and Javascript Plugins into your Ruby on Rails application

I am utilizing an HTML, CSS, and JS template to design the interface for my Rails application. Within this template, there are several plug-ins that are required in both CSS and JS formats. I have stored these plug-ins within the "/assets/plugins/" directo ...

Arranging the rows and columns of a table in optimal alignment

I am currently facing an issue with two tables. The first table consists of 2 rows and 4 columns, with the first column spanning 2 rows. However, in the visual representation, the last 3 columns are misaligned with the rows. How can this alignment be corre ...

Ways to minimize the loading time of contents within the Dropdown

I am facing an issue with the loading time of my dropdown list. When trying to load 100,000 items on button click, it takes too long. Is there any way to reduce the loading time? Looping through Products for (int i = 0; i < 100000; i++) { ...