Arranging an Image and text side by side

My goal is to have an image and text display inline with each other, side by side. I've been attempting to use display:inline;, but so far it's not working as expected. Here is the code snippet:

<div class="design-image" style="display:inline;">
      <img src="https://s29.postimg.org/taqtdfe7r/image1.png">
    </div>
    <div class="programs" style="display:inline;">
      <p>Taking the approach of truly designing programs from ground up, Northman Underwrites each individual to reflect the unique exposure of an extraordinary life. </p>
    </div>

Answer №1

Or, you can opt for a flexbox layout:

img {
  width: 300px;
  height: auto;
}

p {
margin:0;
}

.fb {
  display: flex;
}

.programs, .design-image {
padding: 1em;
}
<div class='fb'>
  <div class="design-image">
    <img src="https://s29.postimg.org/taqtdfe7r/image1.png">
  </div>
  <div class="programs">
    <p>Embracing the concept of creating programs from scratch, Northman Ensures each person is an individual representation of a remarkable life experience. </p>
  </div>
</div>

Answer №2

If you want to achieve a specific outcome, consider using the float property. This property alters how elements are positioned within the browser window. Take a look at this demonstration to see its impact:

div {
  display: inline;
}

#pic {
  float: left;
  /* set dimensions for visualization */
  width: 200px;
  height: 200px;
  background-color: red;
  margin-right: 50px;
}

#blah {
  float: left;
  width: 100px;
}
<div id="pic">
  Image content here
</div>
<div id="blah">
  <p>Brief description related to the image.</p>
</div>

Answer №3

Give this a try:

.design-image {
  float: left;
  width: 50%; /*/ Or any other value /*/
}

img {
  width: 100%;
}
<div class="design-image"">
      <img src="http://www.mrwallpaper.com/wallpapers/cute-bunny-1600x900.jpg">
</div>
<div class="programs">
      <p>Taking the approach of truly designing programs from ground up, Northman Underwrites each individual to reflect the unique exposure of an extraordinary life.</p>
</div>

Answer №4

If you're looking to achieve a specific layout, using float and setting widths for your div elements can help you accomplish this.

Check out the code snippet below for an example:

<div class="design-layout">
      <img src="https://example.com/image.jpg" style="width: 50%; float: left;">
      <p style="width: 50%; float: left;">Your text content here</p>
    </div>

Answer №5

Various CSS attributes can be used to align elements in different ways, and here are some examples:

To achieve your goal, you can utilize float, display inline-block, or table-cell (although less common). Another option is flexbox, which is not covered here but is worth exploring.

It's important to remember that "divs" are block elements, so using inline-block is usually a better choice over inline. Inline-block allows for vertical margin/padding properties (top, bottom) while still maintaining some of the characteristics of inline elements.

Check out the code on jsFiddle

<div class="method method-float">
<div class="design-image">
      <img src="https://s29.postimg.org/taqtdfe7r/image1.png">
    </div>
    <div class="programs">
      <p>Method float <br>Taking the approach of truly designing programs from ground up, Northman Underwrites each individual to reflect the unique exposure of an extraordinary life. </p>
    </div>
</div>


<div class="method method-inline-block">
<div class="design-image">
      <img src="https://s29.postimg.org/taqtdfe7r/image1.png">
    </div>
    <div class="programs">
      <p>Method inline-block <br>Taking the approach of truly designing programs from ground up, Northman Underwrites each individual to reflect the unique exposure of an extraordinary life. </p>
    </div>
</div>


<div class="method method-table-cell">
<div class="design-image">
      <img src="https://s29.postimg.org/taqtdfe7r/image1.png">
    </div>
    <div class="programs">
      <p>Method display table cell (not commonly used, but an interesting technique to know) <br>Taking the approach of truly designing programs from ground up, Northman Underwrites each individual to reflect the unique exposure of an extraordinary life. </p>
    </div>
</div>

CSS

img {
  width: 100%;
  height: auto;
}

.method-float {
  overflow: hidden;
}

.method-float .design-image {
  float: left;
  width: 50%;
}

.method-float .programs {
  float: left;
  width: 50%;
}

.method-inline-block {
  font-size: 0;
}

.method-inline-block .design-image {
  display: inline-block;
  width: 50%;
  vertical-align: top;

}

.method-inline-block .programs {
  display: inline-block;
  width: 50%;
  vertical-align: top;
  font-size: 16px;
}


.method-table-cell .design-image {
  display: table-cell;
  width: 1%;
  vertical-align: top;
}
.method-table-cell .programs {
  display: table-cell;
  width: 1%; 
  vertical-align: top;
}

Answer №6

When setting up your layout, be sure to include a div element before the img tag with a specified width and float right style. Here's an example:

<div>
            <p>Taking the approach of truly designing programs from the ground up, Northman Underwrites each individual
                to reflect the unique exposure of an extraordinary life.
            <div style="width:300px;float:right; padding:10px;"><img src="insert your image path"></div></p>
        </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

Changing the appearance of your website on various pages using WordPress: activating unique stylesheets

When connecting my stylesheets to my WordPress theme, I include the following in my customtheme/style.css file: @import url('bootstrap/bootstrap.min.css'); @import url('includes/styles1.css'); @import url('includes/styles2.css&ap ...

HTML elements are positioned in alignment

I'm currently working on a website and I need some assistance in aligning my images properly. Here's what I have tried: https://i.sstatic.net/suIVu.png However, I haven't been able to achieve the desired result with the following code: &l ...

Deleting a button from a list item or array in Angular 12

Having some trouble removing a list item with the click button, I've tried a few options but nothing seems to be working. Can anyone offer assistance? I need to remove a list item from my users array when clicked. Below is the Typescript code and cor ...

Guide to dynamically adding two CSS files in a single component in Angular 8

Within this component, there is a form that needs to support two languages, each with its own unique CSS style - one for left-to-right (ltr) direction, and the other for right-to-left (rtl) direction. Is there a way to conditionally apply two different CS ...

Maintain the markup created by jQuery inside the AJAX function called by setInterval

In the code snippet below, real-time markup is generated and automatically updates using the setInterval function. The markup includes buttons and hidden content within div elements. Each button reveals its corresponding div, but the div reverts to a hid ...

Basic image slider featuring adjustable heights

I'm currently working on a basic content slider, but I've encountered an issue where the container doesn't expand as new content slides in. It seems to be related to the absolute positioning of the content items. If I don't use absolute ...

Removing parent elements with JQuery

I have a piece of third-party HTML that I need to work with: <tr> <td> <asp:Label ID="lblURL" AssociatedControlID="txtURL" runat="server" EnableViewState="false" CssClass="FieldLabel" /> ...

HTML: arranged <pre> with fixed positioning

I currently have a centered column of text with a fixed width. However, I am looking to break that fixed width for certain tags like <pre> so that they can fill the full screen width while maintaining flow with the rest of the text. My CSS snippet s ...

What could be the reason for Firefox failing to display the border of a table when the tbody is

If Firefox isn't displaying table cell borders correctly in the presence of an empty tbody, a simple solution is to use the pseudo selector tbody:empty {display:none;} to hide the empty tbody element. This will ensure that everything is rendered as ex ...

Improving code quality and consistency in Javascript: Tips for writing better code

Hey, I've been experimenting with some code using ajax and have ended up with a lot of repetitive lines. Is there a way to streamline the code without losing functionality? I keep using the .done method multiple times when I could probably just use it ...

Why is Selectpicker failing to display JSON data with vue js?

After running $('.selectpicker').selectpicker('refresh'); in the console, I noticed that it is loading. Where exactly should I insert this code? This is my HTML code: <form action="" class="form-inline" onsubmit="return false;" me ...

Using only CSS to swap out periods in OL>LI elements for a different style

Is there a way to customize the punctuation used in lists in HTML and CSS? For instance, can the standard period at the end of list items be changed to a right parenthesis or removed altogether? Concept Below is an example of improper CSS attempting to a ...

What is the method to retrieve the selected value from a drop-down menu that is connected to JSON keys?

I am just starting to learn AngularJS and I need help with binding column names (keys from key-value pairs) to a select list. I want to be able to retrieve the key name when the selection in the select list is changed. The select list displays: name, snip ...

Can someone help me troubleshoot why the form for my Django LoginView is not showing up on my website?

After spending nearly an hour going through the documentation, I still can't figure out why the LoginView form is not displaying properly. The template seems to be rendering correctly but the form itself is missing from the HTML tags. urls.py from dj ...

Making modifications to index.html that is being hosted on GitHub Pages

Need to make a minor change to a website hosted on Github pages, specifically updating the title in the index.html file. Considering modifying and committing the change directly in the Github code editor for ease. Upon checking the repository's Sett ...

Insert HTML code into a specified location using a WordPress Plugin

How can I add a custom text to my WordPress website using a plugin in an HTML theme, and display it between the post and comments section? Is there a universal method for achieving this, regardless of the installed theme, so that I can effectively showcas ...

Finding a specific element on a web page can be accomplished by targeting its href attribute

I'm facing a simple task. I have a String with an href value, and my goal is to locate the web element on the webpage that includes that specific href. Here's what I'm trying: String href = "http://www.bing.com/images?FORM=Z9LH"; driver.fin ...

Tips for accessing content within the <main> element with selenium and Python

Currently, my coding environment consists of Python 2.7.12 and Selenium 3.0.2. I had a requirement to locate a tag within the <section> tag, and below is the code snippet I used: driver = webdriver.Chrome() driver.get("https://www.semanticscholar.o ...

Utilizing Angular to apply multiple ng-repeat directives with multiple filters

I am working on a project that involves multiple ng-repeat lists with several filters. Currently, I am using (ex:A.value) if (ex:B.value), but I would like to implement multiple filters. The filters I want to incorporate are recommend_search, skill_searc ...

Inline CSS alignment

While experimenting with layout inline elements, I came across some unusual behavior. Can someone please explain why there is a difference? I have applied the following CSS to both HTML structures: .time { position: relative; top:100px; heigh ...