Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling a Twitter feed - CSS won't target .timeline-Tweet-text

Tags:

html

css

twitter

I'm bringing a Twitter feed through to my site using the following code which is described on https://publish.twitter.com/

<a class="twitter-timeline" href="https://twitter.com/ACCOUNT-HERE" data-tweet-limit="3">Tweets by</a> 
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

The feed is displayed correctly. However it uses CSS which is provided via Twitter.

When I inspect it using Chrome dev tools I can see the following classes around the Tweets:

<p class="timeline-Tweet-text" lang="en" dir="ltr">

So I thought it would be a simple case of targetting this in CSS, e.g.

.timeline-Tweet-text {
}

However, this doesn't apply any styles to the Tweets. Why not?

I have also referred to Twitters guidance on this here https://dev.twitter.com/web/overview/css but that also doesn't work.

The only reason I want to do this is so the font used within the widget matches the font used by the rest of the body text on my website.

like image 382
Andy Avatar asked Nov 18 '16 10:11

Andy


People also ask

How do I customize my twitter feed?

In the top menu, tap the icon. Tap the arrows to switch to the timeline view of your choice, or tap View content preferences to go to your settings. In the top menu, click the icon. Click the arrows to switch to the timeline view of your choice, or click View content preferences to go to your settings.

How do I prioritize my twitter feed?

Choose Settings and privacy. Then look for Show the best Tweets first in the Content section. Uncheck the box, then click Save Changes. Click Home to see your new timeline format, in reverse chronological order with the most recent tweets from people you follow first.


Video Answer


1 Answers

Simply adding a style rule to your top-level page won't work, because they are two different and isolated documents as far as the browser is concerned.

However, with the use of kevinburke's Customize Twitter 1.1 project, you should be able to embed CSS into a timeline. It does this by injecting a link to an external CSS file directly into the contents of the document within that frame.

In Kevin's published example, It makes all the text white, which looks a bit broken, but when I took this example and adjusted it to also turn the background red, we can see it's working as intended and you can therefore make any adjustments you like, provided you have a CSS file for it.

Screenshot of twitter feed with red background

Note that this is only possible because Twitter have configured platform.twitter.com so that it can be embedded in frames. For security reasons, many websites will nowadays send a HTTP response header to prevent framing of the content, to avoid people meddling with their contents.

like image 55
BoffinBrain Avatar answered Oct 09 '22 01:10

BoffinBrain