Reorganizing content under an image as the browser is resized by implementing a media query

In the footer section of my document, I have text positioned next to an image (floated to the right). However, when I resize my browser to a minimum width of 768px, both the text and image lose alignment. My goal is to centralize both elements with the image above the text, but I'm struggling to achieve this.

Below is an example of what I am trying to accomplish along with my current code:

HTML :

<div id="wrapper">
    <footer id="page_footer">
       <p>Thanks for visiting</p>
         <a href="#" target="_blank"><img alt=
        "nffc_logo" src="images/logo.png"></a>
    </footer>
</div><!-- wrapper -->


CSS :

 #page_footer {    
     width: 100%;
     height: auto;
     position: absolute;
     bottom:0;     /*sticky footer*/
     left: 0;  
     background: #282828;
     color: white;
}
#page_footer img {
     max-width: 3%;
     height:auto;             
     margin: 5px;
     float:right;                               
}             
#page_footer p {
     float:right;
     margin-right: 10px;
     margin-left: 1px;             
}


and then an empty media query :

@media screen and (min-width:768px) {  }

Answer №1

To enhance the structure, I have introduced a new container named .right-div to hold a link and paragraph. This container is set to float right using float: right;, eliminating the need to float its children (p and a). The children are now styled as inline blocks with width or max-width for improved positioning.

It's worth noting that styles have been applied to the a element, not the img.

You can view the demonstration HERE

Answer №2

Reordering your markup so that the image appears first followed by the <p> tag can simplify and solve the problem:

<div id="wrapper">
  <footer id="page_footer"> 
    <a href="#" target="_blank>
     <img alt="nffc_logo" src="http://www.jonathanjeter.com/images/Square_200x200.png" />
    </a>
    <p>Thanks for visiting</p>
  </footer>
</div>
<!-- wrapper -->

You can view a demonstration of this solution here

CSS

@media screen and (max-width:768px) {
    #page_footer {
        width: 100%;
        height: auto;
        position: absolute;
        bottom:0;
        /*sticky footer*/
        left: 0;
        background: #282828;
        color: white;
        text-align:center;
    }
    #page_footer img {
        max-width: 3%;
    }
    #page_footer p {
        margin:0 auto;
    }
}
@media screen and (min-width:768px) {
    #page_footer {
        width: 100%;
        height: auto;
        position: absolute;
        bottom:0;
        /*sticky footer*/
        left: 0;
        background: #282828;
        color: white;
        text-align:center;
    }
    #page_footer img {
        max-width: 3%;
        vertical-align:middle
    }
    #page_footer p {
        display:inline-block;
    }
}

How to align? To place the <p> next to the image, use the display:inline-block; method for alignment.

To stack one above the other, simply apply a margin.

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

Binding HTML Elements to JavaScript Values

Currently, I am working on a project with .Net and Vue. However, I am facing an issue in binding a value in a label. <li v-for="restaurant in vHolidays.data" > <form id="1"> <div> ...

What is the best way to ensure the box div is centered responsively?

Here is the code for my HTML file: body { background-color: rgb(231, 59, 59); font-family: "Alata"; font-size: 20px; margin: 30px; } h1 { margin-top: 100px; color: #202124; text-align: center; } .box { width: 1000px; } input { positi ...

What is the best way to link a file to index.html using feathers.js?

I am currently learning feathers and encountering a problem. I am attempting to include files similar to PHP's switch function. For instance: /src/middleware/index.js 'use strict'; const handler = require('feathers-errors/handler&ap ...

When using CSS border-width:1px, I notice that the borders aren't consistently thin

I'm attempting to add thin borders to a div. My CSS code is as follows: border: solid; border-width: 1px; However, the resulting borders appear unevenly thin in my browser. The borders on the left and bottom seem thicker than those on the right and ...

Guide to creating HTML file with SSI tags

Currently, my website uses Nginx SSI tags to dynamically include template files such as the header, footer, and sidebar. However, I need to provide the final HTML output to clients instead of running it on their browsers. The issue I'm facing is that ...

Is it possible to target the HTML element or root node using the nth-child selector?

During one of my teaching sessions, I was discussing the nth-child() pseudo-selector with a student. I posed the question: Can you use the nth-child selector to target any HTML element? The response I received was negative, as it is not possible to select ...

How can I ensure that I am only retrieving the first object within a "for loop" in vuejs and returning its value without getting the rest?

Why am I only able to retrieve the value of the first object in my "for loop" and not all three values as intended? var app = new Vue({ el: '#app', data: { myObj: [ {name: 'Hello', age: 10}, {name: ...

What is the best way to create a responsive grid layout for my form using Bootstrap?

I have designed a form using bootstrap 5 with 1 row containing 4 columns (1 dropdown menu and 3 buttons). While it looks fine on my desktop, the problem arises when I view the page on a mobile device. The buttons shrink and remain on the same row instead o ...

Navigate audio tracks with JavaScript

I'm currently facing an issue with using a button to switch between two audio tracks being played in the browser. The method I have implemented switches to the second track, but it doesn't change the audio that is played afterward - instead, it s ...

Use jQuery to switch out certain text with specified HTML elements

I am looking to use jQuery in order to dynamically wrap any text that matches a specific regular expression with a particular HTML tag. For instance: <div class="content"> <div class="spamcontainer"> Eggs and spam is better than ham and spam. ...

What could be causing the submit action to not work when using PHP's isset function?

This is an HTML registration form with a PHP action triggered by the submit button. <html> <head> <title>Registration Form</title> </head> <body> <h1 align="center"> REGISTRATION FORM </h1> <form ...

What steps should be taken to enlarge a checkbox within a table?

I need help with resizing the checkboxes that are inside a table. When I try using width:###px; height:###px;, it only seems to make them smaller, not bigger. Even when I set the values higher than the default size, the checkboxes stay the same while the d ...

Tips for safeguarding against the insertion of scripts into input fields

Is there a method to stop users from inputting scripts into text fields or text areas? function filter($event) { var regex = /[^a-zA-Z0-9_]/; let match = regex.exec($event.target.value); console.log(match); if (match) { $event.pre ...

Struggling with z-index or float issues on Chrome and Safari with CSS styling

Check out my website at I have incorporated the Easy Slider 1.7 plugin from this source and made some custom JavaScript modifications for a banner rotator. The issue I am facing is that on webkit browsers, the navigation links (1,2,3,4,5) on the banner a ...

When the FLASK button is triggered, retrieve data from the FLASK and display it

This is a unique test where I will create a button to retrieve information from a MySQL database. However, it's important to first understand this concept. So here is my custom text within the Flask framework: @app.route('/pythonlogin/home', ...

Form Validation Issues Detected

Could someone help explain why the code below is causing an error according to W3C guidelines: <form id="" method="post" action="" /> <input type="text" name="" title="" tabindex="10" class="" /> <inp ...

quickest method for accessing the selected radio button using jQuery

I'm trying to use jQuery to retrieve the selected radio button and display the text associated with that radio button. <div id="Poll"> <div id="PollQuestion">Your favorite color?</div> <ul> <li class="liAnsw ...

There are two different ways to set a hyperlink in HTML. One method is by using the href attribute, where you provide the URL inside the quotation marks. The other

While browsing, I stumbled upon this interesting piece of JavaScript code: onClick="self.location.href='http://stackoverflow.com/'" I incorporated this code into my website, and it seems to have the same effect as using the href attribute. Sin ...

Dynamic background rectangle tilted at a 45-degree angle overlays an image

I have a challenge to create a 45-degree rotated square inside a square container, making sure it is responsive. Here's the code I have come up with so far: <div class="container"> <figure> <img src="https://placekitten.com/500 ...

How can I manage file input within a Vue.js application?

After attempting to open a file input with a button, I encountered an issue. When clicking the button, the client reported: “this.$refs.image.click”. Below is my code snippet: <v-btn height="50" ...