What could be causing the CSS float left and right to not function as expected?

I've been trying to get my image to float to the left of my text, but using the float property doesn't seem to be working. I want the image to align to the right of the text within a div. This is the code I currently have:

<div class="say-hello">
            <img src="images/say-hello.jpg" alt="Person placing macarons on top of cake">
            <div class="say-hello-text">
                <h2>Say Hello</h2>
                <p>In the mood for something sweet? We'd love to make your next event special with something Positively Delicious. Whether you're looking for a classic birthday cake or a unique cupcake assortment, we've got you covered.</p>
                <div class="say-hello-button">
                    <a class="button" href="#">Contact us</a>
                </div>
            </div>
        </div>
.say-hello {
    width: 80%;
    max-width: 100%;
    height: 100%;
    padding: 30px;
    margin: auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    border-radius: 8px;
  }
  .say-hello img {
    object-fit: cover;
    width: 50%;
    border: none;
    float: right;
    padding: none;
    margin-left: 0;
    margin-right: 0;
  }
  .say-hello-text {
    text-align: center;
    align-self: center;
    width: 40%;
    padding-right: 4%;
    float: left;
  }

Answer №1

If you're facing issues with the float property in a flex container, it's likely due to using "display:flex" on the parent div (with the class .say-hello). To resolve this, simply remove the display flex property and your floating elements should work as expected:

.say-hello {
    width: 80%;
    max-width: 100%;
    height: 100%;
    padding: 30px;
    margin: auto;
    /*display: flex;*/
    flex-wrap: wrap;
    justify-content: space-between;
    border-radius: 8px;
  }
  .say-hello img {
    object-fit: cover;
    width: 50%;
    border: none;
    float: right;
    padding: none;
    margin-left: 0;
    margin-right: 0;
  }
  .say-hello-text {
    text-align: center;
    align-self: center;
    width: 40%;
    padding-right: 4%;
    float: left;
  }
<div class="say-hello">
            <img src="https://assets.codepen.io/t-1/user-default-avatar.jpg?format=auto&version=0&width=80&height=80" alt="Person placing macarons on top of cake">
            <div class="say-hello-text">
                <h2>Say Hello</h2>
                <p>In the mood for something sweet? We'd love to make your next event special with something Positively Delicious. Whether you're looking for a classic birthday cake or a unique cupcake assortment, we've got you covered.</p>
                <div class="say-hello-button">
                    <a class="button" href="#">Contact us</a>
                </div>
            </div>
        </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

strange glitch found in jquery ui resizable

Experimenting with jquery UI, I came across an unusual bug. After clicking a button to make a div resizable, the div unexpectedly moves below the button. resizable.html: <html> <head> <link href="my.css" rel="stylesheet" type=" ...

Utilizing bootstrap and CSS styling to implement page-level masking for buttons

I struggle with css, but I have a specific design in mind and have attempted to implement it. <div> <div id="propertiesTable" style="padding: 20px 20px 20px 20px;" ng-cloak > <table class="table table-striped table-bordered"> ...

javascript add items to a container

I created a looping animation that features dynamic words, but I'm struggling to append all the spans into the <div id"wordcloud"></div>. Any assistance with this would be greatly appreciated. var interval = 100; var width = 800; var he ...

Despite having the <script> placed after the <div>, I continue to encounter a "TypeError: Cannot read properties of null (reading 'style')" error

I am encountering an issue with the code below. The <script> is positioned after the corresponding <div> in the HTML file, both residing within the <body> tags, however, the browser continues to display an error. <div id="containe ...

Having trouble with the alignment of the Bootstrap CSS grid

Recently started using Bootstrap version 5-2-0 I'm trying to create a layout where an image of a cat takes up one side, with content and a form on the other side (content above the form), but I'm having trouble getting it to display correctly. & ...

Expand the accordion and incorporate both a hyperlink and an anchor tag within the content

My go-to source for codes is usually https://www.w3schools.com. They also provide an accordion feature along with the code; However, I've encountered an issue where when a link is used -> to The accordion doesn't open but remains closed. Does ...

Submit data in the manner of a curl request

Instead of using a curl command to push a file to a web server, I am attempting to create a simple webpage where I can select the file and submit it. Here is the HTML and JavaScript code I have written for this purpose: <html> <body> <i ...

"Utilizing node.js to create a custom regular expression for removing anchor tags

Can someone provide me with a regex pattern that can eliminate all the a tags from HTML and display the URL as plain text? For instance, take this text: abc <a href="http://a.com" target="_blank">bbb</a> ccccccc After applying the regex patt ...

Ways to access dropdown menu without causing header to move using jQuery

Greetings everyone, I am currently working on a dropdown language selection feature for my website. The issue I am facing is that when I click on the language dropdown in the header, it causes the height of the header to shift. $('.language- ...

Tips for preventing a span from disappearing when a hidden div is displayed during onmouseover

, there is a concern about the disappearing behavior of the span with ID "topnavbar" when the display property changes from none to block on a hidden div using onmouseover event. The query is how to ensure that the span remains visible at all times. Additi ...

Unexpected behavior with CSS background-image transitions effects

Currently, I am experimenting with a hover swipe effect using div and background image. The background image utilizes the outer div's max-width and an inner div with a padding-bottom percentage to maintain the aspect ratio. However, there are several ...

How can I design a side navigation menu using Bootstrap?

I've come across various tutorials online on how to create a side collapsible menu, but they all involve a lot of code. I just need to toggle the visibility of a specific div within this structure: <div class="row"> <div class="col-md-2" ...

I'm curious about why I'm receiving the error "Unable to bind to 'ngFor' since it is not recognized as a property of 'li'. Can someone please explain why this is happening?

The issue is related to the *ngFor directive for nonvegfoodlist app.component.ts import { Component } from '@angular/core'; export class Menu { id : number; name :string; } const veg : Menu[] = [ { id:1 , name:'Rice'}, { id: ...

Show a virtual numeric keypad on the HTML input fields when they are set as type text specifically for mobile devices in a unique situation

When accessing the following web page from a mobile device, I currently have number input fields with comma separators added. However, in order to implement the comma separation function, I had to set the input type to text. This resulted in showing an alp ...

Incorporate a font-awesome icon directly within the input field

My div element contains a span element, which in turn includes an i tag. However, the i element extends outside of both the span and div elements. I am attempting to place an eye icon inside an input field. Here is my current code - what adjustments shou ...

Tips for shifting the cursor slightly to the right within an Input field

I created a div with an input field inside. I set the input field to autofocus, so when the page loads, the cursor is automatically focused on the input field. However, the cursor is touching the border of the input field, making it hard to see clearly. ...

Create a dynamic image positioned alongside text specifically designed for mobile devices

One of my challenges involves implementing a responsive image in Bootstrap (3.3.7): <div class="col-sm-2 text-center"> <img class="img-responsive center-block " src="img/1.png" style="max-width: <p>I would like to include some gua ...

I am looking to pair a unique audio clip with each picture in my collection

I have implemented a random slideshow feature that cycles through numerous images. I am now looking to incorporate a brief audio clip with each image, synchronized with the array I have established for the random pictures. The code snippet below is a simil ...

Tips for incorporating a zoom feature into a bootstrap carousel

I've been attempting to incorporate a zoom effect into a bootstrap carousel, but for some reason, I can't seem to get it to work :( I suspect that I may need to insert the syntax into the core _carousel.scss file (or maybe not?). Despite my atte ...

What is the best way to reset a CSS background GIF after hovering over it?

Is there a way to create a texture animation with text using CSS background GIFs that reload when hovered again? I've tried some JavaScript/jQuery but can't seem to make it work. Any suggestions? I attempted the following approach, but it's ...