Creating a button that adjusts its size proportionally to the page and surrounding elements, all without relying on positioning

I'm fairly new to creating websites with CSS and HTML, and I'm currently working on a project about my time in China. The main issue I'm facing right now is aligning a button with my other contact icons and ensuring it scrolls correctly with the rest of the page. I came across a CSS style for the button that I really like, but I'm struggling to make it the same height as the other icons and center it horizontally. I've tried adjusting margins, but I can't seem to get it right. Changing the position just seems to mess with the scaling. If anyone could help me out with this, I'd really appreciate it. I can provide a js fiddle with the code as well.

Here is the HTML & CSS code:

.Social {
  margin-top: 1%;
  margin-left: 29.3%;
}

.Pop {
  margin-left: 0.8%;
  margin-right: 0.8%;
  width: 6%;
  transition: all .3s ease;
  -moz-transition: all .3 ease;
  -ms-transition: all .3s ease;
  -webkit-transition: all .3s ease;
  -o-transition: all .3s ease;
}

.Pop:hover {
  -moz-transform: scale(1.1);
  -webkit-transform: scale(1.1);
  -o-transform: scale(1.1);
  -ms-transform: scale(1.1);
  transform: scale(1.1);
  -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand')";
  filter: progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand');
}

.button {
  background-color: #4CAF50;
  /* Green */
  border: none;
  color: white;
  margin-left: 2%;
  padding: 1% 4%;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 80%;
  font-family: "eraslight";
  -webkit-transition-duration: 0.4s;
  /* Safari */
  transition-duration: 0.4s;
  cursor: pointer;
}

.button5 {
  background-color: white;
  color: black;
  border: 2px solid #555555;
}

.button5:hover {
  background-color: #555555;
  color: white;
}
<div class="Social">
  <img alt="snap circle" class="Pop" src="https://image.ibb.co/cHB5SU/SnapPop.png">

  <img alt="Insta circle" class="Pop" src="https://image.ibb.co/eOtkSU/InstaPop.png">

  <img alt="Wechat circle" class="Pop" src="https://image.ibb.co/dppEMp/WePop.png">

  <img alt="Linkedin circle" class="Pop" src="https://image.ibb.co/effAu9/Linkedin_Pop.png">

  <img alt="Gmail circle" class="Pop" src="https://image.ibb.co/movbZ9/GmailPop.png">

  <button class="button button5"><h2>Résumé</h2></button>
</div>

Answer №1

To establish a specific height for the containing div and have its children inherit it, you can apply the following CSS properties to the container: display: flex; and align-items: center;

    .Social {
      display: flex;
      align-items: center;
      height: 40px;
      margin-top: 1%;
      margin-left: 29.3%;
    }

    .Social img, .Social button {
      display: inline-block;
      width: auto;
      height: inherit;
    }

    .Pop {
      margin-left: 0.8%;
      margin-right: 0.8%;
      width: 6%;
      transition: all .3s ease;
      -moz-transition: all .3s ease;
      -ms-transition: all .3s ease;
      -webkit-transition: all .3s ease;
      -o-transition: all .3s ease;
    }

    .Pop:hover {
      -moz-transform: scale(1.1);
      -webkit-transform: scale(1.1);
      -o-transform: scale(1.1);
      -ms-transform: scale(1.1);
      transform: scale(1.1);
      -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand')";
      filter: progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand');
    }

    .button {
      background-color: #4CAF50;
      /* Green */
      border: none;
      color: white;
      margin-left: 2%;
      padding: 0 4%;
      text-align: center;
      text-decoration: none;
      display: inline-block;
      font-size: 80%;
      font-family: "eraslight";
      -webkit-transition-duration: 0.4s;
      /* Safari */
      transition-duration: 0.4s;
      cursor: pointer;
    }

    .button5 {
      background-color: white;
      color: black;
      border: 2px solid #555555;
    }

    .button5:hover {
      background-color: #555555;
      color: white;
    }
    <div class="Social">
      <img alt="snap circle" class="Pop" src="https://image.ibb.co/cHB5SU/SnapPop.png">

      <img alt="Insta circle" class="Pop" src="https://image.ibb.co/eOtkSU/InstaPop.png">

      <img alt="Wechat circle" class="Pop" src="https://image.ibb.co/dppEMp/WePop.png">

      <img alt="Linkedin circle" class="Pop" src="https://image.ibb.co/effAu9/Linkedin_Pop.png">

      <img alt="Gmail circle" class="Pop" src="https://image.ibb.co/movbZ9/GmailPop.png">

      <button class="button button5">Résumé</button>
    </div>

The HTML structure remains unchanged, except for the removal of the unnecessary <h2> tags in your <button> text, which could affect vertical alignment in some browsers.

Answer №2

To adjust the vertical alignment of all your inline elements, use the vertical-align property.

img {
    ...
    vertical-align: middle;
}
.button {
    ...
    vertical-align: middle;
}

If you want your .button to match its neighboring elements better, consider removing the h2 tags, setting a fixed padding size, and using a fixed font size.

.button {
    font-size: 14px;
    padding: 5px;
    ...
}

<button class="button button5">Résumé</button>

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

Show a picture on top of another picture

Is there a way to overlay an image and text on top of another image, similar to what is done on this website ? ...

Z-Index Problem with PureCSS Horizontal Scrollable Menu

I've been working on this issue but can't seem to get it right. I have a purecss menu with a horizontal scrollable feature, but the submenus at depth 1 and 2 don't appear on hover in Firefox and Safari - they are being hidden underneath. I ...

Crafting an interactive form

Creating a form with 2 options (Yes/No) is my current task. When the user selects one of these options, I want a collapsible subform to appear with specific details related to that selection. If the user chooses the other option, a different collapsible su ...

What could be the reason for Python requests giving me a different text output compared to when I manually visit the website?

I'm in the process of creating a basic 'stock-checker' for a T-shirt that I have my eye on. The link to the product is available here: https://i.stack.imgur.com/usSJN.jpg Upon visiting the page, I noticed that it displays 'Coming Soon ...

Customize Google Chrome to display a vibrant splash screen instead of a boring white blank page when

"I've been on the lookout for Chrome apps that can help make my screen darker or inverted to reduce eye strain. While I have found some apps that do the job, there's one thing they don't seem to be able to override - the White Blank page. W ...

Is it possible to include aria-controls in an anchor tag?

My primary navigation includes some elements that may have a secondary navigation. In order to optimize accessibility on my website, I am seeking the most effective way to show/hide the secondary nav. After brainstorming, here is what I have come up with: ...

What is the best way to update the text on buttons once they've been clicked for a variety of buttons

I'm encountering an issue with multiple buttons where clicking on any button causes the text to change on the first button, rather than the one I actually clicked on. All buttons have the same id, and using different ids for each button seems impracti ...

HTML min-width is not being considered by the media query breakpoint

After resizing the browser window to less than 480px, my site reverts back to its original style (the css not defined inside the mixins). I attempted to limit the html with min-width, but despite the browser displaying a horizontal scrollbar, the css still ...

Google API integration in Chrome Extension Manifest

I'm seeking advice on how to modify my chrome manifest for an extension in order to enable communication between Google API servers and the application. The application functions properly when accessed directly (not as an extension). However, when lo ...

The issue of flickering while scrolling occurs when transitioning to a new page in Angular

I have encountered an unusual issue in my Angular 13 + Bootstrap 5 application. When accessing a scrollable page on small screen devices, the scrolling function does not work properly and causes the page to flicker. I observed that this problem does not o ...

Styling menus with CSS

I'm struggling with a CSS issue while attempting to add a 1px solid black line after each element in my drop-down table menu. The current appearance of my menu is causing some trouble. What I desire for it to look like involves applying border: 1px s ...

Ensure that each of the two divs maintains a 16:9 aspect ratio, and utilize one div to fill any remaining empty space through the

This layout is what I am aiming for: https://i.sstatic.net/uZdty.png While I can achieve a fixed aspect ratio with a 16:9 image by setting the img width to 100%, I run into an issue where the height scaling of flexbox becomes non-responsive. The height re ...

Darkening the background of HTML and CSS text to black

I'm having trouble removing the black background from the navigation. It doesn't appear to be styled in black when I inspect each element individually. Here is an image showing the issue: https://i.stack.imgur.com/gvbn8.png @charset "UTF-8"; ...

Can I create personalized animations using Compass?

I am curious about how to convert this code into Compass mixins @-webkit-keyframes shake { 0% { -webkit-transform: translate(2px, 0px) rotate(0deg); } 10% { -webkit-transform: translate(-1px, 0px) rotate(-1deg); } 20% { -webkit-transform: tran ...

Creating a mechanism that fetches web links and automatically substitutes the URL with the corresponding title of the webpage

Just the other day, I noticed that putting a link in my profile resulted in it being replaced by the exact title of the question. This got me thinking, how exactly do they accomplish this? My hunch is that they achieve this by using ajax to send the link ...

Updating HTML5 localStorage value upon a click

Currently, I have implemented a countdown timer using the provided code snippet. To prevent the count from resetting upon page refresh or reload, I am utilizing local storage. However, if there is an alternative solution to achieve this functionality, I wo ...

Tips for implementing the same autocomplete feature across multiple form fields

Struggling to add multiple products and provide auto-suggest for each product name? You're not alone. It seems like the auto suggest feature is only working for the first product. Can anyone point out what's going wrong here? Here's my HTML ...

Using the loop function within HTML in JavaScript with React

I'm trying to loop over my SliderComponent function with different inputs within the HTML to generate multiple components, but I can't seem to get it to work. I came across a solution online that involves building a string and returning it as HTM ...

What is the optimal resolution for a background image in a Cordova app?

Currently working on a Cordova application that requires different background images for various screens. Despite using media queries to provide the background image in different resolutions, we are facing an issue where the background image is not displ ...

Steps to create a custom function that can manage numerous onclick actions to toggle the visibility of a specific field

I'm relatively new to coding and JavaScript. I'm working on a basic webpage that involves showing and hiding parts of sentences for language learning purposes. Is there a way to create a single function that can show and hide the sentence when a ...