Tips for positioning buttons in the bottom corner of a webpage while ensuring they are responsive

Currently working on this website as a personal side project, focusing on making it responsive. This is my first attempt at creating a responsive webpage, and I have successfully figured out most aspects except for the positioning of the social media buttons. I aim to have them located in the bottom right corner of the page while ensuring responsiveness. However, every time I resize the window, the buttons start to move upwards. Below, I have included my HTML and CSS code. Any assistance provided is greatly appreciated.

Despite my efforts using flexbox, bootstrap, and grid, I have not been able to achieve the desired result. Additionally, I find myself a bit confused about which CSS properties to apply in this scenario.

HTML:

    <!DOCTYPE html>
    <html>
    <head>
       <meta charset="utf-8">
       <meta name="viewport" content="width=device-width">
       <title>Giphy Search</title>
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"integrity="sha384ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2Zw1T" crossorigin="anonymous">

       <link href="Style.css" rel="stylesheet" type="text/css">
    </head>

    <body>
       <div id="fb-root"></div>
       <script async defer crossorigin="anonymous"
        src="https://connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v4.0"> 
       </script>

       <div id="imgLogoDiv">
          <img id="imgLogo" src="/img/logo.png" alt="unable to load image">
       </div>

       <div id="divTxtField">
          <input type="text" id="search" placeholder="Search for a gif!">
       </div>

       <div id="bs-divSearchButton">
          <button id="bs-Button" type="button" class="btn btn-dark">Search</button>
       </div>
       <br>

       <div id="GifDisplay">
          <img id="gif">
       </div>

       <div id="socialMediaBottons"> 
           <div id="twitterButton">
               <a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-size="large"
        data-text="Search for a Gif!" data-show-count="false">Tweet</a>
               <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
           </div>

           <div id="fbButton">
              <div class="fb-share-button" data- 
  href="https://www.facebook.com/GIPHY/" data-layout="button" data-size="large"><a target="_blank"
          href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;src=sdkpreparse"
          class="fb-xfbml-parse-ignore">Share</a></div>
             </div>  
          </div>

         <script src="JS/script.js"></script>
      </body>

     </html>

CSS:

body {
    background-image: url(img/background.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center center;
    background-attachment: fixed;
}

#imgLogoDiv {
    display: flex;
    justify-content: center;
    height: auto;
    /*height: auto
    Not sure if I should keep this since it seems to have to effect.*/
}

#imgLogoDiv #imgLogo {
    width: 45%;
    height: auto;
}

#divTxtField {
    display: flex;
    justify-content: center;
    position: relative;
    top: 20px;
    padding-bottom: 1%;
}

#divTxtField #search {
    border-radius: 25px;
}

#divTxtField #search:hover {
    cursor: auto;
}

#bs-divSearchButton {
    display: flex;
    justify-content: center;
    position: relative;
    top: 20px;
    padding-bottom: 20px;
}

#bs-divSearchButton #bs-Button:hover {
    cursor: pointer;
}

#socialMediaBottons{
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    height: 50vh;
}

#GifDisplay {
    display: flex;
    justify-content: center;
}

Image link to website showing buttons

Answer №1

This tip is sourced from the Flex section of Bootstrap 4 documentation.

Following the recommendation, I included flex classes d-flex justify-content-end to the #socialMediaButtons div and removed similar styling from your CSS.

Below is the updated HTML section:

<div id="socialMediaButtons" class="d-flex justify-content-end"> 
    <div id="twitterButton">
      <a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button" data-size="large"
        data-text="Search for a Gif!" data-show-count="false">Tweet</a>
      <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
    </div>

    <div id="fbButton">
      <div class="fb-share-button" data-href="https://www.facebook.com/GIPHY/" data-layout="button" data-size="large"><a
          target="_blank"
          href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;src=sdkpreparse"
          class="fb-xfbml-parse-ignore">Share</a></div>
    </div>  
  </div>

The CSS block now only includes the height attribute:

#socialMediaButtons{
    height: 50vh;
}

With this adjustment, the buttons are now evenly aligned. Check out the image for reference:
aligned buttons


For more information, please refer to the following resources:

Bootstrap 4 Flex: https://getbootstrap.com/docs/4.0/utilities/flex/

Answer №2

While Flexbox is a great tool, it may not be the best solution for this particular task.

To achieve the desired layout with the social buttons in the bottom corner, consider using either absolute or fixed positioning. It is important to ensure that the body element has position:relative set.

body { position:relative }
#socialMediaBottons { position:fixed; bottom:10px; right:10px; }
#fbButton, #twitterButton { display:inline-block; }

By implementing this approach, the social buttons will always maintain a set distance from the bottom right corner regardless of the viewport size. Feel free to adjust the values of bottom and right to suit your design preferences.

Answer №3

To enhance your webpage design, you can implement the following CSS:

.socialMediaButton{
    display: inline-block;
    margin: 5px;
}

.socialMediaButtons {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: flex;
}

View the live demonstration here.

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

Using PHP to create multiple div elements and then concealing them all

I'm having an issue with the hide feature not working. My intention is to hide each dynamically generated div and gain control over them, but the problem seems to lie in the div id incrementing. Any assistance would be greatly appreciated! <?php $ ...

Iterating through children of the target element using the .each() method in jQuery

Currently, I am looping through the elements and extracting the src attribute from the child element. This is the snippet of HTML code that I am working with: <noscript data-alt="super awesome"> <img src="http://farm9.staticflickr.com/8235/85 ...

Glitch discovered in the if statement implementation in PHP and HTML

<img id="post_like_btn_<?php echo $post_info['id']; ?>" class="post_like_btn" <?php $like_result = data_like($dbc, $user_info['id']); while($like_info = mysqli_fetch_assoc($like_result)){ if($post_info['id' ...

The Bootstrap star-rating display duplicated on the page

I have integrated a plugin to display star ratings on my Bootstrap website. Here is a snippet of the modal code where I have included the star rating input element: <div class="modal-header"> <button type="button" class="close" dat ...

How can I utilize the Facebook API on Tizen to share a video?

Could someone please provide guidance on how to incorporate video uploading functionality into a Tizen application using the Facebook API and HTML5? ...

Troubleshooting a problem with dynamic options in Materialize select set

I'm currently facing an issue with my two dependent dropdowns, country and state. When I select a country, I use JavaScript to populate the respective states in the state dropdown. However, even though the options are added correctly when I inspect th ...

Ways to eliminate the default margin surrounding an image within a div

Struggling with CSS while building websites is a common issue for me. In my current project, I have encountered a challenge where I placed two images inside a div container. Oddly enough, when I add text to the div, it adjusts its height accordingly. How ...

The Opera browser displays a horizontal orientation for vertical menus

Having some trouble with my vertical menu rendering correctly in different browsers. It's appearing horizontal in Opera, but looks good in Firefox and Chrome. I'm pretty sure it's just a small tweak needed in the code, but I can't quite ...

Tips on obtaining the element selector when a div is being dynamically loaded during an AJAX call

When running two ajax calls, I encounter an issue where the second call loads some HTML onto the page that is needed for processing a specific div in the first call. However, since the div is not present until after the second call is completed, I receiv ...

Attempting to display a brief description when hovering over a particular project image

My goal on is to display a description when hovering over a portfolio image by setting the opacity to 1. However, this functionality seems to not be working. .description { display: block; opacity: 0; text-align: left; height: 130px; padding- ...

Guidance on transferring servlet variables to an HTML page through redirection in Java

I am looking for a way to open an HTML page from my Java servlet and utilize the variables of that servlet to populate the form fields in the HTML page when it is opened. Below is the code snippet of my servlet: import java.io.*; import java.sql.*; impor ...

What could be causing Prettier code formatter to suddenly stop formatting in VS Code?

I've been having trouble formatting my code using Prettier in VS Code. Even after reinstalling it, the issue persists and I can't seem to format my HTML/CSS code properly. The screenshot I provided shows that the code remains unformatted even aft ...

Placement of Buttons Inside a Division Tag

Is there a better way to align button 3 & 4 in a vertical column next to button 1 & 2 without using tables in CSS? See the working example below: https://jsfiddle.net/Jaron787/0te3cs66/1/ Code: HTML <div id="lse" class="display"> <di ...

Clicking on a specific month results in displaying only one row from the database rather than showing all rows associated with that particular month

I am facing an issue with my calendar feature on the website. The problem is that when I click on a specific month, it should display all the data associated with that particular month. However, the current code does not seem to work as expected. For insta ...

Guide to personalizing checkbox design using react-bootstrap

I am working with react-bootstrap and attempting to style a custom checkbox, as it appears possible but is not working. I have followed the documentation provided here. Here is the code snippet: import * as React from "react"; import { t as typy } from & ...

Tips on defining the specific CSS and JavaScript code to include in your Flask application

I am currently working on a web application using Flask and I need to specify which CSS and JS files should be included in the rendered HTML page based on a condition. There are times when I want to include mycss1.css and myjs1.js: <link href="/sta ...

Why isn't it working? Looking for a script that adds a class when the element is empty?

I have a script that should add the class "leftmax" to the li element with id "spect" when the div element with id "tab2" is empty, but it doesn't seem to be working. Can someone provide some assistance? <script type="text/javascript"> $(funct ...

What is the best method for adjusting the width of a LengthMenu in dataTables?

Is there a way to increase the width of this drop-down menu? It seems too small, especially when selecting 10. https://i.sstatic.net/ObqBA.png ...

Injecting navigation bar onto an HTML page using jQuery

After being a dedicated user of ASP, I have made the decision to switch to a Linux-based server for my website. However, as I begin to build my site, I am facing challenges that were once simple in ASP - such as loading a constant navigation bar. My objec ...

jQuery UI smooths out the transitions, making the effect more gradual and fluid

Is there a way to make my toggle sidebar scroll smoothly using jQuery UI? Currently, it has a jerky behavior and I would like it to have a smoother left/right effect. I want the outer shell to slide smoothly just like the inner container does, instead of ...