Object shifting as the window is resized

Check out the Umbrella image in the images section:

Full-size window: .

Reduced (ideal placement):

I want my umbrella image to always display in the center of the screen, regardless of the size of the window. It should work when the window shrinks and also in mobile view.

I've experimented with different methods but haven't been successful so far. Any suggestions would be highly appreciated.

Here is the code snippet:

HTML

<div class="wrapper">
<div class="page2">

  <h2>Blog</h2>

  <div class="wrap">

    <div class="card">
      <a href="welcome.html">
      <img class="card-img" src="str3.jpg">
    </a>
      <div class="card-text">
        <h3><a href="welcome.html" id="card-link">Welcome</a></h3>
        <p>Website Launch and my First Project</p>
      </div>
    </div>

    <div class="card">
      <a href="blog.html">
      <img class="card-img" src="steve_roe_kyoto.jpg">
    </a>
      <div class="card-text">
        <h3><a href="blog.html" id="card-link"> Kyoto</a></h3>
        <p>My Recent Trip</p>
</div>
  </div>

    <div class="card">
      <a href="best.html">
      <img class="card-img" src="str4.jpg">
    </a>
      <div class="card-text">
        <h3><a href="best.html" id="card-link">Best of 2018</a></h3>
        <p>Neon Goodness from Last Year</p>
      </div>
  </div>
    </div>


<div class="page3">
  <footer>
  <div class="umbrella_icon">
  <img src="umbrella-02.png">
  </div>


    <div class="logo_footer">Steve Roe</div>
      <div class="footer_menu">
  <ul class="ul_footer">
    <li><a href="work_with_me.html">Work With Me</a></li>
    <li>
<a href="xxxxxxxxxxxx.com">Contact</a></li>
  </ul>

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

CSS

.page2{
  width: 100%;
  margin: 0 auto;
  margin-top: 20px;
  height: 100%;

}

//cards
.wrap{
  width:960px;
  margin:auto;
  margin-top: 100px;

}

.card{
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.15);
  transition: 0.4s;
  width: 300px;
  text-align: center;
  font-size: 16px;
  float:left;
  margin:10px;
  text-decoration: none;


}
.page3{

  margin: 20px;
  margin-top: 20px;
  height: 30%;
}

.umbrella_icon {

  text-align: center;

}

.footer {
  z-index: 1000;
  width: 960px;
  margin: 0 auto;

}

Answer №1

Utilize the dispaly:flex property within the .wrap class

View the code in action

.page2{
  width: 100%;
  margin: 0 auto;
  margin-top: 20px;
  height: 100%;

}


.wrap{
    margin: auto;
    margin-top: 100px;
    display: flex;

}

.card{
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.15);
  transition: 0.4s;
  width: 300px;
  text-align: center;
  font-size: 16px;
  float:left;
  margin:10px;
  text-decoration: none;


}
.page3{

  margin: 20px;
  margin-top: 20px;
  height: 30%;
}

.umbrella_icon {

  text-align: center;

}

.footer {
  z-index: 1000;
  width: 960px;
  margin: 0 auto;

}
    <div class="wrapper">
<div class="page2">

  <h2>Blog</h2>

  <div class="wrap">

    <div class="card">
      <a href="welcome.html">
      <img class="card-img" src="str3.jpg">
    </a>
      <div class="card-text">
        <h3><a href="welcome.html" id="card-link">Welcome</a></h3>
        <p>Website Launch and my First Project</p>
      </div>
    </div>

    <div class="card">
      <a href="blog.html">
      <img class="card-img" src="steve_roe_kyoto.jpg">
    </a>
      <div class="card-text">
        <h3><a href="blog.html" id="card-link"> Kyoto</a></h3>
        <p>My Recent Trip</p>
</div>
  </div>

    <div class="card">
      <a href="best.html">
      <img class="card-img" src="str4.jpg">
    </a>
      <div class="card-text">
        <h3><a href="best.html" id="card-link">Best of 2018</a></h3>
        <p>Neon Goodness from Last Year</p>
      </div>
  </div>
    </div>


<div class="page3">
  <footer>
  <div class="umbrella_icon">
  <img src="umbrella-02.png" alt="umbrella">
  </div>


    <div class="logo_footer">Steve Roe</div>
      <div class="footer_menu">
  <ul class="ul_footer">
    <li><a href="work_with_me.html">Work With Me</a></li>
    <li>
<a href="xxxxxxxxxxxx.com">Contact</a></li>
  </ul>

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

Answer №2

Finish The second page div before beginning the third page div. Modify the page3 css to .page3{

margin: 50vh 50vw; }

  <h2>Blog</h2>

  <div class="wrap">

    <div class="card">
      <a href="welcome.html">
      <img class="card-img" src="str3.jpg">
    </a>
      <div class="card-text">
        <h3><a href="welcome.html" id="card-link">Welcome</a></h3>
        <p>Website Launch and my First Project</p>
      </div>
    </div>

    <div class="card">
      <a href="blog.html">
      <img class="card-img" src="steve_roe_kyoto.jpg">
    </a>
      <div class="card-text">
        <h3><a href="blog.html" id="card-link"> Kyoto</a></h3>
        <p>My Recent Trip</p>
</div>
  </div>

    <div class="card">
      <a href="best.html">
      <img class="card-img" src="str4.jpg">
    </a>
      <div class="card-text">
        <h3><a href="best.html" id="card-link">Best of 2018</a></h3>
        <p>Neon Goodness from Last Year</p>
      </div>
  </div>
    </div>
</div>

    <div class="page3">
      <footer>
      <div class="umbrella_icon">
      <img src="umbrella-02.png" alt="umbrella Here">
      </div>


        <div class="logo_footer">Steve Roe</div>
          <div class="footer_menu">
      <ul class="ul_footer">
        <li><a href="work_with_me.html">Work With Me</a></li>
        <li>
    <a href="xxxxxxxxxxxx.com">Contact</a></li>
      </ul>

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

Answer №3

To center an image horizontally, utilize the flex property for .wrap as shown below:

.wrap{
   width:960px;
   margin:auto;
   margin-top: 100px;

   display: flex;
   justify-content: center;
}

By using this code snippet, the image will be positioned at the center horizontally.

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

Avoid shifting focus to each form control when the tab key is activated

I have a form where users need to be able to delete and add items using the keyboard. Typically, users use the tab key to move focus from one element to another. However, when pressing the tab key in this form, the focus only shifts to textboxes and not t ...

Issues with padding and margin on iOS devices

On my iPhone (iPhone 6, iOS 8), I noticed that the loader is positioned slightly above the button. However, when I use the Chrome mobile emulator, I can't see this issue. I'm puzzled about how to resolve it. What do you think could be causing thi ...

What is the best way to style only numbers using CSS in jQuery?

Here is some HTML code that needs styling: <tr> <td>Test</td> <td>324</td> </tr> The default CSS setting is text-align:left However, I am looking to apply text-align:center to any <td> element that contai ...

PHP code for sending email with attachment file

I have created an HTML form with the option to upload a file and send it to me via email. Additionally, I already have a PHP script that sends textbox values and text area values via email. Now, I would like the uploaded file from the form to be sent to m ...

What is the best way to replicate tags in selenium when an element has multiple class names?

Extracting information from a webpage where a significant amount of text was concealed behind the "see more" tab. Using selenium to click on all such buttons and then extracting data with beautifulsoup. However, some of these buttons have additional space ...

Is it possible for me to generate a fresh webpage by incorporating a new jsp file into the current web project?

Is it possible to create a new web page by adding a new jsp to an existing web project? I would like to create a new webpage while reusing the resources from the old web project such as java class files. Furthermore, I want both websites to be able to ac ...

take a paragraph element outside of a container div

In my ASP project, I have incorporated JavaScript and CSS code that I obtained from JonDesign's SmoothGallery demo website. Now, I am trying to move the p tag containing the summary out of the div. Here is the current code snippet: <div id="myGall ...

Semi-transparent navigation bar with dropdown functionality

Trying to create a Bootstrap menu similar to the one on I've made progress, but I can't seem to achieve a completely transparent effect on hover. In my fiddle below, there always seems to be a hint of grey in the dropdown when hovered over. I& ...

Fluid Design - Extra Spacing at the Bottom with Percent Margin-Top

Currently, I am working on developing a website using only percentages. However, I have encountered an issue with my main content section. I have set a margin-top of 10%, but this is causing excessive spacing at the bottom of the page and resulting in a sc ...

Displaying or concealing list elements in Angular 6

I am working on a simple Angular app that displays a list of items. I want the behavior to be such that when the first item in the list is clicked, its description (card) should be displayed. And, if the second item is clicked and its description is displa ...

Troubles with React Material-UI class names overlapping in library integration

Incorporated a library into our Creatives project that functions similarly to one of our existing pages. Upon interacting with a graph, I observed the generation of numerous empty <style data-jss> tags which override the current styling on the page. ...

Utilize fancybox to target and display related content through external links within tabs

My website features a stylish box with tabbed inline content, allowing users to navigate between different views by clicking on tab names. However, I want the tabbed content to be accessible when a user clicks on a navigation link to launch the box. For ex ...

Chrome does not support href while Edge does

href seems to be causing issues in Chrome, but it works fine on Microsoft Internet Explorer or Edge. It appears that the line (a href="....html")Something(/a) is not functioning properly on edge or safari. It behaves like a dropdown menu. There is a sig ...

Can elements be prevented from resizing in relation to another element without using position:absolute?

Is there a way to prevent elements in a <div> from moving when an adjacent element is resized, without using position:absolute? Any help would be greatly appreciated. Thank you in advance! ...

JavaScript code that activates several hovering elements

I am a beginner in the world of JavaScript and I'm attempting to create a simple function that will activate multiple div hover effects. I have tried various approaches so far, but I believe this code is closer to the solution. Any assistance from som ...

Is it beneficial to incorporate AJAX functionality into my PHP classes and scripts?

I recently started working on a PHP/AJAX website and I'm contemplating the best approach to "only include the content". Should I incorporate if statements in my header and footer scripts to check for a "ContentOnly" get parameter? Then, append that p ...

Is it possible to nest an array within a value of a Sass object?

I'm currently attempting to incorporate an array within the value of an object. $background-things: ( 'a': ['100vh', 'transparent', 'column'], 'higher': ['70vh', '#000', &ap ...

Bootstrap link causing alterations to my CSS code

After incorporating Bootstrap into my HTML, I noticed that it caused some unexpected changes to my CSS code. Original CSS: https://i.stack.imgur.com/EsE6J.jpg Modified CSS after applying Bootstrap: https://i.stack.imgur.com/yH1r9.jpg Link to Bootstrap ...

Although AJAX $.post functions properly in the View, it seems to encounter issues when relocated to a separate .js file. Interestingly, all other JQuery functions work

I have recently delved into MVC, JQuery, and AJAX, and encountered a perplexing issue. After completing the initial development of a practice website, I dedicated time to enhance the interactivity using JQuery. Everything was functioning smoothly until I ...

Is there a way to create a responsive navbar using flexbox that automatically transitions into two rows at smaller screen sizes?

I've designed a sleek navbar located at the bottom of my webpage featuring a central logo leading to the home page, with two links on each side directing users to specific pages. Using @media CSS, I made it responsive by reducing its size as the scree ...