What is the best way to align these text elements beside the images?

I am in need of the following:

======
=img1=  Description
======

======
=img2=  Additional Info
======

Existing HTML setup:

<div id="division-id">
    <a href="[href]"><img src="images/img1.png"></a>
    <p>Description</p>
    <a href="[href]"><img src="images/img2.png"></a>
    <p>Additional info</p>
</div>

After applying this CSS rule:

#division-id p {
    display: in-line
}

The output appears like this:

======      ======
=img1= Text =img2= Some more Text
======      ======

Understanding why this happens and finding a suitable solution is crucial. What could be causing this issue and how can it be rectified?

Answer №1

If you want to make changes to the HTML structure, consider enclosing the <p> and <img /> elements within a new <div> container like this:

#division-id p {
  display: inline;
}
<div id="division-id">
  <div>
    <a href="[href]"><img src="images/img1.png"></a>
    <p>Text</p>
  </div>
  <div>
    <a href="[href]"><img src="images/img2.png"></a>
    <p>Some more text</p>
  </div>
</div>

Additionally, please note that there are two errors in the code provided:

  1. The correct CSS property is not display: in-line.
  2. The selector used is incorrect.

Answer №2

Here's a helpful tip for you:

To create line breaks after each paragraph tag, simply add a <br> tag. For example:


<div id="division-id">
  <a href="[href]"><img src="images/img1.png"</a>
  <p>Text goes here</p><br/>
  <a href="[href]"><img src="images/img2.png"</a>
  <p>More text goes here</p><br/>
</div>

CSS:

#division-id p{ display:inline; vertical-align:top}

Answer №3

Give this a try

I made an adjustment by enclosing each image and text with <div class='item'>

<div id="division-id">
    <div class='item'>
        <a href="[href]">
            <img src="images/img1.png">
        </a>
        <p>Text</p>
    </div>
    <div class='item'>
        <a href="[href]">
            <img src="images/img2.png">
        </a>
        <p>Some more text</p>
    </div>
</div>

<style>
    #division-id p {
        display: inline
    }
</style>

Hopefully, this solution is helpful to you

Answer №4

Using lis instead of divs and brs is my preference because it eliminates the need for additional styling.

ul {
  list-style: none;
  margin: 0;
}

ul li a {
  display: inline-block;
  float: left;
  margin-right: 10px;
}
<ul id="division-id">
  <li>
    <a href="[href]"><img src="images/img1.png"></a>
    <p>Text</p>
  </li>
  <li>
    <a href="[href]"><img src="images/img2.png"></a>
    <p>Some more text</p>
  </li>
</ul>

Answer №5

.section-class p:after
{
    content: '';
    display: block;
    clear: both;
}

Answer №6

If you're looking for an alternative approach, consider the following suggestion. I advise against using float:left as it may restrict your styling options in terms of height and width.

<style type="text/css">
.division_id div, .division_id>div>p{
    display:inline-block;
}
.division_id>div>a{
    vertical-align:middle;
}
</style>
<html>
<div class="division_id">
    <div>
        <a href="[href]"><img src="images/img1.png"></a>
        <p>Text</p>
    </div>
    <div>
        <a href="[href]"><img src="images/img2.png"></a>
        <p>Some more text</p>
    </div>
</div>
</html>

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

Keep one row in a grid with five columns in Bootstrap

After trying out the code snippet from this Stack Overflow thread, I noticed that when I expand the screen to full size, column 5 moves to the next line on xs resizing. Is there a method to keep all columns in a single row even when the screen is resized ...

The proper way to showcase an apostrophe in HTML when dealing with a viewmodel's string property

My asp.net view has a minor issue where it displays the client's name at the top of each page using a layout template. Everything works smoothly except for when the name contains an apostrophe. Instead of displaying the actual apostrophe, the view sho ...

I'm having some trouble getting my HTML menu within the header tag to hover correctly in Angular. Can someone please provide

https://i.sstatic.net/SK6Dw.png My Angular application's CSS is causing the menu to not hover over all controls in the component. CSS nav { background-color: #4D678D; } nav ul { padding: 0; mar ...

Hosting services and content management system for a website built with Twitter Bootstrap

Embarking on a new venture to create a website for a Custom Home Building company, I am eager to learn and grow in web development. Although I have some programming experience, please bear with me as I ask my newbie questions. I have been searching high a ...

Eliminating the muted attribute does not result in the sound being restored

I am looking to implement a feature where a video loads automatically without sound, but when a user clicks a button labeled "Watch with Sound", the video restarts from the beginning and plays with sound. Below is the JavaScript code: let videoButton = do ...

Examining the code - I'm having trouble locating the origin of its creation

My question might seem trivial and I could figure it out on my own, but for some reason, it's just too difficult for me. I can easily find details like the width and height of a div, the background color, and the font used. However, what I can't ...

"Master the art of creating a curved circular arrow using a combination of HTML, SVG, D3.js

I am looking to design an SVG circle with a fading stroke that blends into the background and features an arrow at one end. The goal is for the ring to fade out completely right above the arrow, similar to the visual reference provided in the image.view ex ...

What is the best way to stop a page from reloading when a hyperlink is clicked, instead redirecting to the new page while ensuring the code on that page functions correctly?

Without trying to confuse you, let me explain the situation. I have the following HTML code: /*For example purposes, here is a hyperlink that may appear on a webpage with different question ids*/ <a delhref="http://localhost/eprime/entprm/web/control/m ...

What is the best way to emphasize this specific section of text?

Looking for help with my tumblr template. I have the following block of code: {block:IfNotEndlessScroll}{block:Pagination}{block:PreviousPage}Previous Page{/block:PreviousPage} {block:NextPage}Next Page{/block:NextPage}{/block:Pagination}{/block:IfN ...

Checkbox and Ionic avatar image combined in a single line

I am currently working on a mobile app using the ionic framework. I would like to create a layout with an avatar image on the left, text in the middle, and a checkbox on the right. Can anyone provide guidance on how to achieve this? The code snippet below ...

Modify the class of the <select> element when it has been clicked or altered using JavaScript or jQuery

There is a select element styled as a dropdown list using bootstrap-select. I am interested in adding a specific class with CSS when the select is clicked or changed. https://i.sstatic.net/fbdK4.png <select required class="form-control selectpicker" ...

What is the best way to figure out the resolution of a computer screen using javascript?

It came to my attention that the <canvas> element can be adjusted to have varying scales. For example, if I specify the CSS width and height as 100px but use JavaScript to set them to 200px, the element will shrink so that everything drawn on it appe ...

Responsive design issues with Bootstrap Popover

Whenever I open the popover for the first time, the image is not displayed correctly. How can I ensure that it always shows correctly? Here is a link to the issue: https://jsfiddle.net/n2Lfro30/1/ Below is the button code causing the problem: <button ...

Control the HTML button's state according to the information received from the server

I am currently working with datatable Jquery and using an ajax call to retrieve data from the server. Let's assume that the database consists of three attributes: "Attribute1, Attribute2, Status". Depending on the Status attribute, I need to enable or ...

My draggable item seems stuck in place. Any ideas on how to get it moving again?

I have been trying to implement some code I found on this link. Despite adding all the necessary file links, the code is not functioning as expected. It should be able to move within the bounds of a container, but it's not working properly. var max ...

Is it better to define the SVG `viewbox` once in a `symbol`, or each time an SVG is `used`?

Based on my research, some tutorials suggest that when inserting an SVG <symbol> with <use>, the viewBox property only needs to be defined once - in the <symbol> tag. While this method seems to work fine, it results in the contents of th ...

After clicking, I would like the text from the list item to have a style of "background-color: aqua" when displayed in the textarea

Is there a way to apply a highlight with a style of "background-color: aqua" in the textarea only to the word selected from the list above after clicking on it? See below for my HTML: <head> <script src="https://ajax.googleapis.com/ajax/libs/ ...

"Seeking assistance with concept sharing and content transmission. In need of guidance

Basic Question I'm stuck trying to brainstorm a concept to reach my objective. I am having trouble figuring out how to navigate the DOM correctly with my chosen method. The Objective First, let me explain what I am doing: I use ajax to bring HTML ...

The Django tag `{% block content %}` seems to be malfunctioning

I have recently embarked on my journey to learn Django and I am beginning to grasp the basics of tag blocks. However, I encountered an issue when trying to implement them on my pages named index.html and question.html. In my index.html file, I structured ...

The placeholder in the text input field is missing

I'm new to this, and struggling to figure out why the placeholder isn't working. I attempted using the LABEL tag but it stays visible as I type into the text input. I am hosting the HTML on heroku. Here's the code snippet: <!-- <label ...