Can someone assist me with positioning the image card to overlay the top border of the card using bootstrap, or is it only achievable with CSS?

https://i.sstatic.net/Ef69i.png

Is there a way to use Bootstrap to position the image card to overlay the top border of the card without using custom CSS?

I've attempted to achieve this with the following custom CSS:

style="margin: -50px 70px;"

However, I am looking for a solution that utilizes Bootstrap instead.

Answer №1

To achieve this layout, you can use the following combination of classes

position-absolute top-0 start-50 translate-middle
. This will center the element horizontally with its middle point at the top of the container. For more information, check out https://getbootstrap.com/docs/5.2/utilities/position/#center-elements

Illustrated below is an example:

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f6fbfbe0e7e0e6f5e4d4a1baa6baa6">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">

<div class="container">
  <div class="row">
    <div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
      <div class="card mt-5 pt-5">
        <img src="https://www.fillmurray.com/200/200" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
        <div class="card-body text-center pt-5">
          <h5 class="card-title">Card title</h5>
          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </p>
        </div>
      </div>
    </div>
    <div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
      <div class="card mt-5 pt-5">
        <img src="https://www.fillmurray.com/199/200" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
        <div class="card-body text-center pt-5">

          <h5 class="card-title">Card title</h5>
          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </p>
        </div>
      </div>
    </div>
    <div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
      <div class="card mt-5 pt-5">
        <img src="https://www.fillmurray.com/200/198" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
        <div class="card-body text-center pt-5">

          <h5 class="card-title">Card title</h5>
          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </p>
        </div>
      </div>
    </div>
    <div class="col-12 col-sm-6 col-md-4 col-lg-3 mt-5">
      <div class="card mt-5 pt-5">
        <img src="https://www.fillmurray.com/200/199" class="rounded-circle w-50 position-absolute top-0 start-50 translate-middle" alt="">
        <div class="card-body text-center pt-5">

          <h5 class="card-title">Card title</h5>
          <h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
          <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
          </p>
        </div>
      </div>
    </div>
  </div>
</div>

The inclusion of margin and padding classes such as .col, .card, and .card-body is crucial to prevent image overlap or overflow outside the container boundaries.

Answer №2

Your inquiry lacks clarity and does not include any code to reference. Here is a suggested solution:

<div class="grid">
   <div class="item">
     <div class="image-container">
          <img
            width="90"
            height="90"
            style="border-radius: 100%; margin-top: -45px"
            src="https://example.com/image.jpg"
            alt=""
          />
          <h3>Name Placeholder</h3>
          <p>
            Lorem ipsum dolor sit amet consectetur adipisicing elit.
            Necessitatibus pariatur nisi veniam dolorem architecto, 
            voluptatibus maxime eaque accusantium illum magni.
          </p>
     </div>
   </div>
 </div>

It's better to ignore the grid and item classes as they are used for formatting purposes based on your description. Focus instead on using the margin-top property in CSS to address your issue.

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

Difficulty arises when trying to engage with the addition span within a span using jQuery

Looking for some assistance here! Currently in the process of developing a mail system and focusing on creating a list of receivers. I am working on adding user names to a span element, with the goal of being able to remove users by clicking their name. & ...

Preview Image Unavailable

I am currently working on a project that involves creating a form where users can upload an image and see a preview of it before submitting. Unfortunately, I am facing issues with getting the image preview to display correctly. Below is the HTML code snip ...

Tips on concealing the scrollbar only when a particular element is visible

I inserted the following code into my index.html file: <head> <style> body::-webkit-scrollbar { display: none; } </style> </head> This code successfully hides the scrollbar. My goal is to only h ...

The <Option> element fails to return a value upon selection by the user

I have successfully created a SQL query that populates a listview on HTML. However, I am encountering an issue when the user selects a value from the listbox. The variable becomes null, causing the SQL statement for INSERT to be missing the value of this v ...

Issue with Internet Explorer 7 causing table to display with added height

Currently investigating why there is additional space being added by IE. The only fixed data is the width of the image (171 px). Using Jquery, I checked the height of the div in Firefox, Chrome, and Opera which came out to 164px, but in IE 7 it's 172 ...

Troubleshooting problem in asp.net involving datasrc and datafld for obtaining XML data

I have successfully implemented code in IE that displays my profile information on an XML site, including my userid, name, company, and phone number. After adding HTML codes, <xml id="XmlUserInfo" src="http://usmdlcdoww002.intranet.dow.com/common/comp ...

Elements overlapping within div elements

Div container and p element are overlapping another Div that contains an image. The image needs to respond to a :hover CSS event but only a small portion of that Div container is able to sense the mouse hovering over it. Any suggestions on how to solve t ...

"Embracing Flexbox for a fully responsive mobile experience

What's the best way to make this flexbox design responsive for mobile devices? I want the layout to look consistent across both desktop and mobile screens. The issue seems to be related to the responsiveness of the flexbox and the smaller size of mobi ...

Transforming an Ionic mobile application into a web-based application: A step-by

I currently have a mobile app developed using Ionic. I now require a desktop-friendly website version of the app to cater to users who wish to access it from their computers. Can anyone point me to any resources or documentation that demonstrate that th ...

Trouble with Bootstrap Collapse feature not collapsing on its own

I recently added a Bootstrap collapse feature to my payment view in Laravel. The Bootstrap section collapses when clicked, but I would like it to be collapsed by default. I understand that I need to include: aria-expanded="false" However, it still doesn& ...

Tips for eliminating the border radius on select box elements within Bootstrap

I am currently using bootstrap v3.3.1 from the standard directory, and I am facing difficulty in removing the border radius from the select box components specifically in Google Chrome. This particular inquiry is unique because: Despite attempting to mo ...

Utilizing CSS styling in PHP as a functional approach

In my journey of learning CSS, HTML5, and jQuery, I have found a unique way to organize my CSS code into different chapters. I simply call them into the head section when needed. This method allows me to have only the necessary CSS on each page, making it ...

Comparing identical elements in JavaScript

Crucial Note I want to clarify that I have no intentions of scamming, phishing, or causing any harm. My goal is to develop a website magnifier similar to using a magnifier on paper. Dilemma Let me paint the picture for you. I've effectively copied ...

What could be the reason for my CSS selector with :target not functioning properly?

I tried to implement the instructions I found online for using :target, but it's not working as expected. My goal is to change the background color and font color of #div1 when the first link is clicked, and to change the border of #div2 when the seco ...

Is there a way to decrease the size of the content within this iFrame?

Is there a way to display 6 cameras on a single webpage without them taking up the entire screen within iframe windows? Can the content be shrunken to fit the iframe window? <!doctype html> <html> <head> <meta charset="utf-8"> &l ...

Position icons and images on the right side, and the textarea on the left side of the page (using Twitter

Summary: Here is the desired end result shown in the image below. Alternatively, you can refer to the JSFiddle. Ideally, only CSS should be used without changing the DOM structure. The icons need to be aligned completely to the right using the .pull-right ...

Adding space between Bootstrap columns to align them one below the other on small devices

https://i.sstatic.net/turhY.png Within this illustration, there are two columns - one with the class col-sm-3 and the other with col-sm-8, situated in a single row. Upon resizing the window (as shown in the screenshot provided), the two columns appear ...

Using Less in CSS values can sometimes involve incorporating slashes (`/`), such as in the shorthand for `font`

While working with Less and font shorthand, I came across an issue: .font(@weight: 300, @size: 22px, @height: 32px) { font: @weight @size/@height "Helvetica Neue", Arial, "Liberation Sans", FreeSans, sans-serif; } The above code snippet resulted in a ...

Performing mathematical calculations using javascript

In my project, I'm utilizing HTML, CSS, and JavaScript to achieve the following: Dropdown menu for Category (Coffee Appliance) Dropdown menu for Product (Keurig Coffee Maker) Wattage: 1500kWh (auto-filled from Local Storage) Daily Energy Con ...

Implementing JavaScript to add a loading spinner to a specific cell

Currently, I'm utilizing the code below (not my original) in order to load an image into a css element (referred to as cell) and showcase an activity indicator. var cell = document.createElement('li'); cell.textContent = this.labelForIndex( ...