What steps should I take to make my Twitter widget adaptable to varying screen heights?

I'm currently utilizing react-twitter-widgets to incorporate a Twitter timeline within my application. While everything is rendering correctly, the height of the timeline extends down the entire page. Is there a way to adjust the widget's height so that it only occupies the available viewport height? https://i.sstatic.net/KXZJ2.png

The main dashboard has the following DOM structure:

<div className="col-md-9 ml-sm-auto col-lg-10 pt-2 px-3">
                <div className="row">
                    <div className="col">
                        <TitleBar title={this.props.ticker} status={this.props.status}/>
                    </div>
                </div>
                <div className="row">
                    <div className="col-lg-8">
                        <div className="row">
                            <div className="col-lg-12 mb-2">
                                <div className="card border-0">
                                    <div className="card-body">
                                        <Chart chart={this.props.predictionChart} />
                                    </div>
                                </div>
                            </div>
                            <div className="col-lg-6">
                                <div className="card border-0">
                                    <div className="card-body">
                                        <Chart chart={this.props.errorChart}/>
                                    </div>
                                </div>
                            </div>
                            <div className="col-lg-6">
                                <div className="card border-0">
                                    <div className="card-body">
                                        <Chart chart={this.props.volumeChart} />
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div className="col-lg-4">
                        <TwitterCard href={this.props.twitter} ticker={this.props.ticker}/>
                    </div>
                </div>
            </div>

Here's an example format for the TwitterCard component:

import React from "react";
import { Timeline } from 'react-twitter-widgets';

export class TwitterCard extends React.Component{
    constructor(props){
        super();
        this.state = {
            ticker: props.ticker,
            href: props.href
        }
    }
    render() {
        return (
            <Timeline dataSource={{sourceType: 'URL', url: this.props.href}}/>
        )
    }
}

The primary CSS file looks like this:

body {
    font-size: .875rem;
    background-color: #f7f7f7;
}

/* Remaining stylesheet omitted for brevity */

Answer №1

My approach to resolving this issue:

 HTML:
     <Box className={classes.media}>
          <Timeline
            dataSource={{
              sourceType: "profile",
              screenName: "lbeegg",
            }}
            options={{ theme: "dark", width: "545" }}
          />
    </Box>

    CSS:
    media: {
    display: "flex",
    objectFit: "cover",
    width: "auto",
    height: "450px",
    overflowY: "scroll",
    borderRadius: "15px",
  },

Since I am utilizing material UI, the code may differ slightly. To address the problem, I enclosed the Timeline component within a Div that has a "media" class. In the CSS, I utilized the overflowY property with a set height in pixels to provide a solution.

Answer №2

To render the widget, please provide the required JavaScript code below. If it matches the example provided, you can customize the height attribute as needed.

ReactDOM.render((
  <Timeline
    dataSource={{
      sourceType: 'profile',
      screenName: 'twitterdev'
    }}
    options={{
      username: 'TwitterDev',
      height: '400' 
    }}
    onLoad={() => console.log('Timeline is loaded!')}
  />

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

What is the best way to specify the dimensions of an image with CSS or Bootstrap?

I am facing some challenges while building my website. The ideal look of the page is represented by home_page_ideal. The issue arises with the small boxed image on the top left corner. Once I scroll to the top, the page displays as home_page_issue. The CSS ...

Hovering over the designated area will reveal the appearance of

I've encountered an issue with a list group in a card. Specifically, when hovering over the topmost item in the list group, a border appears underneath it (which should only appear when hovering). However, when I try to override this behavior using :h ...

Error encountered when using Symfony 2 command line interface

Just started learning Symfony2 and encountered a problem. I made changes to my CSS and when I try to re-install them in Eclipse shell, I get this error message: 'C:\wamp\www\Symfony' is not recognized as an internal or external ...

Refreshing the page causes Material UI Button to revert to default styling

My question regarding the Material UI Button losing styling after a page refresh (link: Material UI Button loses Styling after page refresh) went unanswered, so I am reposting with a CodeSandbox included for reference: https://codesandbox.io/s/bold-resonan ...

Encountering an issue with the installation of react-twitter-embed

Having an issue with react-twitter-embed. I encountered an error when running the command: install error If anyone has a solution to this problem, please share it with me. ...

The HTTP connection established between the ReactSample and the AsP.NET Core WebApi

My current setup involves using axios to make HTTP requests in the frontend. async componentDidMount() { const { data: posts } = await axios.get("http://localhost:58944/api/posts"); this.setState({ posts }); } When the backend receives a request from the ...

IE7 disregards the margin set in a div after a div that has been positioned absolutely

Within a container, I have two divs - the first one with absolute positioning. Strangely, in IE7, the second div doesn't seem to acknowledge the top margin. Padding works fine, but for visual consistency, I prefer using margin. The culprit appears to ...

"Utilize Python's Selenium library to automate clicking the 'Get Data

Having trouble with clicking the GetData button to retrieve the output. Looking for assistance on how to achieve this. Update your code below:- from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.chrome.o ...

What is the best way to retrieve information from a data set?

After borrowing some basic HTML, CSS, and JavaScript code from CodePen, I ran into an issue while attempting to convert it to React. The error message says that it cannot read properties of null (specifically 'dataset'). Here is the JavaScript c ...

Create a rectangular container with text using CSS

Looking to achieve a square box design using CSS with specific dimensions? Want to insert text inside the square and ensure it is horizontally centered within the square? Check out this code snippet: #myid { width: 100px; height: 100px; ...

Tips for customizing the appearance of a specific cell in the first column of a Material UI table

Currently, I am modifying the material ui table found in this codesandbox link. My goal is to adjust the style of the first column's cell in the table when it is selected to match the image provided below. https://i.sstatic.net/DGubN.png It seems lik ...

Updating the display in React Native

My application receives its theme (colors and styles) from a REST API. Whenever there is a change in the theme on the server, the app is notified through socket communication so that it can fetch the new theme using REST. The theme is retrieved in a Redux ...

Javascript/Typescript Performance Evaluation

I am looking to create a visual report in the form of a table that displays the count of each rating based on the date. The ratings are based on a scale of 1 to 5. Below is the object containing the data: [ { "Date": "01/11/2022", ...

Eliminate gaps between lines in a wrapped Flexbox layout

I am trying to eliminate the spaces between rows in a horizontal list flexbox. I am creating an alphabetical list and I want it to flow seamlessly without any gaps. This is what I have so far: #example { display: block; margin-left: auto; margin-r ...

Does Div have the capability for text-shadow?

Is there a way to create a shadow effect for DIVs similar to the text-shadow property? While text-shadow is great for adding shadows to individual pieces of text, I'm interested in applying a shadow effect to an entire DIV element. Does anyone have a ...

Creating fluid designs for my boxes with CSS to enhance responsiveness

I have designed my HTML file with 8 boxes that appear correctly on desktop, but when viewed on mobile devices, the columns are misaligned and shifted to the right side instead of being centered. How can I make it more responsive? See Preview Here is the ...

Prevent outside clicks from closing the React Ant Design drawer by disabling the functionality

Does anyone know how to disable the outside click option in the ant design drawer component for my react project? Here is a link to a working example on StackBlitz Below is the code snippet: import React from 'react'; import ReactDOM from &apo ...

Tips on organizing a typescript object/StringMap in reverse order to prioritize the last element

I've just started working with TS/React in a .tsx file and I'm trying to add a key/value pair to a StringMap at the very first index. Below is the code snippet that: takes the StringMap 'stats' as input, iterates through each row, re ...

Dynamic grid in Bootstrap functioning flawlessly with the generation of all elements except one

I'm currently working on creating a dynamic grid for video components, but I'm facing a challenge. I'm struggling to figure out how to handle an element that is not generated dynamically. The first video element is created conventionally, wh ...

React is failing to display images even with the correct file path

I have developed a React test with dynamic content. The sidebar includes Bootstrap collapses that contain lists with icons and names. However, there is an issue where some images within the "Natürlich" section are not displaying. Strangely, these images a ...