Options for making the Facebook Like Box responsive

I'm in the process of creating a responsive layout with unsemantic, and I want to adjust the settings on a Facebook Like box when switching between desktop, tablet, and mobile views. Essentially, I would like the options to change so that faces and post feeds are no longer displayed when the browser size is reduced.

At the moment, I am loading two separate like boxes and using CSS to show/hide them based on the browser width. However, I suspect there must be a more efficient method (as the website is still in early stages of development and these are just rough drafts)...

<div class="grid-100 tablet-grid-50 hide-on-mobile">
    <div class="fb-like-box" data-href="https://www.facebook.com/myurl" data-colorscheme="light" data-show-faces="true" data-header="true" data-stream="true" data-show-border="false"></div>
</div>
<div class="hide-on-desktop hide-on-tablet mobile-grid-100">
    <div class="fb-like-box" data-href="https://www.facebook.com/myurl" data-colorscheme="light" data-show-faces="false" data-header="false" data-stream="false" data-show-border="false"></div>
</div>

I have set up jQuery to trigger an event whenever a breakpoint is reached, and my idea is to use this to modify the Like Box's settings and refresh it. I assume this is feasible, as the Facebook developer page adjusts its layout during configuration.

Therefore, my question is - is there a way to only use one Facebook Like box and alter its settings using JQuery when browser size events occur? If so, would this be a more effective approach?

(Please note, the script for changes may not run frequently since the browser size is likely fixed, but it could be triggered by transitioning from portrait to landscape mode on a tablet)

Answer №1

Using jQuery may not be necessary, as CSS often provides better performance. To hide a div based on the width of the page in pixels, you can add the following code to your CSS file:

@media (max-width: (###-1)px)    
{    
    div.hide-on-desktop
    {
        display:none;
    }
    div.hide-on-mobile
    {
        display:block;
    }
}

@media (min-width: ###px)    
{    
    div.hide-on-desktop
    {
        display:block;
    }
    div.hide-on-mobile
    {
        display:none;
    }
}

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

Enhance the user experience with Twitter Bootstrap 3 tooltips featured on every title

Is there a way to display tooltips on all title="" attributes without having to define each #id in the javascript? I have a large table with over 100 entries and it's not practical for me to manually define each row in the script at the footer. Any s ...

Reduce the height of the navigation bar

I used the header example from Bootstrap's documents here: https://getbootstrap.com/docs/5.3/examples/headers/# The code I have is: <div class="container fixed-top bg-white"> <header class="d-flex flex-wrap justify-conte ...

Issues encountered while using the rest operator with jQuery .when method

We have implemented a wrapper in our code base for handling ajax calls using jQuery. The purpose of this wrapper is to make it easier to eventually switch away from jQuery, if needed, by isolating all ajax-related calls. Below is the definition of the wrap ...

Tips for Preventing Page Scrolling When Clicking on a Hashed A Tag in Content with a Fixed

Currently stuck dealing with a challenging problem related to hashed anchor links. Here's a basic representation of the HTML code: <div class="main-wrap"> <header></header> <aside> <nav> <ul> ...

Contrasts in characteristics of CSS images versus SVG graphics

I'm curious if there are distinctions between CSS images and SVGs on your website. When referencing CSS images, I mean images constructed with div elements in HTML and then styled using CSS (such as this: https://codepen.io/andrewrock/pen/jOEZxrY). ...

How can the carousel item numbers be adjusted for proper display?

I'm currently working on an Angular app and have encountered a task related to displaying 5 cards using mdbootstrap. I want to showcase these cards in a carousel format, but with a twist - I only want the carousel functionality to be active on mobile ...

Turn off the ability to debug XHR requests in the developer tools of all web browsers for my website

Is there a method to prevent website users from viewing the communication between my web application and the server via ajax requests? Is there a way to achieve this on my website using code? I want to make sure that the XHR, Ajax calls, and responses ca ...

Aligning HTML form elements side by side

I am having trouble displaying multiple Bootstrap elements and buttons in a single line. Here is an example of what I have: <span><input class="form-control" id="filename" value="Select a ZIP file to upload..." disabled style="display: inline"> ...

Deciphering JSON data into PHP arrays and variables: A step-by-step guide

As a PHP beginner, I'm struggling to grasp certain concepts related to extracting data from POST requests in PHP. Let me describe my code and the issue I'm facing: I have a serialized array that I convert to JSON before sending it via ajax to PH ...

jQuery - "Error: fadeIn is not a valid function"

Encountering an odd issue here. Attempting to execute fadeIn() but receiving the error ".fadeIn is not a function". Here is my code: body { display:none; } <!DOCTYPE html> <html lang="en> <head> <!-- Required meta tags --&g ...

How can I eliminate a class when the scrollTop() position matches a specific div element?

I am trying to implement a script that will allow me to scroll to my navigation and then change the class of the navigation, however, it is not working as expected. $(window).scroll(function() { if ($(window).scrollTop == $('.menu_nav').offs ...

Customizing product prices with unique icons

I have successfully integrated a 'Latest Products' row on the Homepage of my WooCommerce enabled WordPress Website. Now, I am looking to enhance it by adding an icon on each side of the price entry. Although I know how to manually insert <i c ...

Error: Unexpected token found in jQuery code execution

I'm encountering an error that says: Uncaught SyntaxError: Unexpected Token Here is the code snippet where the error occurs: $(document).ready(function(){ $(".cartsummary .showcartsumm").click(function() { $(".cartsummary .cartitems").show(); ...

Unable to successfully download zip files using Ajax in the MVC framework

I need to trigger the download of a zip file that contains .pdf files using an ajax call. The issue I'm encountering is that everything seems to be working fine except for the actual downloading of the zip file. public FileResult DownloadZip(string[] ...

Vertical text area expansion functioning in Chrome, but not in Firefox

Is there a way to create a textarea that dynamically expands to fill the available space within a div, while maintaining fixed height offsets from the top and bottom? The CSS code below achieves this effect in Chrome, but Firefox displays the textarea with ...

Add a <div> element to a webpage in a random location every time the page is refreshed

I have a variety of 2 types of <div>s displayed on a single page. Collection 1 consists of: <div class="feature">content 1</div> <div class="feature">content 2</div> ...and so forth. Collection 2 consists of: <div class ...

What might be causing the issue with the active navigation pill's content not displaying

I'm facing an issue with Bootstrap 5 nav pills where the content of the pills is not displaying correctly. I have 3 nav pills set up, but after the 3rd pill, the content of the 3rd pill shows up in the first pill, and the content of the first pill is ...

Is it possible for an <input> tag in PHP AJAX to have an "action" attribute similar to a <form> tag?

Forms typically use an action attribute to specify where the data should be posted, such as a .php file. Do <input> elements have this action attribute as well? The answer is likely no, but I am curious to understand what concept I may be misunders ...

Ways to update the DOM following modifications to a data attribute

I'm currently working on a small CMS system that handles translations for static pages in multiple languages. The system refreshes and loads translations dynamically, but I've encountered some bugs that are proving difficult to resolve. One issue ...

Creating dynamically adjustable columns in Bootstrap

I've created a simple code for experimentation purposes: <!doctype html> <html lang='en'> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" ty ...