Div with responsive design trims image

I'm currently working on crafting a div with text and rounded corners, where the right side features an image also with rounded corners. Since this content will eventually be tied to a CMS, it may change in the future. That's why I need the div to adapt responsively: adjust its height based on the text content and trim the excess part of the image without sacrificing the rounded corner or resizing the image.

Below is the code snippet that I've included, and I am really hoping for some assistance!

.spacing {
  padding: 15px;
}

.banners {
  display: block;
}

.banner_home {
  min-height: 100px;
  box-shadow: 5px 5px 10px #888;
  margin-top: 20px;
  padding: 0px;
  border-radius: 15px;
  display: block;
}

.banner_home_text {
  float: left;
  overflow: hidden;
}

.banner_home_text p {
  margin: 15px;
}

.banner_home .banner_home_text img {
  float: right;
  padding: 0px;
  border-radius: 0px 15px 15px 0px;
  margin-left: 10px;
  display: block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="banners">
  <div class="spacing">
    <div class="banner_home col-xs-12">
      <div class="banner_home_text">

        <img src="http://placehold.it/375x375" alt="Barbecue">

        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac lorem eget tellus volutpat pellentesque ut eu libero. Proin et dui ut nibh laoreet varius. Praesent nec dignissim ex. Mauris pharetra convallis lacus, a rhoncus urna porttitor id. Morbi
          vel tellus id quam condimentum egestas. Phasellus elementum molestie lacus. Donec aliquam congue mollis. Sed pellentesque orci tellus, sed fringilla turpis ullamcorper dapibus.
        </p>

        <p>
          Duis commodo egestas lacus quis commodo. Duis semper dapibus mi, posuere dictum libero fermentum sed. Etiam ligula eros, ornare nec mattis at, rhoncus vel ante. Vestibulum eget finibus nisl. Nam ullamcorper scelerisque sem non sagittis. Pellentesque habitant
          morbi tristique senectus et netus et malesuada fames ac turpis egestas.
        </p>

      </div>
    </div>
  </div>
</div>

Answer №1

If the statement I made earlier is accurate, what about this scenario? The image has an absolute position, allowing it to be hidden without affecting the positioning of the div below...

.spacing {
  padding: 15px;
}

.banners {
  display: block;
}

.banner_home {
  min-height: 100px;
  box-shadow: 5px 5px 10px #888;
  margin-top: 20px;
  padding: 0px;
  border-radius: 15px;
  display: block;
}

.banner_home_text {
  float: left;
  overflow: hidden;
  position:relative;
  padding-right:375px;
}

.banner_home_text p {
  margin: 15px;
}

.banner_home .banner_home_text img {
  position:absolute;
  right:0;
  top:0;
  padding: 0px;
  border-radius: 0px 15px 15px 0px;
  margin-left: 10px;
  display: block;
  width:375px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="banners">
  <div class="spacing">
    <div class="banner_home col-xs-12">
      <div class="banner_home_text">

        <img src="http://placehold.it/375x375" alt="Barbecue">

        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac lorem eget tellus volutpat pellentesque ut eu libero. Proin et dui ut nibh laoreet varius. Praesent nec dignissim ex. Mauris pharetra convallis lacus, a rhoncus urna porttitor id. Morbi
          vel tellus id quam condimentum egestas. Phasellus elementum molestie lacus. Donec aliquam congue mollis. Sed pellentesque orci tellus, sed fringilla turpis ullamcorper dapibus.
        </p>

        <p>
          Duis commodo egestas lacus quis commodo. Duis semper dapibus mi, posuere dictum libero fermentum sed. Etiam ligula eros, ornare nec mattis at, rhoncus vel ante. Vestibulum eget finibus nisl. Nam ullamcorper scelerisque sem non sagittis. Pellentesque habitant
          morbi tristique senectus et netus et malesuada fames ac turpis egestas.
        </p>

      </div>
    </div>
  </div>
</div>

Answer №2

#banner {   
  box-shadow: 15px 15px 15px #888;
  margin-top: 20px;
  padding: 10px;
  border-radius: 15px;
  margin: 10px;
  overflow: auto;
}

img {
  float: right;
  width: 40%;
  border-radius: 15px 15px 15px 15px;
  padding: 10px;
  max-width: 100%;
}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div id="banners">   
        <img src="http://placehold.it/375x375" alt="Barbecue" class="img-responsive">

        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac lorem eget tellus volutpat pellentesque ut eu libero. Proin et dui ut nibh laoreet varius. Praesent nec dignissim ex. Mauris pharetra convallis lacus, a rhoncus urna porttitor id. Morbi
          vel tellus id quam condimentum egestas. Phasellus elementum molestie lacus. Donec aliquam congue mollis. Sed pellentesque orci tellus, sed fringilla turpis ullamcorper dapibus.
        </p>

        <p>
          Duis commodo egestas lacus quis commodo. Duis semper dapibus mi, posuere dictum libero fermentum sed. Etiam ligula eros, ornare nec mattis at, rhoncus vel ante. Vestibulum eget finibus nisl. Nam ullamcorper scelerisque sem non sagittis. Pellentesque habitant
          morbi tristique senectus et netus et malesuada fames ac turpis egestas.
        </p>

      </div>

You should apply an overflow workaround in this instance.

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

I am looking to modify the anchor link and image source using JQuery based on the specific div ID

Looking to update the link of an anchor and source of an image inside this div when clicking on the FR button. I need help figuring out how to do this with JQuery. Here's the code: <div id="my_id"> <a href="wwww.google.com&qu ...

Is there a way to achieve this specific function using div elements instead of relying on tables, rows, and cells?

To achieve the same behavior as the example code, one can remove the use of the table, td, and tr tags and replace them with divs. The desired behaviors include: Content1 text wrapping within column1 when the page width decreases. Column2 having a minimu ...

Embedding JavaScript information into a cell of an HTML table

I am currently working on creating a pop-up box that, when triggered (with a delay), will showcase a counter displaying the number of clicks along with the dates of each click! I would like to present this information in a structured table format within a ...

Styling: petite vibrant square positioned in the corner of a large container

Can you please take a look at the screenshot from the demo app: box over box image I am trying to create a colorful small square box that will appear in the top left corner, on top of the larger parent square box (including all the contents inside the whi ...

Tips on incorporating form groups within a grid using semantic-ui-react

I am currently developing a project using semantic-ui-react that involves numerous input fields. To better organize the page, I have decided to split it into 3 columns. Below is the approach I have taken: render() { return ( <Form> < ...

Convert the image presentation to be inline

I am currently working on an image slider and I'm having issues with displaying the images inline. I have applied CSS but unfortunately, it's not working as expected. The images are not being displayed inline. Can someone please advise on what pr ...

Image floating with varying width and title with a background image

Here is the code I am currently working with: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...

Your browser's popup blocker is preventing the file from being downloaded

I am encountering an issue with my PHP file download function where the browser's popup blocker is preventing the file from opening. My objective is to create an HTML form submit button that will send a form, modify an RTF file on the server based on ...

Using jQuery validation to verify that a minimum of one radio button holds a true value

I have a form with two questions. The first question asks if the product value exceeds a certain fixed amount, and the second question asks if the product value is below that fixed amount. Upon submitting the form, validation should ensure that at least on ...

Is there a way to make the text appear on top of the overlay within this bootstrap carousel?

Currently, I am working on a project and I am interested in using a full-screen carousel. I came across this carousel snippet: . I am using the latest Bootstrap 3 version (3.3.7), but the snippet was originally built for version 3.2.0. If you try changing ...

Customizing the title style of the Material-UI app bar

Is there a way to customize the AppBar title in Material-UI without using inline styling? I have a separate CSS file and I want to be able to adjust the size of the title, for example. Something along these lines: .app-bar title { font-size: 120px !i ...

Creating a dynamic animation for a button in AngularJS

I'm having some trouble applying animations to an angular js button using traditional CSS and JS methods. Specifically, I'm attempting to include an opacity animation on the button. Can someone offer assistance? HTML <span id="sign_btn"> ...

What is the best way to adjust the size of my <div> to accommodate additional vertical content?

Every time I attempt to include margin-top: 30px to my box_1 and box_2 <div>, the bottom <div> is pushed down and disappears. It seems like my wrapper isn't expanding to accommodate the content. How can I achieve a 30px space between the ...

Is it possible to assign a Bootstrap class as a variable in a custom CSS declaration?

While trying to make my website responsive, I planned on using media queries to adjust text size and other elements. The issue arises because I rely on bootstrap for setting text sizes. Is there a way to apply bootstrap classes in my CSS file? For instanc ...

Difficulty with alignment in the process of generating a vertical stepper using HTML and CSS

I'm currently working on developing a vertical stepper component using html & css with inspiration from this design. However, I've encountered some alignment issues in the css that I'm struggling to resolve. CSS .steps-container .step::b ...

Get the PDF in a mobile app using HTML5 and Javascript

For my HTML5/JavaScript-based mobile application, I am in need of implementing a feature that enables users to download a PDF file. The PDF file will be provided to me as a Base64 encoded byte stream. How can I allow users to initiate the download proces ...

Adjust the ARIA value of a Bootstrap progress bar within a VueJS component on the fly

During the development of my website using VueJS and Bootstrap, I made the decision to utilize Vanilla Bootstrap instead of a specific VueJS framework like VueBootstrap or VueStrap. Currently, I am facing an issue while building a custom component that wr ...

Content overflowing the container - Designed to adapt to different screen sizes

I'm currently working on a project within the Bootstrap 3 framework and struggling with an issue regarding text overflow in extra small view. The text is not behaving as expected, as it should stick to its container and break accordingly. I've ex ...

SQL/PHP challenge: Trouble updating a record

As a newcomer to PHP, I apologize if my question is basic. I am attempting to update a record using PHP / SQL. Despite researching the error message online, I cannot pinpoint the issue within my code: An error occurred: SQLSTATE[HY093]: Invalid paramet ...

Having trouble with the href attribute not properly redirecting to a different page

I am trying to create a hyperlink for an option that will take users to another page. All the other options on the page lead to different sections within the same page. When I add CONTACT, it doesn't work. All the files are in the same ...