Position the image before the unordered list item to align with the text

I'm looking to align the image and text horizontally using CSS.

Check out my code below:

<div class="latest-tweets">
  <ul>
    <li>
      <p class="tweet-text">This is tweet Text</p>
    </li>
  </ul>
</div>

See it in action here: https://jsfiddle.net/Lwhnunad/1/

Any assistance would be greatly appreciated.

Answer №1

Instead of using display: inline, opt for display: inline-block in your CSS code:

.latest-tweets ul li p,
.latest-tweets ul li:before {
  display: inline-block;
  vertical-align: top;
}

If you have an inline element followed by a block-level element, the latter will start on a new line. To keep them on the same line, make both elements inline-block.

.latest-tweets ul li:before {
  content: url("https://s27.postimg.org/419bicyab/home_tweeter_icon.jpg");
  display: inline-block;
  vertical-align: top;
}

.latest-tweets ul li {
  background: none;
  list-style:none;
}

.latest-tweets ul li p {
  display: inline-block;
  vertical-align: top;
  max-width: 85%;
}
<div class="latest-tweets">
  <ul>
    <li>
      <p class="tweet-text">This is tweet Text</p>
    </li>
  </ul>
</div>

Note: Apply a max-width to p so it remains contained when lots of text is added.

Answer №2

.tweet-feed ul li:before {
  content: url("https://s27.postimg.org/419bicyab/home_tweeter_icon.jpg");
  display: inline-block;
  float:left;
}

.tweet-feed ul li {
  background: none;
  list-style:none;
}
<div class="tweet-feed">
  <ul>
    <li>
      <p class="tweet-text">This is tweet Text</p>
    </li>
  </ul>
</div>

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

Concealed Text Entry

Hi, I am looking to create a simple input text field that functions like this example. <input type="text" id="pin" name="pin" maxlength="4" size="4" placeholder="____"> I would like the placeholder on the front end to stay visible until all charact ...

What is the best way to place division elements next to each other?

Is there a way to align the text "burger king" to the right of the logo on my webpage? I attempted using the bootstrap class pull-left, but it didn't produce any changes. This is how my page appears: body { font-size: 16px; background-color: # ...

Sass error: Unable to locate the stylesheet for import while trying to import bootstrap

I am currently working on integrating bootstrap into my project directory using npm. Below is an overview of my file structure: https://i.sstatic.net/HjExY.png Within my style.scss file, I am utilizing the @import feature to include Bootstrap as follows: ...

Dynamic change of table cell text color based on condition utilizing ng-if and ng-style

I am looking to create a table cell with alternating color combinations based on specific conditions. Here is the code snippet: <tr ng-repeat="x in data"> <td> <span ng-if="((x.time2 < x.time1) || (x.time2 < x.time3))" ng-style="colo ...

Switch out image with Jquery when hovering, and revert to default on mouse out

Despite the numerous times this question has been asked, I am struggling to find a solution that fits my specific case. Let's dive into it. My navigation setup involves using Bootstrap nav pills to navigate through content. The structure looks like t ...

What is the best way to ensure that a sidebar occupies the entire height of our webpage?

Here is the current layout of my sidebar: https://i.sstatic.net/c1sy6.png I want it to always occupy full height, how can I achieve this? I've tried using height: 100%, but it doesn't seem to work. Here is my CSS code: #sidebar { /* Make s ...

Determine the image's position in relation to its parent element while factoring in any vertical offset

Within my HTML, I have arranged two images to sit adjacent to one another. Interestingly, one image happens to be taller than the other. Despite assigning a CSS property of vertical-align: middle to both images, the result is that the shorter image appears ...

Is it possible to utilize a variable while assigning an element id through a JavaScript function?

Currently, I am in the process of learning JavaScript and have come across a scenario that has left me uncertain. I am attempting to utilize a variable in a particular situation and am unsure if it will work as expected. I am looking to assign a unique id ...

Seeing <br> elements being inserted into a <div> element in the page source

I have encountered an issue where my code does not contain any br tags between the beginning of the div tag and table tag, but when I view the source, several br elements appear. Below is the code snippet from a .php file: <div id='tx_addAccountp ...

Issues arise when attempting to use bootstrap in col-md-6 format on a tablet, as the

I attempted to have 2 columns appear side by side on tablets by using col-md-6 so that each column would only use 6 units. However, when switching from desktop to tablet size, the columns end up stacked vertically, with each column now using all 12 units ...

PHP: Bootstrap CSS for Carousels

I'm experiencing some difficulties with the Bootstrap CSS Carousel on my website. The left and right arrows seem to be unresponsive, and the slides are not transitioning automatically. I have been unable to identify the root cause of this issue. Belo ...

Is there a way to conceal/remove the text displayed on the submit button?

I am facing an issue with a submit button in my PHP code. The button displays an integer value that is crucial for running a script, but I want to hide the value as it interferes with the design using CSS. I have attempted various solutions like removing t ...

The code is not displaying correctly in Chrome, but it works fine when viewed on a live server

While developing a webpage in Vscode, I noticed that all my CSS and Bootstrap SASS styles render correctly. However, when opening the page without using Vscode live server, some of the styles are not being applied. ...

How to effectively use graph paper with both major and minor grids in the background?

Looking to create a 100px by 100px image in Inkscape with major lines every 100px and minor lines every 10px. This will help verify viewport size when used as a repeating background. What's the best approach for this? Thinking of using #888888 for ma ...

Facing a blank page with no errors displayed during the HTML rendering process in Angular version 6

One of the most frustrating aspects of working with Angular is the lack of information provided when there is a render error in an HTML page. Instead of specifying which page the error is in, Angular defaults to the route page and provides no further detai ...

How can I position an input element with the class "button" exactly where I need it on the webpage?

I am struggling to position my input (class="button") where I want it to be html: <div id="popup" class="overlay"> <div class="popup"> <a class="close" href="#">×</a> <div id="content"> <select required name="list" ...

Turn words into smiley faces without having to refresh the page

Recently, I came across an interesting feature on Facebook where text in messages is automatically converted into smiley faces without the need to reload the page. This got me thinking about how I could recreate this same functionality using jQuery and HTM ...

The image tag disrupting the spacing between lines

Here's a snippet of the css and html code: CSS: div { height:24px; line-height:24px; } HTML: <div><img src="image.png"/>Text</div> According to the code, a div should be 24 pixels high with text vertically centered after ...

Make SVG Path (Vector Graphic) Simplification easier

Provided Input: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="800pt" height="600pt" viewBox="0 0 800 600"> <g enable-backgrou ...

Upload file to database and move to new location

In order to gain a clearer understanding, I have a question regarding inserting data from a form. Let's say I have the following form: <form action="upload.php" method="post" enctype="multipart/form-data"> Select image to upload: <inp ...