Adjusting layout to second row based on screen width using CSS media query

My div contains the following elements:

<div>
    <a class="postLink" href="{{post.authorLink}}"  target="_blank">{{post.author}}</a>
    <span class="">Published: {{ post.published}}</span>
    <a class="postLink" href="{{post.link}}"  target="_blank">View More</a>
</div>

By default, the rendering looks like this:

{{post.author}}   Published: {{ post.published}}   View More

If the screen width is less than 760px, how can I reposition all the links to the second line?

Published: {{ post.published}}   
{{post.author}}   View More  

Answer №1

If you're looking to achieve a responsive design, one approach is to use relative positioning for the container and absolute positioning for the span within a media query. However, I have an alternative solution that I find more intriguing:

.postInfo a {
    margin-right: 20px;
}
.postPublished::after {
    content: attr(data-published);
    display: inline-block;
    margin-right: 20px;
}

@media (max-width: 780px) {
    .postPublished::after {
        display: none;
    }
    .postPublished::before {
        content: attr(data-published);
        display: block;
    }
}
<div class="postInfo">
    <span class="postPublished" data-published="Published: {{ post.published}}">
        <a  class="postLink" href="{{post.authorLink}}"  target="_blank">{{post.author}}</a>
    </span>
    <a class="postLink" href="{{post.link}}" target="_blank">View More</a>
</div>

Feel free to test it out yourself on JSFiddle.

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

Ensuring consistent column heights in Bootstrap across all devices

There is an HTML element containing an image and text positioned side by side using Bootstrap. Here is the code: <div class="row"> <div class="col-md-6"> <div class="avatar"> <img src="<?= get_template_directory_uri(); ...

Adjusting image size to accommodate responsive column cell using CSS

I've been working on optimizing my mobile website using a responsive column layout. The challenge I'm facing is getting the images within each column to stretch to 100% width while automatically adjusting their height. I experimented with settin ...

Customize default progress bar in browsers

One feature of my website allows users to update their personal information, profile image, background image, and more. After clicking the submit button, a loading screen appears with a progress percentage displayed at the bottom left corner of the page (i ...

The body element is not positioned at the top of the webpage in the HTML/CSS layout

I'm running into an issue with my HTML/CSS. It seems like my body tag has unexpectedly acquired a margin-top of 10px... However, I've searched high and low but can't seem to figure out how to remove it. This is something that has never happe ...

When a div is floated to the left and another div is floated to the right, the

I would like the footer to display an image aligned to the left and some additional text (an inline ul with links) aligned to the right within the footer. Here is the CSS & HTML: footer { clear: both; background: #113551; width: 90%; ma ...

Adjusting animation placement when resizing the window

Is it possible to utilize jquery window.resize() to ensure that the positioning of the two donuts never interferes with the text in the middle of the home? I am unsure of how to connect the x and y values of the window size to adjust the top/left and botto ...

Avoid jQuery ContextMenu Submenu Items from Expanding in Size on Mobile Devices

Recently, I started using the jQuery contextMenu which can be found at . The issue I encountered involves a menu with a submenu. Whenever I try to access the submenu items on mobile Safari or Chrome, the size of the menu items suddenly doubles and gets cu ...

Icons disappear from the navbar toggle when clicked on a small screen

Using Django and Bootstrap 4, I've created a navbar with a toggle feature. However, when viewed on a small screen, the toggle button does not display the icons as expected. Instead, it shows empty lines. Strangely, when the phone is rotated, the toggl ...

I am encountering an issue while running npm run webpack in production mode where the CSS file is not being generated separately in the dist folder as expected. The file is not appearing as it should

Here is the code snippet from my webpack configuration file: const currentTask = process.env.nmp_lifecycle_event const path = require("path") const MiniCssExtractPlugin = require('mini-css-extract-plugin') const config = { entry: './ ...

Tips for placing a background color *behind* a bootstrap button

When a button is clicked, I want to display an input with a background surrounding both the button and the input. Currently, my markup renders like this: https://i.sstatic.net/rxaPt.png So when the button is clicked, I need a yellow (alert-warning) backg ...

Troubleshooting issues with the IE flexible box model functionality

Working on incorporating the flexible box model into my website has been a bit challenging. It seems to function well in webkit-based browsers like Chrome and Safari, but I'm running into issues with Mozilla, Opera, and most notably Internet Explorer. ...

Explore all dropdowns in Bootstrap by hovering over them

I am looking to have all my dropdown menus appear on hover in any of the menu items. I currently have this code snippet: ul.nav li.dropdown:hover ul.dropdown-menu{ display: block; } The problem is that it only works for one menu item at a time, d ...

Counting the number of visible 'li' elements on a search list: A guide

In the following code snippet, I am attempting to create a simple search functionality. The goal is to count the visible 'li' elements in a list and display the total in a div called "totalClasses." Additionally, when the user searches for a spec ...

Arranging inline-flex elements within a div container

I have been struggling to position two elements side by side within a single div, where the second element should be on the right side. <div className={classes.container}> <div className={classes.first}> First </div> <d ...

When combining li, radio-input, and label, there is no padding at the top

I am facing an issue with the padding at the top of my list items. Here is a link to a working Fiddle: [http://jsfiddle.net/TH3zq/9/][1] http://jsfiddle.net/TH3zq/9/ Can anyone suggest a CSS style solution for this problem? Thanks, John ...

Switching the horizontal tab design from Bootstrap 3 to Bootstrap 4

I'm currently working on adapting a code snippet from bootsnip that creates horizontal Bootstrap tabs with material-style design. I've encountered some challenges in converting it to Bootstrap 4, specifically in updating the CSS to use .nav-item ...

Collapse the mobile nav bar upon clicking an item

I'm currently facing a challenge with the navigation bar on my event landing page. The issue is that when I open the navbar in mobile view, it does not collapse back after clicking on an item. Instead, it remains open and covers almost 3/4 of the scre ...

Is it possible to conceal the Google recaptcha badge using CSS and show the legal text in its place instead?

We have successfully hidden the Google reCaptcha badge on our website using CSS: <style> .grecaptcha-badge { visibility: hidden; } </style> As a result, there is now an empty space where the reCaptcha badge used to be display ...

iOS devices experiencing issues with fixed positioning

Currently, I am in the process of implementing a few instances of , but I am encountering some issues with the CSS. When viewing the website on an iPad or iPhone, the calendar is positioned correctly as the container covers the window like a fixed position ...

Center div encroaching on floated left div

https://i.sstatic.net/uwyGY.pngCan someone help me align three divs horizontally? I'm having an issue where the center div is overlapping the left div. What could be causing this problem? <div> <div style={{width:"100px", ...