Embedded tweets may occasionally lose their borders when viewed on various web browsers

My goal is to showcase a collection of responsive embedded tweets in rows of 2.

Here are the key elements of the code that have enabled me to achieve this:

HTML

<div id="tweets"></div>
<script src="https://platform.twitter.com/widgets.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

CSS

#tweets {
  margin: 10px auto 0;
  max-width: 820px;
  width: 95%;
}
#tweets .row {
  overflow: hidden;
}
#tweets .row > .tweet {
  max-width: 520px;
  width: 49%;
}
#tweets .row > .tweet:nth-child(1) {
  float: left;
}
#tweets .row > .tweet:nth-child(2) {
  float: right;
}
#tweets .row > .tweet .twitter-tweet-rendered {
  max-width: 100% !important;
  width: 100% !important;
}

JavaScript

window.onload = (function() {
  // sample data
  var tweets = [
    '629488522752212992', '629487749200936961', '629488522752212992',
    '629487749200936961', '629488522752212992', '629487749200936961'
  ];

  var container = $('#tweets');
  var list = '';
  // create markup before rendering tweets
  for (var i = 0, even = true; i < tweets.length; i++, even = i % 2 === 0) {
    if (even) {
      list += '<div class="row">';
    }
    list += '<div class="tweet"></div>';
    if (!even) {
      list += '</div>';
    }
  }
  container.html(list);
  // render tweets 
  $.each(tweets, function(i) {
    var tweet = container.find('.tweet:eq(' + i + ')');
    twttr.widgets.createTweet(this, tweet[0], {
      'cards': 'none'
    });
  });
});

Demo: https://jsbin.com/yigucejice/edit?output

The issue I'm facing is with inconsistent display of borders on the tweets across different browsers. For instance, the right border of some tweets may be hidden in IE 11 or the bottom border may not show in Firefox 39.0.

I want the borders to consistently appear on all browsers.

I've tried adjusting the styles of the iframe (.twitter-tweet-rendered) within the tweets by modifying the margin and height, but so far, it hasn't resolved the problem.

How can I address this issue? If not, is there a way to disable the borders?

https://i.sstatic.net/GzX42.jpg

Solution

Thanks to the solution provided below, I made changes to my JavaScript code as follows:

twttr.widgets.createTweet(this, tweet, { 'cards': 'none' }).then(function(frame) {
    // remove EmbeddedTweet's border
    $(frame).contents().find('.EmbeddedTweet').css({ 'border': 'none' });
    // add border on the placeholder that holds the iframe
    tweet.addClass('border'); 
});

Answer №1

To address the issue of borders not disappearing, there are two possible approaches.

The reason for the border disappearing is due to media screen size queries. In Chrome, the border is rendered correctly and displayed, but in Firefox, it disappears. However, in Firefox, if you reduce the page size from 100% to 90%, the border reappears and displays correctly.

There are two solutions to this problem:

Option 1: Using pure CSS

Modify the width property from width: 49%; to width: 47%;

#tweets .row > .tweet {
    max-width: 520px;
    width: 47%;
}

Option 2: Utilizing jQuery

Add the following code and set margin: 1px on EmbeddedTweet to allow space for the border to appear/show.

<script>
window.setTimeout(function(){
    $(".twitter-tweet-rendered").contents().find(".EmbeddedTweet").css("margin","1px");
  }, 3000); 
</script>

A timeout of 3000 is set so that the iframe loads first and the margin can be adjusted since the Twitter iframe is cross-domain.

Note: Directly applying CSS on the iframe is not possible due to cross-domain restrictions, making jQuery or JavaScript the only viable options.

I have recreated the error Here and implemented the jQuery solution successfully.

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

Utilize the $setValidity function within ng-repeat to validate input fields

I am facing an issue with my form that is being repeated in an ng-repeat. Below is a snippet of the form. I need to implement custom validation using $setValidity in the controller. However, I am struggling to access input names by index in the controlle ...

Tips for sending a localstorage value as a parameter in an axios request

Currently, in my React app, I am using Express to handle all of my database queries. One thing I am attempting to achieve is passing the user id stored in local storage into a post request. This is necessary for my application since it revolves around use ...

The form does not seem to be updating or refreshing even after an AJAX submission and validation

I have a form set up to submit data to my database using jQuery Validate plugin and ajax. However, I'm encountering an issue where after clicking submit, the form does not clear out. While the data does get updated in the database, I need help figurin ...

Modify the color of the Swing link label for disabled state

I'm currently working with Java Swing linkLabel. I've noticed that when the link is disabled, it appears in gray by default, but I would like it to be black instead. Is there a method available to change the color of a disabled link label? ...

The jQuery change event does not fire once the DIV has been rendered, while working with CakePHP

Whenever a room_id is chosen from the drop-down menu, I utilize the JS helper to automatically fill in the security_deposit and room_rate input fields. However, there seems to be an issue where selecting a room_id causes the room_rate_update jQuery change ...

Ways to slightly boost the default font-size values when using wicked-pdf

In the wicked-pdf report, I have body content with varying font sizes. When I apply a font-size of 16px to the paragraph like so: p { font-size: 16px !important; } The entire paragraph's font size becomes 16px, which may include words with diff ...

How can I show the last li item in a ul element that extends beyond its parent container?

Chat App Development In my current project, I am developing a chat application using React. The app consists of a list (ul element) that displays messages through individual items (li elements). However, I have encountered an issue where the ul element st ...

Identifying edited files within the node_modules directory: A comprehensive guide

While working with the serverless framework, I installed it using npm. During my debugging process, I made some modifications by adding console.log statements to different files within the node_modules folder. Unfortunately, I can't recall which speci ...

Why is there a discrepancy between the value displayed in a console.log on keydown and the value assigned to an object?

As I type into a text box and log the keydown event in Chrome, I notice that it has various properties (specifically, I'm interested in accessing KeyboardEvent.code). Console Log Output { altKey: false bubbles: true cancelBubble: false cancelable: t ...

Remove chosen tags from the options list in Material UI Autocomplete Multiple

When utilizing the Material UI Autocomplete for multiple values, the selected input is shown in the options list with a blue background color. Is there a way to configure the autocomplete to exclude already selected values from appearing in the options li ...

Adding Javascript and CSS files to the document dynamically

I've created a custom jQuery plugin, but I need it to verify if jQuery is already loaded. If not, I want the plugin to load jQuery along with a few other necessary JavaScript files. Additionally, I want it to check if a specific CSS file has been load ...

Is there a way to apply a css class to all nested elements in Angular 6 using Ngx Bootstrap?

I've defined a CSS class as follows: .panel-mobile-navs > ul > li { width:100% } Within the HTML, I am utilizing Ngx-bootstrap for a series of tabs like this: <tabset class="panel-mobile-navs" > ... </tabset> My intention is to ...

Discover the amazing capabilities of Beautiful Soup's find function in extracting numerical data from Google

Just finished watching a tutorial on beautiful soup and decided to put it to the test by scraping some data from Google. After searching for "coronavirus UK" I aimed to extract the current number of confirmed cases. A table on the upper right side of the ...

Utilizing the Loess npm module in conjunction with Angular 4

I am attempting to incorporate the Loess package into my project. The package can be found on NPM and offers various regression models for data fitting. I successfully installed it using npm install loess --save, and it now resides in the node_modules dire ...

Guide for using JavaScript to obtain the current line position within a contenteditable div during a keypress event

I am in the process of developing a customized editor using a contenteditable div. I require a javascript code that can determine the line position of the current caret position during a keypress event. It should be able to adapt when new lines are added o ...

Difficulty encountered when attempting to utilize keyup functionality on input-groups that are added dynamically

I've exhausted all available questions on this topic and attempted every solution, but my keyup function remains unresponsive. $(document).ready(function() { $(document).on('keyup', '.pollOption', function() { var empty = ...

Achieving uniform distribution of items within a flex container

I have been struggling since yesterday to make this work. I just can't seem to get these flex items to fill the container equally in width and height. No matter what I try, it's not cooperating. <html> <meta charset="utf-8"> ...

Utilizing withRouter outside a component to navigate through historical data

I'm still getting the hang of react router and encountering some challenges. I can easily use history within a component without any issues. However, when trying to access history from a function outside the component, I run into problems. Despite my ...

An alternative solution for forms within forms

I'm in need of nested forms, but since they are not allowed in HTML, I've come up with a solution. I decided to have several submit buttons within one form. Now, my problem is figuring out how to determine which of the submit buttons is pressed ...

Looking to arrange an object by the value of a nested object in Typescript/Angular?

I'm currently developing an Angular 9 application focused on covid-19 cases, and I need to arrange my objects by the value of nested objects. Here is the dataset that I want to organize alphabetically based on the 'state' field values: stat ...