What is the best way to ensure that the image appears directly below the text, rather than being obscured by the content of the

Hey there! I'm pretty new to StackOverflow and currently diving into fullstack web development. Just the other day, I embarked on creating my very own website, but now I find myself in a bit of a pickle. It seems that my image keeps appearing behind the next div's content instead of neatly positioning itself right below the text block. 😩 Could really use some guidance here, much appreciated for any help you can offer me! 🙏

Here's the code snippets:

<div class="wrapper">
    <div class="container">
        <div class="row">
            <div class="col-sm-8 text-container">
                <p>
                    <h1>laoreet ante eget, vehicula ligula.</h1><br />
                    sed odio eu, eleifend aliquet urna. Donec ultrices dapibus ipsum. 
                    Suspendisse ac hendrerit augue. Pellentesque massa eros, auctor ac sapien a, lacinia 
                    luctus dolor. Proin et eleifend quam. Mauris tristique dictum tellus vitae molestie.
                    Praesent auctor justo nisl, eu porta leo aliquam at.
                </p>
            </div>
            <div class="col-sm-4">
                <img src="images/picture.png" class="picture-container my-picture" alt="">
            </div>
        </div>
    </div>
</div>

CSS

.wrapper {
    width: 100%;
    height: 700px;
    background-color: #ed8d8d;
}

.container {
    height: 500px;
    padding: 80px 0px;
}

.text-container {
    width: 700px;
    height: 500px;
    float: left;
    margin-top: 80px;
    text-align: right;
}

.picture-container {
    overflow: hidden;
}

/* IMAGES */

.sophie-picture {
    height: 450px;
}

Answer №1

When looking at your HTML code, it seems like the "picture-container" class on the IMG element should be repositioned to sit within the "col-sm-4" div above.

It appears that the "my-picture" class on the IMG and the "sophie-picture" class in the CSS might actually be referring to the same thing. Perhaps one of them was renamed without updating the other file. If this is the case, make sure to align their names once again.

In the HTML snippet provided, there is a missing </div> tag at the end. However, this could be due to you only sharing part of your HTML document and not indicative of an actual error in your own version.

The issue causing the overlap between your image and text-container is most likely related to the use of float. Removing this property should resolve a significant portion of the problem.

Based on the classnames like col-sm-8, it appears that you are utilizing something similar to bootstrap for styling. Bootstrap includes various classes that handle layout design efficiently without requiring extensive custom CSS. It's recommended to either stick with using bootstrap classes for structure and styling or manually write your CSS without relying on bootstrap if you choose to do so.

Consider following one approach for each container:

  • Embrace the bootstrap methodology with container/row/col and utilize corresponding margin/color classes from bootstrap.
  • Alternatively, craft your CSS styles independently without integrating bootstrap classes.

Answer №2

rearrange the elements by moving the h1 tag above the p tag and apply a margin-bottom of 0 to the p tag. Additionally, since the picture-container has no defined height, applying overflow:hidden won't have any effect there. Instead, apply overflow:hidden to the wrapper element.

.wrapper {
  width: 100%;
  height: 700px;
  background-color: #ed8d8d;
  border:solid 2px red;
  overflow:hidden;
}

.container {
  height: 500px;
  padding: 80px 0px;
  border:solid 2px blue;
}

.text-container {
  width: 700px;
  height: 500px;
  float: left;
  margin-top: 80px;
  text-align: right;
  border:solid green 2px;
}

.picture-container {
  overflow: hidden;
}




p{
margin-bottom:0}

/* IMAGES */

.sophie-picture {
height: 450px
}
<div class="wrapper">

    <div class="container">
      <div class="row">
        <div class="col-sm-8 text-container">
          
            <h1>laoreet ante eget, vehicula ligula.</h1>
          <p>
            sed odio eu, eleifend aliquet urna. Donec ultrices dapibus ipsum. 
            Suspendisse ac hendrerit augue. Pellentesque massa eros, auctor ac sapien a, lacinia 
            luctus dolor. Proin et eleifend quam. Mauris tristique dictum tellus vitae molestie.
            Praesent
            auctor justo nisl, eu porta leo aliquam at.
          </p>
        </div>
        <div class="col-sm-4">
          <img src="https://via.placeholder.com/450" class="picture-container my-picture" alt="">
        </div>
      </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

Internet Explorer 9 (IE9) causing CSS dropdown menu to be truncated due

My issue is very similar to the problem described in this post: CSS Flyout menu gets cut off by borders of its container in IE9 The difference in my case is that I need to set the z-index (and position) on the container. You can view my JSFiddle here: h ...

Simply modifying a custom attribute source using jQuery does not result in it being refreshed

Introduction: Utilizing jQuery.elevateZoom-3.0.8 to display zoomed-in images. The SRC attribute contains the path to the smaller/normal image The DATA-ZOOM-IMAGE attribute holds the path to the larger image used for zooming. Here is the HTML Code: ...

Pattern matching to locate text that is not enclosed within HTML tags and does not fall within certain specified tags

I am attempting to create a regular expression that will match specific words located outside and between HTML tags (but not within the tags themselves). However, I also need to ensure that these words are excluded when they appear between heading tags suc ...

Leveraging HTML attributes in CMS source code

My website is built using Prestashop, and the content pages are created using: Prestashop > Preferences > CMS > Source-Code. For each CMS page, I utilize basic HTML in the source code. THE ISSUE I am attempting to add a widget to the site&apos ...

I'm facing an issue with grid-template-area not working properly, even though I've ensured that

My div elements are not aligning with the grid template areas specified in the CSS. When inspecting in Firefox, it shows as "zero one two three four", "five six ... etc." The classes mentioned apply to divs within the container div with a class of "spaces ...

What is the best approach to refreshing a particular div with the contents of a view file?

I have a block of code in PHP/Symfony that looks like this: <div id='content'> <?php include_partial( 'course/content.php', array("param1" => "1", "param2" => "2") ); ?> </div> Now, I am interested in updatin ...

Divide Footer Information into Two Sections: Left and Right

<footer> <div class="copyrights-left"> <p>&copy 2015. <a style="color: #fff;" href="index.html">Free Xbox Live Gold Membership and Free Xbox Live Gold Codes</a>. All rights reserved.</p></div> <div class="co ...

Evaluate numerical values using xsl:choose function

Using XSL version 1.0, I am populating an HTML table with percentage values from XML. My goal is to display the highlighted color of the percentages based on a condition, but the condition is not being processed as expected, leading to the exclusion of the ...

How can you use Dart to uncover the content within an H1 element on an HTML webpage?

I'm currently self-teaching mobile development with Dart and Flutter, and my current project involves connecting a mobile app to a website. I want to extract the text from an H1 tag that is loaded through JavaScript on the website and display it in th ...

Building a responsive CardMedia component with React Material UI

I am currently working on creating a gallery using React Material UI (utilizing Card, ...). I am facing some challenges in making the gallery responsive, especially with varying cover sizes: https://i.stack.imgur.com/2n6vf.png Here is the code snippet I ...

What is the best way to change a byte array into an image using JavaScript?

I need assistance converting a byte array to an image using Javascript for frontend display. I have saved an image into a MySQL database as a blob, and it was first converted to a byte array before storage. When retrieving all table values using a JSON ar ...

Comprehending the positioning of elements enclosed within a parent <div> tag

I'm struggling to understand why: vertical-align - isn't behaving as expected in this scenario, even though the elements are aligned along a baseline and are inline elements. I've experimented without using float but that didn't sol ...

HTML - PHP, navigating the history of the page with the browser's back button in real-time

My current project involves the development of a website using HTML and PHP. On one of my HTML pages, I have a form with certain fields marked as "REQUIRED". To ensure that all required fields are filled before submission, I have implemented a feature wher ...

Tips on utilizing the identical template in ngIf

I need to display different templates based on certain conditions. For example: <template [ngIf]="item.url.indexOf('http') == -1"> <a class="ripple-effect" [routerLink]="[item.url]" *ngIf="isUserLoggedIn == true" > ...

Retrieve the value of the textarea only if it exceeds 15 characters

Could you please explain why in this example: <div id="comment-form"> <h3>Comment on this story:</h3> <form method="post" id="story-comment-form" action="#"> <textarea name="comment" id="story-comment-text"></textarea& ...

What is the best way to design an element that exceeds the size of my physical body

I am currently working on creating a table that needs to be larger than the body and centered. Let me provide some more information. Below is my simplified HTML code : <body> <div id="one"> <div> <tab ...

Having trouble with the CSS :hover tag? Try changing the display property from none to inline-block

I'm currently working on a website navigation menu... I've decided to utilize the :hover feature in CSS to switch the display property from none to inline-block. In the past, I have implemented this with no issues whatsoever. However, I am now e ...

jQuery animation that smoothly fades out from the left and fades in from the right

This survey is designed to assist individuals in determining where they should go with a specific type of ticket. Currently, everything is functioning smoothly, but I would like to add a sleek animation to each ul transition. Whenever a button is clicked ...

Using regular expressions to search for HTML tags in PHP may result in empty tags being overlooked

I have a question about using regular expressions to remove hidden tags along with the ending tag. It appears to be working, but there is one issue I am facing. After removing the elements, it leaves behind "<>" for all the found elements. Here is t ...

What could be causing the uneven application of CSS padding when it is applied to a div that serves as the parent of an HTML form?

Padding has been added only to the top and bottom of a div. The padding attribute is displaying consistently for the form element, however, it is not behaving uniformly for the parent div of the form as illustrated in the image provided below. Output:- h ...