The offspring departing from the guardian's left side

I have a canvas element inside a container and I want to prevent the canvas from extending beyond the left side of its container. Despite trying various solutions, I have not been successful. The legend is hidden within the container but when the chart reaches the right border, it pushes the chart outside the container.

CSS:

.chart-container{
    display: flex;
    flex-direction: row;
    border: 1px solid red;
    justify-content: center;
}
#totalChartLegend, #pdChartLegend {
    list-style-type: square;
    list-style-position: inside;
    cursor: pointer;
    font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
    font-weight: bold;
    font-size: 15px;
    color: #666;
    overflow-y: auto;
    overflow-x: hidden;
    height: 280px;
    width: 140px;


    border: 1px solid green;
    margin-top: 40px;
    text-align: left;
    white-space: nowrap;
}
#totalChartLegend li, #pdChartLegend li{
  display: block;

}
#totalChartLegend li.hidden, #pdChartLegend li.hidden{
  color: rgba(102, 102, 102, .4);
}
#totalChartLegend li span, #pdChartLegend li span{
  display: inline-block;
  height: 15px;
  width: 35px;
  margin-right: 10px;

}
#totalChart, #pdChart{
    border: 1px solid blue;

}

HTML

<section id="totalChartContainer" class="chart-container">
    <canvas id="totalChart" width="900" height="400"></canvas>
    <span id="totalChartLegend"></span>
</section>

Image (blue = child, red = parent)

https://i.sstatic.net/Qtqv9.png

UPDATE 1

If I continue collapsing the browser's width, my chart moves all the way to the left side of the browser window.

Answer №1

Updated the CSS for parent element to

.chart-container{
    display: flex;
    flex-direction: row;
    border: 1px solid red;
    justify-content: center;
    min-width:900px;
}

Answer №2

Feel free to utilize the following code snippet

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <title>Hello, world!</title>
    <style type="text/css">
        body {
            margin: 0;
            padding: 0;
        }        
        .chart-container {
            display: flex;
            flex-direction: row;
            border: 1px solid red;
            justify-content: center;
        }        
        #totalChartLegend, 
        #pdChartLegend {
            list-style-type: square;
            list-style-position: inside;
            cursor: pointer;
            font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
            font-weight: bold;
            font-size: 15px;
            color: #666;
            overflow-y: auto;
            overflow-x: hidden;
            height: 280px;
            width: 140px;
            border: 1px solid green;
            margin-top: 40px;
            text-align: left;
            white-space: nowrap;
        }       
        #totalChartLegend li,
        #pdChartLegend li {
            display: block;
        }        
        #totalChartLegend li.hidden, 
        #pdChartLegend li.hidden {
            color: rgba(102, 102, 102, .4);
        }       
        #totalChartLegend li span,
        #pdChartLegend li span {
            display: inline-block;
            height: 15px;
            width: 35px;
            margin-right: 10px;
        }       
        #totalChart,
        #pdChart {
            border: 1px solid blue;
        }
    </style>
</head>
<body>
    <div class="container>
        <div class="row">
            <section id="totalChartContainer" class="chart-container>
                <canvas id="totalChart" width="900" height="400"></canvas>
                <span id="totalChartLegend"></span>
            </section>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous></script>
</body>
</html>

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

Adaptable transformations within ngx-bootstrap carousel

Currently, I am in the process of learning Angular and I have encountered a problem while trying to make my site responsive using ngx-bootstrap carousel. Is it achievable to implement responsive changes within the ngx-bootstrap carousel? In the main v ...

The combination of AddEventListener in the parent and postMessage in the iframe is ineffective

As I delve into the Stripe documentation to develop a new feature, I have encountered an issue regarding the communication between a webpage and an iframe. The code in index.html: <!DOCTYPE html> <body> parent<br> <iframe src="./ ...

Adjust the padding when hovering using CSS

Hey everyone, newbie here taking a crack at my first Joomla module! I've made some progress but hit a snag with my CSS styling - I think it's an issue with my selectors and my limited understanding of what's going on. Basically, I'm at ...

How can I create additional white space at the end of my webpage with CSS grid?

Looking for some help with CSS as a beginner here. I'm facing an issue where my CSS is creating excessive blank space at the bottom of my document, almost 60% of it. Could this be due to incorrect parent parameters or the children elements? This is m ...

one webpage featuring HTML-based charts - visual data representation in HTML

I am looking to create HTML charts using a single file that includes JavaScript and jQuery. Specifically, I need the ability to generate line charts, pie charts, and other types of graphs, all within one file. I do not have much knowledge about JavaScript ...

PHP script not recognizing CSS styles

My coding dilemma involves a script that is supposed to display numbers from 1 to 100 in black font. For multiples of 3, it should show "Three" in green, and for multiples of 7, it should display "Seven" in blue instead of the number. If a number is a mult ...

Stop horizontal overflow of content

This unique Vuetify demo on CodePen showcases a two-column layout. The first column contains a <v-list> enclosed in a green <v-alert>. By clicking the "toggle text" button, you can switch the title of the first list item between short and long ...

Hacking Html tables in Firefox to prevent native selection

I'm encountering an issue in Firefox where it has a default selection behavior in an HTML table when pressing Ctrl: https://i.sstatic.net/TbpFa.png Any suggestions on how to disable this action so that my functionality can work properly? Thanks for ...

Contrasting hierarchy of text-decoration and text-shadow in Firefox compared to Chrome

When viewing this HTML/CSS code in Firefox and Chrome, the text-decoration and text-shadow properties appear to be swapped between browsers. .foo { font-size:2em; text-decoration:underline LightBlue 1ex; text-decoration-skip-ink:none; ...

Guide to implementing this specific design using CSS within jQuery Mobile

Want to achieve the red circle effect using CSS. Currently working with jQuery mobile and AngularJS. Below is a snippet of my code: <div data-role="page" id="p2"> <div class="ui-bar ui-bar-d "data-role="header" > <a href="" data-role=" ...

Tips for creating a subclass using jQuery

I am familiar with selecting the class "myClass" using $(".myClass"), but my question is how do I select the child link within an element with the class "myClass" using jQuery? Here is a sample of the code: <a href=#>Home</a> <div class ...

Style-loader in Webpack failing to inject styles into the DOM

I'm facing an issue where the styles from my styles.css file are not being loaded in the DOM despite using Webpack to bundle them. I have both the css-loader and style-loader packages installed and included in my package.json file. The CSS file is imp ...

Exploring the dynamic animation of jQuery slideDown with the layout manipulation of

My current project involves using an HTML table with multiple rows. I have hidden every second row, which contains details about the preceding row, using CSS. Upon clicking the first row, I am utilizing jQuery's show() function to display the second ...

How can I extract the string located immediately after the last character using jQuery?

Can you help me extract the text after the last "=" symbol in this string? <div class="main_menu_link" data-ajax-url="http://mytestdomain.com/temp-param-page-2/?wpv_paged_preload_reach=1&wpv_view_count=1&wpv_post_id=720960&wpv_post_search&a ...

Using CSS to position an element relative/absolute within text inline

Need help aligning caret icons next to dynamically populated text in a navbar menu with dropdown tabs at any viewport size. Referring to positioning similar to the green carets shown here: https://i.stack.imgur.com/4XM7x.png Check out the code snippet bel ...

Delay showing the div until it has finished loading

<section class="slideshow" id="slideshow"> <div id="slides"> <div class="slides-container"> <div class="slide"> <img src="img/people.jpeg" alt="Cinelli"> </div> < ...

The content in an app using Ionic and Angular is being obstructed by the bottom tabs, preventing users

I am facing an issue with my Ionic and Angular app. When I place tabs at the bottom of my page, outside the ion-content, the scrolling stops working inside the ion-content and the fab button, which is located inside the ion-content, ends up covering the ta ...

Integrate a Google Maps API Javascript into a Flex application

I'm trying to incorporate a Google Maps API JavaScript into my Flex Application, but I have been unsuccessful so far despite looking at various examples. If anyone has any tips or guidance on how to achieve this, I would be extremely grateful for you ...

Eliminate the white background from the modal image

I'm facing an issue with an image displayed in a modal. The image has a white background that I want to remove so only the image itself is visible. https://i.stack.imgur.com/CG9Ne.png Here's the code snippet: <div id="myModal" class ...

Guide to preserving canvas state in React?

I am currently working on a drawing application that allows users to draw lines on a canvas. The functionality is such that the line starts drawing on the first click, continues as the mouse moves, and stops on the second click. However, each time a user ...