Having some trouble getting the text to float alongside an image properly in HTML and CSS

I'm having trouble positioning my text next to an image. I've tried floating it to the right and even using a flexbox, but nothing seems to be working well. Here is the code I have...

    
    <div class="tab-content">
        <div class="tab-pane active" id="tab_default_1">
            <h2 class="text-dark-green">Kur Gin</h2>
            <p>
                <img class="img-responsive" style="height: 40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/KurGin.jpg" alt="" />
            </p>
            <p>
                Our gin, Kur (pronounced "cure") is made in the London Dry Gin style and is produced with Washington heirloom variety red winter wheat that emphasizes a backbone of classic juniper aromas and flavors with subtle citrus (Seville orange) as well as Douglas Fir and Braeburn apples from Mr. Liedholm's backyard.
            </p>
        </div>
        <div class="tab-pane" id="tab_default_2">
            <h2 class="text-dark-green">Stark Vatten</h2>
            <p>
                <img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/StarkVatten.jpg" alt="" />
            </p>
            <p>
                Our vodka, Stark Vatten (Swedish for “strong water”), is produced with Washington heirloom variety red winter wheat and pure, filtered water to create a clean, viscous, oily vodka that displays a definitive classic European style while remaining a distinctive local product.
            </p>
        </div>
        <div class="tab-pane" id="tab_default_3">
            <h2 class="text-dark-green">White Dog Bourbon</h2>
            <p>
                <img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/bourbon.jpg" alt="" />
            </p>
            <p>
                Duis autem vel eum iriure dolor in hendrerit in vulputate. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat.
            </p>
        </div>
    </div>
</div>

Answer №1

One way to create a vertical centered image and text layout is to use a wrapper with CSS flex properties. The wrapper should have align-items: center; to vertically align the content, and the paragraph (p) inside the wrapper should have the following styles.

.wrap {
display: flex;
align-items: center;
}
.wrap p {
flex:  1 0 100px;
padding-left: 20px;
}
<div class="tab-content">
                    <div class="tab-pane active" id="tab_default_1">
                        <h2 class="text-dark-green">Kur Gin</h2>
                        <div class="wrap">
                         <img class="img-responsive" style="height: 40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="http://placehold.it/200x600/fa0" alt="" />
                            <p>Our gin, Kur (pronounced "cure") is made in the London Dry Gin style and is produced with Washington heirloom variety red winter wheat that emphasizes a backbone of classic juniper aromas and flavors with subtle citrus (Seville orange) as well as Douglas Fir and Braeburn apples from Mr. Liedholm's back yard.</p>
                    </div>
                    <div class="tab-pane" id="tab_default_2">
                        <h2 class="text-dark-green">Stark Vatten</h2>
                        <div class="wrap">
                        <img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="http://placehold.it/200x600/fa0" alt="" />
                        <p>                        
                         Our vodka, Stark Vatten (Swedish for “strong water”), is produced with Washington heirloom variety red winter wheat and pure, filtered water to create a clean, viscous, oily vodka that displays a definitive classic European style while remaining a distinctive local product.</p>
                        </div>
                        </div>
                    </div>
                    <div class="tab-pane" id="tab_default_3">
                        <h2 class="text-dark-green">White Dog Bourbon</h2>
                        <div class="wrap">
                        <p>
                        <img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="http://placehold.it/200x600/fa0" alt=""  />
                        </p>
                        <p>
                            Duis autem vel eum iriure dolor in hendrerit in vulputate. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat
                        </p>
                    </div>
                </div>
            </div>
        </div>

Answer №2

To ensure proper alignment of your images with text, use the .pull-left class on the p wrapping the images. Additionally, apply the .clearfix class to the parent element to clear the float. Don't forget to add margin and padding to your text for proper alignment.

For demonstration purposes only, the .tab-pane css is included here to show hidden panes.

/* This is not essential - used for demo */
.tab-pane {
  display: block!important;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="tab-content">
  <div class="tab-pane active clearfix" id="tab_default_1">
    <h2 class="text-dark-green">Kur Gin</h2>
    <p class="pull-left">
      <img class="img-responsive" style="height: 40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/KurGin.jpg" alt="" />
    </p>
    <p>
      Kur Gin is a London Dry Gin style crafted with Washington heirloom variety red winter wheat, highlighting juniper, citrus, Douglas Fir, and Braeburn apples from Mr. Liedholm's orchard.
    </p>
  </div>
  <div class="tab-pane clearfix" id="tab_default_2">
    <h2 class="text-dark-green">Stark Vatten</h2>
    <p class="pull-left">
      <img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/StarkVatten.jpg" alt="" />
    </p>
    <p>
      Stark Vatten, meaning “strong water” in Swedish, is a vodka produced with Washington heirloom red winter wheat and pure filtered water, offering a clean and distinctive local product.
    </p>
  </div>
  <div class="tab-pane clearfix" id="tab_default_3">
    <h2 class="text-dark-green">White Dog Bourbon</h2>
    <p class="pull-left">
      <img class="img-responsive" style="height:40em; width:30em; margin-top:25px; box-shadow: 10px 10px 5px #888888;" src="app/what-we-make/images/bourbon.jpg" alt="" />
    </p>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam accumsan suscipit magna, vel mollis lectus aliquam nec. Sed euismod, dui et ultrices cursus, eros ligula suscipit dolor
    </p>
  </div>
</div>
</div>
</div>

Answer №3

To retrieve the content located to the right of the picture without relying on a table, simply incorporate

the "float:left" property within the image's inline style.

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

How can I validate HTML input elements within a DIV (a visible wizard step) situated within a FORM?

I recently made a decision to develop a wizard form using HTML 5 (specifically ASP.NET MVC). Below is the structure of my HTML form: @using (Html.BeginForm()) { <div class="wizard-step"> <input type="text" name="firstname" placeholder ...

Using regex for 'OR' conditions in regular expressions

I have been grappling with this issue for quite some time now. Can you offer any helpful hints or suggestions? When it comes to Outlook emails, we often see forwarded emails containing information within the email body like so: From: Jackson, Peter Sent: ...

The text becomes jumbled and messy when the browser is resized

I came across this fantastic header design > https://codepen.io/rm/pen/ldhon <. However, I noticed that when the window is resized, the text ends up overlapping. In the demo provided, resizing the window too much causes the issue to become apparent, ...

Mobile device accessing a video file twice in a row

Currently, I am in the process of developing my own DRM solution for video content. Each time an access is made to the actual video file, it goes through a verification process. For example, instead of streaming video.mp4 directly, it first passes through ...

Mobile Devices Image Gallery Optimization

Just starting out with HTML, CSS, Bootstrap, and JavaScript and I've put together this gallery. It looks good, but I need to optimize it for mobile devices and smaller screens. Any suggestions on what I should change? For items #myImg4, #myImg5, #myI ...

When a table has overflow set to auto, any content that exceeds its dimensions will

The issue at hand is explained in the fiddle provided. The problem arises when there is a scrollable table with a context menu inside it, and with the overflow-x: auto property set, the visibility of this "context menu" is hindered. table { overflo ...

Can we dynamically adjust font size based on the width of a div using CSS?

My div is set to 70% width and I have a specific goal in mind: To fill that div with text To adjust the font size so that it takes up the entire width of the div https://i.stack.imgur.com/goVuj.png Would it be possible to achieve this using only CSS? B ...

Integrating md-chips md-separator-keys with md-autocomplete: A step-by-step guide

My experience with using md-chips and md-autocomplete reveals an issue: when I incorporate md-separator-keys, it functions as expected. However, upon adding md-autocomplete, the md-separator-keys functionality ceases to work. This is how my code is struct ...

Uniform Column Height Functionality Exclusive to Desktop Devices

I have a snippet of code in my Bootstrap 5 website that looks like this <div class="row mt-3"> <div class="col-md-6 mt-3 mt-md-0"> <a href="post/good-morning-status-shayari-68346" class="h-100&q ...

Tips for customizing the border radius style of the menu in Vuetify's v-autocomplete component

I am looking to customize the appearance of the drop-down list in the v-autocomplete component by adding a border-radius style, as depicted in the image below. The current design I have achieved closely resembles the visual shown below. Previously, I app ...

Utilizing the ternary operator in Angular HTML templates

Using the ternary operator in HTML can simplify your code: <div> {{ showStringOneFlag ? 'Display String 1' : 'Display String 2' }} </div> This approach could save you from setting a string variable multiple times in JavaSc ...

Selecting specific elements based on their position within a parent element using

I can't seem to figure out the strange behavior of the nth-child selector. After calling the function BackColor1(), my visual appears different than expected: Something seems off. However, when I call BackColor2(), everything looks normal again. Co ...

The menu in IE7 seems to have a mind of its own, appearing and

Having trouble with my menu displaying correctly in IE7. It seems to be a stacking issue: the menu initially appears but disappears once the header image and rest of the page load. I've tried adjusting the z-index values in both the menu and its paren ...

What is the method for setting an image to stretch and fill the divided screen?

I'm having trouble getting my image to fill the screen correctly on a split screen. The top half of the screen has an image, while the bottom half has text. No matter what I do, there always seems to be a blank space either at the top of the image or ...

What is the best way to add 1 to a number every second with javascript?

My code seems to be functioning correctly, but I'm having trouble setting the delay and stopping the increment after a certain interval. Can someone please assist me with this? Javascript: $(document).ready(function() { var number = parseInt($(& ...

Resolving syntax error to enable dismissible device alerts

I am attempting to make my devise alerts dismissible. According to the bootstrap documentation found at this link, adding data-dismiss="alert" is necessary. However, when I try to implement this into my application layout as shown below, a syntax error oc ...

Ways to align text in a table row in a way that it remains positioned at the center of the screen's visible area

Can anyone assist me with this task? I need help centering text within a table row ('Some text here...') so that it always appears in the middle of the screen. The table will have horizontal scrolling. .compare-content { max-width: 480px; ...

Trouble with connecting CSS files

Can anyone explain why my CSS file isn't linking properly when the HTML file is located in a subfolder within the directory that contains both the CSS and HTML folders? I attempted to remove the main folder path from the link, but the issue still pers ...

Unlocking the Potential: Unveiling the Art of Activating Navigation in Single-Page Websites

I am currently developing a one-page website. In order to enhance the navigation experience, I want the active section or "page" to be visually highlighted in the navigation bar. At present, when I click on a link, it successfully displays with an underlin ...

Fixed-top navbar in Bootstrap obscuring webpage contents

I have tried various solutions to the issue at hand, but nothing seems to be working. I applied padding-top to the container of my main content, but when I add the following CSS: @media (max-width: 768px) { body{ padding: 0; } } it overrides the padd ...