Change the location of an HTML element within the page structure

Let's consider having 3 elements like this:

<h1>Hello</h1>
<p>hello</p>
<h1>Hello</h1>

I am looking to remove the second <h1> as I only want it to appear once on the page. However, I would like to have flexibility in changing the position of the <h1>. On mobile view, it should be displayed below the <p> and on desktop above. I am aware that this can be achieved with bootstrap/display:none;, but I prefer to adjust the position of a single <h1> based on the scaling of the pages.

Thank you very much for your assistance!

Answer №1

To accomplish this, you have the option of using either flexbox or grid layout. Here's an example using flexbox. If you only want to contain two items, such as <h1> and <p>, you can simply set flex-direction: column-reverse; in the media query instead of changing the order of the elements.

.wrapper {
  display: flex;
  flex-direction: column;
}
.heading {
  order: 1;
}
.text {
  order: 2;
}
@media screen and (max-width: 480px) {
  .heading {
    order: 2;
  }
  .text {
    order: 1;
  }
}
<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
  <div class="wrapper">
    <h1 class="heading">Hello</h1>
    <p class="text">hello</p>
  </div>
</body>
</html>

Answer №2

experiment using the order property along with a media query

@media(max-width:767px){
  .title-section{
    display:flex;
    flex-direction:column;
  }
  h1 { 
    order: 2;
    }  
  p {
     order: 1; 
  }
  
}
<div class="title-section">
<h1>Hello Heading Tag</h1>
<p>hello P Tag</p>
</div>

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

"How to retrieve data from a nested object in MongoDB by referencing variables

I am facing an issue with accessing nested objects using a variable in the npm package mongojs. Despite my efforts, the code snippet below is not working as expected: let userID = req.user._id, marketName = req.body.marketName, itemNam ...

Error message received from Express middleware: "Unable to modify headers after they have been sent."

I have created middleware for my Node Express app to perform the following tasks: Checking all incoming requests to determine if they are from a bot Allowing requests for raw resources to proceed Serving an HTML snapshot if the request is from a bot How ...

Ensuring proper execution of the next callback function in an Express get request

I am currently running an express server on nodejs with a specific file structure that I need to convert into a list of links. Included below are my recursive functions for dealing with the file structure. Here are the file structure functions: function ...

How can I utilize the parseFloat feature within my dedicated parseFloat function located in an angular factory?

What is the solution for accessing parseFloat within an angular factory function named parseFloat? angular .module('myApp') .factory('mathService', [MathService]); function MathService() { return { parseFloat: myGl ...

Next.js has a problem where it displays incorrect data when users navigate rapidly between pages

An unusual challenge has emerged while rendering data on a Next.js page in my application. Here's the scenario: I've created a Next.js page that showcases customer details based on a query parameter called cid. The page retrieves customer data an ...

What is the best way to symbolize a breadcrumb offspring?

In my table representation, the breadcrumb is shown as: <ol class="breadcrumb" data-sly-use.breadcrumb="myModel.js"> <output data-sly-unwrap data-sly-list="${breadcrumb}"> <li itemscope itemtype="http://data-vocabulary.org/ ...

Using R Markdown and Hugo to Style Blog Titles

I am currently utilizing Hugo and Blogdown to craft a blog following the guidelines outlined here. The title of my blog is specified at the beginning of each post, resembling the example below: --- title: One Two Three author: First Last date: '2019- ...

Is there a way to merge all this data into a single Object?

This particular situation is quite complex. Let's consider the following scenario: I have two JavaScript objects that are fetched via REST calls, using two different callbacks. So, we have: call1() - POST method - parsed JSON to JavaScript object, ...

Signing out in React js

Hey everyone! I'm facing an issue. I have to create a logout form on React js that redirects to loginindex.html from hello.ejs and clears some variables using server.js, but I'm not sure how to do it =( Can anyone offer some guidance? Thank you! ...

Creating form inputs dynamically in HTML and then sending them to a PHP script programmatically

On my webpage, users can click a button to add new form inputs as needed. However, I'm running into an issue trying to access these new inputs in the PHP file where I submit the data. Here is the code snippet for the button within the form on the pag ...

Discover the Elements that have been incorporated through the use of JavaScript

I am facing an issue with my ASP site where users can add Label elements. The problem is I am not able to track the labels that were added or their IDs. All I know is that they will be inside the Panel called pnl_Added. Once the user has finished adding la ...

Email Template not rendering properly across various platforms

Dealing with a frustrating issue here. I created a template using Foundation's E-mail features and it looks perfect in Chrome's Device mode as well as in MailChimp. However, when testing it in Litmus and sending it to my own email, things start t ...

Avoiding the use of numbers in v-if in Vue.js

My website features a left menu that displays different content based on the selected menu's ID. However, I currently have === 0 and === 1 in the v-if statement, and I'm looking for a way to avoid manually inputting these numbers. <template& ...

The element type provided is not valid: it is expected to be a string (for built-in components) or a class/function (for composite components) but instead it is undefined. This error

I am encountering an error of Element type is invalid: expected a string (for built-in components) or a class/function (for composite components). It seems like I may have forgotten to export my component from the file it was defined in, or there could be ...

Utilizing LocalStorage in an Ionic application to store data on a $scope

Having trouble saving the array named $scope.tasks to LocalStorage while building a To Do List app. Tried multiple times but can't figure it out. Here's the code, appreciate any help :^) index.html <!DOCTYPE html> <html> <head& ...

How can the error within a promise be captured when using resolve()?

Check out the code snippet below: userUpdate(req: Request, res: Response) { this.userTaskObj.userUpdate(req.params.id, req.body).then(() => { res.status(200).json({ status: 'OK', message: 'User updated', ...

The Dilemma of jQuery Dragging and Resizing Clash

I have implemented the Gridster Plugin() in my project. I discovered an updated demo on Github which includes resizable functionality. To ensure compatibility with future items, I have also integrated the jQuery livequery plugin. However, I am facing an i ...

What is the process for opening a local HTML file in IE compatibility mode?

Having issues with IE compatibility mode while opening my HTML file on desktop. In IE8, unable to switch it to compatibility mode as the icon seems to disappear in local HTML documents. Any insights on this? LATEST UPDATE: Tried three solutions but still ...

Error Encountered: Angular - Despite successful $http.delete request, the operation does not actually take

I am currently facing an issue with deleting a customer in my Angular + PHP application. Although the application returns success without any errors, it fails to delete the customer from the database. Here is the code snippet of my Angular controller: ...

Populate the dropdown menu with data from a JSON file

Recently, I created a custom JSON file and wanted to populate a select>option using this data. However, I encountered an error message saying: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///C:/.../p ...