"Concerns raised about the margin at the bottom of the img element

I'm having trouble creating space between the profile picture and the text on my page. I've tried adding a bottom margin to the image, but it's not working as expected. Setting display: block didn't make any difference either. Why is this happening?

When I adjust the height and width of the #profile-pic to 100%, or apply margin directly to the #profile-pic, it works fine. However, I'm confused about why it's not working in this particular scenario.

#about {
  height: 100%;
  width: 100%;
}

#profile-pic {
  height: 250px;
  width: 250px;
  margin: auto;
}

#profile-pic img {
  display: block;
  height: 100%;
  width: 100%;
  margin-bottom: 100px;
  box-shadow: 0 0 5px 1px rgb(255, 255, 255);
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 38%;
}
<section id="about">
  <div id="profile-pic">
    <img src="https://data.whicdn.com/images/322027365/original.jpg?t=1541703413" alt="profile pic">
  </div>
  <p class="text-center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum autem sequi, est enim, eligendi voluptas et ut aspernatur nostrum laboriosam maxime itaque assumenda sapiente reiciendis, tenetur exercitationem culpa quia ea laudantium! Exercitationem
    quo quibusdam, sit quas perspiciatis aspernatur aliquam enim nihil assumenda omnis sunt sequi rerum quisquam. Nesciunt,

</section>

Answer №1

Due to the fixed height of the parent element #profile-pic, the img element with a height set to 100% will inherit that height, which is specified as 250px. The presence of margins on the image element will not alter this behavior; instead, it will simply cause overflow onto surrounding elements without affecting the appearance of the displayed image.

Answer №2

Try assigning it to the div instead of the image tag

#about {
  height: 100%;
  width: 100%;
}

#profile-pic {
  height: 250px;
  width: 250px;
  margin: auto;
  margin-bottom: 100px;
}

#profile-pic img {
  display: block;
  height: 100%;
  width: 100%;
  box-shadow: 0 0 5px 1px rgb(255, 255, 255);
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 38%;
}
<section id="about">
  <div id="profile-pic">
    <img src="https://data.whicdn.com/images/322027365/original.jpg?t=1541703413" alt="profile pic">
  </div>
  <p class="text-center">Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum autem sequi, est enim, eligendi voluptas et ut aspernatur nostrum laboriosam maxime itaque assumenda sapiente reiciendis, tenetur exercitationem culpa quia ea laudantium! Exercitationem
    quo quibusdam, sit quas perspiciatis aspernatur aliquam enim nihil assumenda omnis sunt sequi rerum quisquam. Nesciunt,
</section>

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

Identifying the names of files downloaded from Google Patents

I have a collection of over 500 links from Google Patents stored in a CSV file. Using Scrapy, I am able to iterate through these links and download the CSV files associated with each link (each link has a download option). The challenge I am facing now i ...

Wrapper with a height of 100% that causes issues with floating children

I am completely lost with what's happening here. I've exhausted all the online solutions I could find, but nothing seems to be working. Adding clear styles isn't effective, and using overflow:auto is not an option as I'm positioning th ...

Creating Interactive Buttons with Dropdown Menus in Bootstrap

I am using a Bootstrap dropdown menu with various categories for users to select from. I want the 'Department' button to dynamically change to display the selected category after a user makes a selection. Below is the HTML code for the dropdown: ...

The redirection of the URL after form submission is not functioning correctly

I'm attempting to develop a pair of dropdown lists in Elementor where the second dropdown's options depend on what is selected in the first, and the second contains URLs linked to a GO button that redirects to the chosen URL. However, I've f ...

What could be the reason my bootstrap cards are stacking vertically instead of being placed horizontally next to each other?

My Bootstrap cards are not aligning side by side and I'm having trouble locating the error in my code. I'm working with Django and HTML. {% extends 'base.html' %} <div> {% block content %} <h1>Team Members<h1& ...

Access the designated hyperlink within the table row

Currently experimenting with Selenium Webdriver in Firefox and also looking to test in IE8. Below is the structure of my HTML: <table id="table"> <tbody> <tr> <td>Text1</td> <td><a id="assign" hr ...

Designing the autocomplete dropdown feature in Bootstrap UI

I'm currently developing an app that is utilizing AngularJS and Bootstrap, with the assistance of Bootstrap UI. Specifically, I am working on implementing the typeahead feature. However, I am facing a challenge in trying to ensure that the dropdown li ...

Using PHP to access HTML content from a page that demands authentication

I need help developing a PHP script that can scrape data from an HTML page. Right now, it works perfectly with pages that don't require authentication. However, I'm struggling to figure out how to extract content from a page that requires users t ...

If a specific class is identified, add a border to the div when clicked using JavaScript

Is there a way to use javascript/jquery to add a border to a selected div? I have multiple rows with columns, and I want only one column per row to be highlighted with a border when clicked. Each row should have one column with a border, so it's clear ...

Guide to creating a visual representation of an audio stream in HTML5

Is it possible to draw a waveform of audio extracted from a webcam media stream in real-time using HTML5 and JavaScript? I have explored: https://github.com/soundcloud/waveformjs https://github.com/katspaugh/wavesurfer.js However, these solutions appea ...

Outlook's limited width is causing images to exceed the boundaries of the HTML email

I have a collection of images that display perfectly in Gmail, but when viewed in Outlook, all five images appear within a single <tr> and cause the table width to expand. My desired layout is to have the first four images centered on the first line ...

Tips for dynamically updating the URL based on a query string within the URL

Here is a table generated by GridView: <table id="ctl00_centerContent_GridView1"> <tr> <th scope="col"> <!-- COLUMN INFORMATION --> </th> </tr> <tr> ...

I'm attempting to resize my images to fit within the container, but instead they appear enlarged

I'm struggling to get my images to resize based on the container size, especially when viewed on tablets or phones. The current result is that the images are too zoomed in and I can't figure out what's causing this issue. ...

What is the best way to assign various classes to individual elements depending on their content?

HTML <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-401 dt-mega-menu mega-auto-width mega-column-3"> <a href='#' data-level='1'> <i class="logo-png dnld-logo"></i> ...

The functionality for bold and italics does not seem to be functioning properly in either Firefox

Text formatted with <b></b> and <i></i> tags appears correctly on iPhone and Internet Explorer, but lacks formatting in Firefox or Chrome. I have included the .css files below. Additionally, I attempted to add i { font-style:italic ...

Ways to troubleshoot React JSX/HTML input issue displaying as -$NaN.undefined

https://i.sstatic.net/1xIvb.pnghttps://i.sstatic.net/aeQrS.pngI'm currently facing an issue while trying to implement an input field that subtracts a number from another computed value within an HTML table setup. I've noticed that everything work ...

Yet again faced with an annoying gap between table rows and cells, for the 532nd instance

Once again, tables have defeated me. I am struggling with a simple table: <table style="width: 200px; margin: 20px auto; border-collapse: collapse; border-spacing: 0; border: none;"> <tr style="margin: 0; padding: 0; border: none; border-colla ...

Contenteditable feature dynamically styling text upon input

Is it possible to prevent CSS properties like text-transform from affecting text entered via contenteditable? On my webpage, "CERTIFICATE PROGRAM" is shown in uppercase due to text-transform settings. However, the original input was: Certificate Program. ...

What is the best way to create a personalized image as the background in WordPress using CSS for a client?

I have this in my style.css .showcase{ background: url("x.jpg") no-repeat 0; } My website is built on WordPress and I have implemented advanced custom fields for the client to edit text. However, I am struggling to find a way for them to change the ...

Creating a fluid grid layout using CSS that consists of just two cells that adjust

Is it possible to design a flexible CSS grid layout with two cells that can switch between stacking vertically or horizontally to maximize the area of the second cell? (or similar heuristic) Vertical Layout Horizontal Layout Ideally, the menu cell shoul ...