When padding is added on an MVC 5 page, the Bootstrap 4.1.1 class option for rounded-circle becomes distorted

Incorporating VS 2017 and bootstrap 4.1.1 into an MVC 5 page, I am facing a challenge in adding right-side padding to an image without distorting the circular shape of the image, as shown below. When I apply the padding, the circle becomes warped, but removing it causes the text to be too close to the image on the right side:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="row">
  <div class="col-sm-12">
    <br />
    <figure>
      <style>
        .imgRightPadding20 {
          padding-right: 20px;
        }
      </style>
      <img class="img-fluid float-left rounded-circle imgRightPadding20" src="https://picsum.photos/200" alt="PersonName" />

      <p> Some text about this person. </p>
    </figure>
  </div>
</div>

The image currently is a standard square image, and I aim to utilize the rounded-circle feature from Bootstrap without compromising its circular form when applying padding to the right side for text alignment purposes. How can I achieve this within the Bootstrap 4.1.1 framework? Thank you for your assistance.

========== UPDATE July 5, 2018

To provide context, below are excerpts from the _Layout.cshtml file in my MVC 5 project. If I implement the suggested tag changes at the beginning of the initial code snippet, should these changes also be added to the _Layout.cshtml file or just to the affected pages? This process has left me somewhat perplexed.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - some person Website</title>
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

</head>
<body style="padding-top:unset; padding-bottom:unset">

    <nav class="navbar navbar-dark bg-dark navbar-expand-sm">
        <div class="container">
            <a href="#" class="navbar-brand">Some Person</a>
            <ul class="navbar-nav">
                <li class="nav-item"><a class="nav-link" href="Index">Home</a></li>
                <li class="nav-item"><a class="nav-link" href="/Home/About">About</a></li>
                <!--    <li class="nav-item"><a class="nav-link" href="/Home/Contact">Contact</a></li>li>-->
            </ul><!-- navbar-nav -->
        </div><!-- container -->
    </nav>

    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - ASP.NET MVC 5 web application built by some person</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

========== UPDATE July 7, 2018 11:30pm

Attached is an image showcasing the bootstrap Nuget package I have integrated into my VS 2017 project:

https://i.sstatic.net/x1DUj.jpg

========= UPDATE July 7, 2018 12:27 a.m. The most viable solution for me was enclosing the img tag within a div tag and applying the float-left and padding styles to the div rather than the img itself. This adjustment ensured all other elements align properly within VS 2017, obviating the need for additional script statements in the MVC 5 pages or the css link at the top of the page.

<div class="row">
   <div class="col-sm-12">
      <figure>
         <style>
           .imgRightPadding20 {
           padding-right: 20px;
           }
         </style>

         <div class="float-left imgRightPadding20">
             <img class="img-fluid rounded-circle" src="~/Content/Images/someperson-200x200.jpg" alt="some person" />
         </div>
         <p>Some text about the person   </p>
      </figure>
    </div>
 </div>

Answer №1

To create a responsive layout, utilize the d-flex class on the figure tag and apply margin using the mr-4 class instead of padding on the image.

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="container">
  <div class="row">
    <div class="col-sm-12">
      <br />
      <figure class="d-flex">
        <img class="img-fluid rounded-circle mr-4" src="https://picsum.photos/200" alt="PersonName" />

        <p> Describe this person briefly. </p>
      </figure>
    </div>
  </div>
</div>

Alternatively, If you prefer to use float, adjust padding-right: 20px to margin-right: 20px;

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="row">
  <div class="col-sm-12">
    <br />
    <figure>
      <style>
        .imgRightPadding20 {
          margin-right: 20px;
        }
      </style>
      <img class="img-fluid float-left rounded-circle imgRightPadding20" src="https://picsum.photos/200" alt="PersonName" />

      <p> Describe this person briefly. </p>
    </figure>
  </div>
</div>

Answer №2

In order to address the issue, I had to enclose the img tag within a div tag and then apply float-left and padding to the div tag instead of the img tag. Thankfully, all other components in VS 2017 were working fine, so there was no need for additional script statements or css link lines at the top of MVC 5. The _Layout.cshtml file remained untouched. The following snippet shows the necessary adjustments:

<div class="row">
   <div class="col-sm-12">
      <figure>
         <style>
           .imgRightPadding20 {
           padding-right: 20px;
           }
         </style>

         <div class="float-left imgRightPadding20">
             <img class="img-fluid rounded-circle" src="~/Content/Images/someperson-200x200.jpg" alt="some person" />
         </div>
         <p>Some text about the person</p>
      </figure>
    </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

Combining JQuery with ASP.NET Web Forms to create dynamic and interactive web

I have embarked on creating an ASP.NET Web Form application that aims to incorporate some cool jQuery features and visual appeal. One part of my application includes two jQuery UI tabs: a search tab and a results tab. Upon conducting a search from the sear ...

Creating dynamic Bootstrap table columns with consistent widths for each column without the use of JavaScript

I'm trying to create a table with a dynamic number of columns using html/css/Bootstrap without relying on Java Script. The table should span 100% of the parent container's width. Each column in the table should have an equal width (3 columns = ...

Is it possible to employ ViewData with a 'for loop' for an integer array?

namespace ViewDataExample.Controllers { public class LandingController: Controller { // GET: Landing public IActionResult Home() { ViewData["WelcomeMessage"] = "Greetings from the ...

Retrieve numerical data from the element and enclose it within a span tag

My goal was to indent a number, but the HTML generated from my CMS is making it difficult to target the number and apply a specific style. <div class="content"> <b>01. Header</b> Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...

What are the possible reasons for the Selenium GECKO driver failing to start the server on Firefox 48?

In our .Net Automation Testing Project, we were using Selenium 2.5.3 along with a NUnit Test project successfully with Firefox version 47. However, after upgrading to Firefox 48, we started encountering issues. I downloaded the Gecko.exe (version 9) from ...

The div element with the id "wrapper" is not functioning properly within the box model

I have defined an ID wrapper in CSS: #wrapper { position: relative; background: yellow; -webkit-box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.2); box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.2); width: 960px; padding: 40px 35px 35px ...

Ways to display or conceal information on an aspx page depending on the roles of the current user

In my ASP.NET website, each page is filled with various content and each user that logs in has specific roles. I am looking for a way to display or hide certain page contents based on the roles of the logged-in user. How can I achieve this? By the way, I ...

The fixed navigation bar shows a flickering effect while scrolling at a slow pace

Currently facing a challenge with our sticky navigation. Noticing a flickering issue on the second navigation (sticky nav) when users scroll down slowly. The problem seems to be specific to Chrome and Edge, as it doesn't occur on Firefox, IE11, and S ...

Displaying a Bootstrap modal with empty editing information

I am facing an issue with my modal bootstrap where the data is not loading into the bootstrap even though it is being passed from the controller. The Grid on my page pulls in data from a list for Notes Object @foreach (var notes in Model) { <tr> ...

Can you please tell me the CSS pseudo element that corresponds to the AM/PM field in an <input type="time">

The issue with the am/pm display is dependent on the browser that the app is opened in. I am looking for a universal solution to ensure it does not appear in any popular browsers. Below is the HTML code for my input time field: <input type="time" for ...

Steps for creating a resizable and automatically hiding side menu

I am working on a side menu that can be resized, and I want it to collapse (set to zero width) when it is empty. I have considered implementing one of these features individually, but I'm not sure how to make both work together. Is there a way to ad ...

Searching in Arrays: Equality and Comparison

I recently came across this MSDN article stating that According to the information provided, in the .NET Framework version 2.0, the method uses the Equals and CompareTo methods of the Array to check for the existence of the Object specified by the valu ...

Hidden overflow and identification in URL causes content to be invisible and suddenly appear at the top of the page

I'm encountering a strange issue with containers that have overflow:hidden and when the page URL includes an id. The content gets pushed up and becomes invisible. This problem arises when I apply padding and negative margin at the bottom to create equ ...

Loading Animation for Pages and Tables

I'm experiencing a choppy and sudden transition when switching between two pages that contain tables populated using ng-repeat. Upon loading, the footer is positioned halfway up the page below the table heading until the table loads and the layout adj ...

Is anyone else seeing a mysterious gray outline surrounding the image?

When visiting my website, I encountered an issue with the main menu. Specifically, when hovering over 'Populaire boeken', the first 2 menu items display properly with an image on mouseover. However, there seems to be a pesky grey border surroundi ...

Center two lines of text in a div in a vertical fashion

After going through several articles on this topic, I've picked up some tricks for vertical alignment like using line-height for a single line of text, display:table for multiple divs, and Flexbox in CSS3. However, I'm still struggling to align t ...

Incorrectly colored buttons upon clicking

I am experiencing an issue with my website where the color of the container div is not changing to the correct color when a button representing a color is clicked. Instead, it seems to be displaying the next color in the array of color codes that I have se ...

The button's color cannot be modified due to a malfunctioning event script that is not

Seeking an explanation for why my current implementation isn't working. I'm attempting to create a quiz with a multiple choice section where the correct answer turns green when clicked, and incorrect answers turn red. Despite validating the code ...

The offcanvas menu in the NextJS Tailwind website does not handle hover or tap events properly when outside of the parent dimensions

My header includes an off-canvas menu that slides in from the right side. Everything seems to be working fine, except for one issue: when the menu is open and visible, the mouse and touch events pass through it to the content underneath. Check out the cod ...

Design of website built on Bootstrap framework seems distorted on Firefox browser

I built this website with the help of Bootstrap and you can view it at js-projects. Everything looks great when I open it in Chrome or Safari, but there are weird white strips that resemble scroll bars when I view it in Firefox. Can someone assist me in ...