Trouble with CSS Positioning: Resizing my browser causes my image to shift in position

Upon resizing the browser window, my website layout adjusts accordingly and looks as intended at a smaller size:

However, as I begin to expand the browser width, the centrally positioned image starts shifting towards the left. I aim for the image to remain centered regardless of how the browser is resized. Is there a solution to this issue? I've been exploring options without success. Any help would be greatly appreciated. Thank you.

Here is my HTML:

<html>
<head>
    <title>Jason H Kang</title>
  <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
  <link rel="stylesheet" href="style.css">
</head>

<body>
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
    </div>
    <div>
      <ul class="nav navbar-nav">
        <li><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Portfolio</a></li> 
        <li><a href="#">Contact</a></li> 
      </ul>
    </div>
  </div>
</nav>

  <div id="span">
      <h1 class="text-center">Jason H Kang</h1>

      <div class="intro">
          <p class="text-center">23 Years Old | Junior Web Developer | NJ</p>
      </div>

      <div class="hello">
          <p class="text-center">
          Hello I am Jason Kang. Welcome to my personal website!</br>Please feel free to contact me if you have further inquiries.</p>
      </div>
  </div>

    <div class="image">
     <img src="kangjason.jpg" alt="face" class="img-circle">
    </div>

    <!-- <div class="button">
      <button type="button" class="btn btn-success">Contact Me!</button>
    </div> -->

<div id="footer">
  <p class="copyright">Copyright: Jason Kang 2015</p>
</div>

</body>
</html>

Below is my CSS:

body {
    background-color: #F8F8FF;
    color: #000000;
}


.navbar {
    background: rgba(114, 180, 39, 1)
}

.navbar .brand, .navbar .nav > li > a {
    color: #FFFFFF;
    margin-left: 14em;
    padding-right: 0em;
    font-family: Gill Sans;
    font-size: 1.0em;
}
.navbar .brand, .navbar .nav > li > a:hover {
    color: #000000;
}

#footer {
    background:#000000;
    width:100%;
    height:47px;
    position:fixed;
    bottom:0px;
    left: 0px;
}

.copyright {
    padding-top: 19px;
    padding-left: 1.3%;
    font-family: Arial;
    font-size: 0.9em;
    color: white;
}

.intro {
    padding-left: 0.35%;
    font-family: 'Source Sans Pro', sans-serif;
    position: relative;
}

.hello {
    padding-top: 1.5%;
    padding-left: 5%;
    font-family: 'Source Sans Pro', sans-serif;
    position: relative;
}

.img-circle {
   width: 11.0em;
   height: 11.0em;
   border: 1px solid black;
   margin-left: 10em;
   margin-top: 1em;
   position: relative;
  }  

Answer №1

To align a block level element in the center, you can use the CSS property margin:auto:

.img-circle {
   width: 11.0em;
   height: 11.0em;
   border: 1px solid black;
   margin: auto;
   margin-top: 1em;
   position: relative;
   display:block;
  }

View JSFiddle Demo
Alternatively, you can also center the element by setting its parent to have text-align:center;:

.image {
  text-align: center;
}

View JSFiddle Demo

Answer №2

To update the style of the img-circle class, adjust your CSS code like this:

.img-circle {
    width: 11.0em;
    height: 11.0em;
    margin: 0 auto;
    border: 1px solid black;
    display: flex;
}

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

When interacting with Chrome, the div gets automatically blurred upon being clicked

While working on the development of our website, we stumbled upon something peculiar. We have a set of divs displayed on the screen, resembling the layout of Pinterest. Upon clicking any of these divs, the content within that particular div is loaded into ...

Adjust and modify class when resizing the window

I've encountered a challenge with my Bootstrap Modal when trying to set the width to 750px on large desktops. When resizing the window to a smaller size, the modal loses its responsiveness. To tackle this, I added a class to the modal to give it a fix ...

Improving JavaScript event management efficiency through handling numerous asynchronous HTTP requests

Summary: In a SPA CMS project, multiple dynamic data sources are causing performance issues due to a large number of asynchronous HTTP calls required to display a table with extensive data. The challenge is to maintain good performance while handling the ...

What is the best way to create a dynamic hyperlink that leads to a detailed information page based on the specific link clicked?

I'm currently working on a web page that displays a list of users, and I want each user's name to be clickable, leading to a page with specific details about that user. I'm new to this field, so I'm unsure where to start. My idea is to ...

What is the best way to create a strip within an oval using CSS to achieve a partially filled vertical vessel effect?

I need to create an oval shape with a strip inside to represent the level of liquid volume. Here is my initial attempt: <style scoped> .strip:before { position: absolute; background: #343434; border-bottom: 2px solid black; content: ""; ...

What is the method to extract div text using Python and Selenium?

Is there a way to extract the text "950" from a div that does not have an ID or Class using Python Selenium? <div class="player-hover-box" style="display: none;"> <div class="ps-price-hover"> <div> ...

Is there a Polar transformation available in CSS3?

Converting a line into a ring is a straightforward process in graphic design software like GIMP: https://i.sstatic.net/7lQZe.png (source: adamhaskell.net) I'm exploring the possibility of achieving the same effect using CSS. Here's what I&ap ...

Making sure the checkbox stays selected in an angular environment

After experimenting with Angular 9 and a custom input, I achieved the following result => https://stackblitz.com/edit/angular-ivy-rgsatp My goal was to prevent users from disabling a radio button that is currently checked. Therefore, I made changes in ...

Struggling to align a search box with other items in a custom navbar using Bootstrap 4?

I created a unique navigation bar using Bootstrap 4's grid system. The navbar is designed with two sections: one for the navigation items on the left and another for the search box on the right. Unfortunately, I am facing an issue where the search box ...

Is it possible to retrieve the current CSS value set by a media query using JavaScript?

Currently working on a website project that involves accessing and manipulating the display property of a menu. The goal is to toggle the menu open or closed based on its current state. In my setup, the initial state of the menu is defined as closed using ...

What methods can be utilized to create sound effects in presentations using CSS?

Let us begin by acknowledging that: HTML is primarily for structure CSS mainly deals with presentation JS focuses on behavior Note: The discussion of whether presentation that responds to user interaction is essentially another term for behavior is open ...

Ways to customize the appearance of an iframe's content from a separate domain

I am facing a challenge with my widget and multiple websites. The widget is hosted on one domain, but the websites use an iframe to display it. Unfortunately, because of the Same Origin Policy, I cannot style the content of the iframe from the parent websi ...

Styling a parent element when it is in focus using CSS3

Is there a way to apply a style to the parent element when an input is in focus? input:focus { background-color:yellow; } For example, if we have the following HTML: <div class="foo"> <input type="text /> Hello </div> I ...

Modifying the maximum length of input fields in HTML, Javascript, and PHP is possible by adjusting the value through

Hi there, I'm facing an issue that should be easy for you guys to help me with. I recently discovered a security flaw while using the maxlength function in HTML. Users can easily modify the maxlength attribute by inspecting elements on the website, wh ...

Is it possible for images to align vertically instead of horizontally in IE?

Encountering an issue with image alignment in Internet Explorer - they are aligning vertically instead of horizontally, while functioning correctly in all other browsers. Moreover, in IE8 and 7, the images are not being displayed at all. Is there a workaro ...

Container that displays vertical scroll while permitting floating overflows

Is there a way to set up a container so that when the window size is too small, it displays a scroll bar to view all elements that don't fit in one go? At the same time, can the child containing floating elements be allowed to extend beyond the bounda ...

The stacking order of React components

I am having an issue with the Z-index in my component-based React app. I currently have a list component that contains items, and I want to adjust the CSS scale and z-index to display one item in front of the others. The problem arises when the hovered it ...

The functionality of the Bootstrap4 accordion is not functioning according to my expectations

My goal is to create a unique e-commerce checkout page design. Each panel would be opened sequentially, with the next panel unfreezing when the action button of the current panel is clicked. However, I seem to be making a mistake as it is not working as in ...

Creating a form that seamlessly integrates with the content using a combination

As I continue to explore the depths of WordPress and delve into learning HTML/CSS, my latest project involves embedding an email signup form on my website using Klaviyo. The basic code provided by their form creator initially had everything condensed into ...

Linking jQuery UI tabs to tabs on a different pageWould you like assistance

I am facing a challenge that I need help with. For a school project, I have to create 8 pages of HTML, each with a template and a menu. The menu consists of tabs that are supposed to link to separate pages when clicked. However, the issue is that when I cl ...