Why isn't the float left property working as expected?

Why won't my image float to the left? I'm using a class called align-left with float: left but it's not working.

You can see the live version at - (check out the review grid halfway down under the heading 'High customer satisfaction ratings').

Here is the code:

<section class="bluesection card__content__headings">
    <img alt="Reviews-6.png" class="align-left" data-entity-type="" data-entity-uuid="" height="395" src="/sites/default/files/2017-03/Reviews-6.png" width="400" />
    <h2 style="height: 400px;"></h2>
    <p></p>
</section>

The CSS:

.align-left {
    float: left;
}

.bluesection {
    background-color:#ecf0f2;
    padding: 50px 100px 50px 100px;
}

Answer №1

Check out this code snippet:

<section class="bluesection card__content__headings">
    <h2 class="heading--two inline-block__heading" style="margin: 0px 0px 20px; text-align:center;">High customer satisfaction ratings</h2>
    <img alt="Reviews-6.png" class="align-left" data-entity-type="" data-entity-uuid="" src="/sites/default/files/2017-03/Reviews-6.png" width="400" height="395">

    <p class="inline-block__copy">With our top-notch software, CRM expertise, and proven implementation best practices, we are your trusted partner in your CRM journey - empowering you to elevate your business and achieve sustainable success.</p>

    <p class="inline-block__copy">Don't just take our word for it. Over 268 satisfied customers have shared their reviews on G2 Crowd where Workbooks consistently outperforms Salesforce in terms of satisfaction and functionality.</p>

    <p class="inline-block__copy">The G2 Crowd Report compares Workbooks with its competitors based on unbiased user feedback. Workbooks excels over Salesforce in various categories.</p>
    <p style="clear:both;"></p>
</section>

You'll notice that I rearranged the elements within the section, added a p element with a clear:both style at the end, and made some CSS tweaks for enhanced visual appeal.

Answer №2

Instead of using float-left, try using float: left;. However, that's not the only issue at play here.

The image is currently floating to the left, but it may not be aligning as you expected due to the padding in the blue section.

Remember that the image's positioning is relative to the enclosing element. If you adjust the padding values to something like padding: 20px 50px 20px 50px;, you'll notice the image shifting further to the left because the padding has been decreased.

Answer №3

I have solved the problem.

The image was aligned to the left, and the issue with text not wrapping was caused by setting an inline height of 400px on the heading instead of the section.

Samantha

Answer №4

The element has already been floated to the left, but it cannot move any further due to reaching the edge of the containing div. Padding affects the boundaries of the child elements, yet still maintains a defined size unless overridden by larger values.

Here is a suggested solution: HTML

<section class="bluesection card__content__headings">
  <img alt="Reviews-6.png" class="align-left" data-entity-type="" data-entity-uuid="" height="395" src="/sites/default/files/2017-03/Reviews-6.png" width="400" />
  <div class="text">
    <h2></h2>
    <p></p>
  </div>
</section>

CSS

.bluesection {
  position: relative;
  width: 100%;
  display: flex;
}

.text {
  width: 100%;
}

For an example on how this works in jsfiddle, visit: https://jsfiddle.net/qf6w18p1/

Answer №5

After some investigation, I finally solved the issue.

The problem was that the image had been floated to the left, causing the text not to wrap properly. This was because a height of 400px had been set inline for the heading instead of the section.

While you can adjust the height to fix the layout, it may not look good on a phone device with dimensions of 360px x 640px. In this case, the section title h2 will appear below the img, resulting in a messy appearance.

My recommendation is to rearrange the order of the h2 and img tags to ensure better responsiveness.

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

Connecting your HTML file to a CSS stylesheet

I'm struggling to connect my "index.html" file with my "stylesheet.css" file. I've tried copying the code from resources like CodeAcademy and w3schools, but nothing seems to be working. I'm currently using Notepad++ as my text editor - could ...

Maintaining text color while adding a color overlay to a Bootstrap Jumbotron

After searching extensively, I couldn't find any mention of this particular issue. According to the Bootstrap 4.2 documentation on the Jumbotron, I constructed my div with an inline background image. However, when I attempted to apply an overlay on to ...

Tips on building an immersive interactive panoramic website

I have a vision for a website that will simulate being in a room, where users can explore the space with limited panoramic views - allowing them to look up/down 30 degrees and left/right 45 degrees. In addition, I would like to integrate interactive object ...

The function driver.find_element is unable to locate an element using the "class_name" attribute

My attempt at using driver.find_element, with the "class_name" method to locate and click on a button for expanding rooms on this website resulted in an error message: raise exception_class(message, screen, stacktrace) selenium.common.exceptions.N ...

The Jquery navigation and image display features are experiencing technical difficulties in Internet Explorer

My website is currently in the development stage and functions well on all browsers except for IE10. Interestingly, both the menu bar and photo gallery, which rely on Jquery, are not functioning properly in IE10. Below is the code snippet: <script ty ...

What is the best way to incorporate a unique font with special effects on a website?

Is there a way to achieve an Outer Glow effect for a non-standard font like Titillium on a website, even if not everyone has the font installed on their computer? I'm open to using Javascript (including jQuery) and CSS3 to achieve this effect. Any sug ...

Two challenges I encountered with my CSS dropdown menu bar

I've been working on a CSS top dropdown navigation bar, but I'm encountering two issues that I can't seem to resolve. The first problem is that my nav div either extends too far down or my 1px right border tabs aren't reaching the botto ...

Encountering an issue when attempting to store image links in the database using PDO

One idea that I have is to create an image uploader system that sends the image to the 'upload' folder and saves the link to the database. I encountered errors in my 'images.php' file. Can anyone assist me with resolving these issues? ...

Navigate to a specific section of a webpage with automatic scrolling

I'm developing a Chrome App and incorporating the web view tag, which functions similarly to an iframe. Is there a way to load a webpage inside the web view halfway down the page? I have attempted the following: application.js: $(document).ready(f ...

Is it Possible to Ajaxify a Forum Using a Bookmarklet?

My coding knowledge is limited to HTML. However, I am curious about the possibility of creating a bookmarklet that could ajaxify a forum, automatically refreshing and adding new posts to the page. Is such a thing possible? It's frustrating having to ...

Best practices for organizing fonts in SCSS 7-1 architecture?

My current project restructuring involves implementing the 7-1 architecture recommended by . As part of this process, I am incorporating flaticons into my project. I'm unsure of where to place the folder and scss file provided by flaticon within the ...

Modifying Margin and Spacing for Selections in Radio Buttons

I have successfully implemented the code for a radio button, and everything is working as expected div > label { margin-right: 80px !important; box-shadow: .3rem .3rem .6rem #c8d0e7, -.2rem -.2rem .5rem #FFFFFF; position: relative; ...

Incorporate text inside the border of a Material UI chip

https://i.stack.imgur.com/VATrD.png I'm looking to replicate this design using a pre-built Chip component from MaterialUI While the solution might involve Some Text using html and css, it still may not achieve an identical result. I've come acr ...

Achieving opacity solely on the background within a div class can be accomplished by utilizing CSS properties such

Whenever I adjust the opacity of my main-body div class, it results in all elements within also becoming transparent. Ideally, I would like only the gray background to have opacity. See below for the code snippet: <div class="main1"> content </di ...

Organize the structure of a JSON object in AngularJS to generate a hierarchical unordered list

Greetings! I am working with a RESTful API that returns a JSON object structured like this: { data: [ { id: 4, name: "Naranja", cant_portion: 2, portion_name: "Piezas", foodgroup_name: "Frutas" } ...

Can you tell me which specific font Adobe Edge Code (Brackets) uses in its code editor?

Can someone please help me? I'm trying to identify the syntax highlighter being used in this code. Is it Prettify or something else? ...

Are the dimensions of <TD> and <table> not displaying properly?

I've encountered a peculiar issue that I need help with. Here is the Fiddle link: http://jsfiddle.net/H3W4X/ If you want to view it in fullscreen: http://jsfiddle.net/H3W4X/embedded/result/ This is the code snippet causing trouble: <div id="wor ...

What is the process for assigning the value returned from an Angular HTTP request to ng-bind?

I am trying to retrieve a value from an HTTP request in AngularJS and set it as the result in a variable that is bound to ng-bind. The goal is for the value returned from the HTTP request to be displayed when text is typed into an input field. Below is th ...

transfer a product attribute value to a different product attribute within the Magento platform

There is an attribute called Weight : Attribute Code: weight Scope: general Catalog Input Type for Store Owner: Text Field Values Required: yes Apply To: Simple Product, Bundle Product Allow HTML Tags on Frontend: yes Also, there is a General Weight attr ...

dealing with a problem with the bootstrap navigation bar concept

I’ve been struggling to align the menu and company name in a single row. Initially, I tried setting the company name followed by some spaces before adding the menu items, but it didn't work out as expected. I've been spending the last couple of ...