One way to view inherited width while ensuring that data remains inside a pre tag is by utilizing CSS

Currently, I'm facing an issue with displaying PHP and Javascript code within pre tags in a project. The problem arises as the code spills outside the boundary of the containing element. While inspecting the console, I am attempting to identify the source of width for the element or determine the width of the container div. Despite setting a width of 100% for the parent wrapper div in the CSS file, some containing elements exhibit narrower widths that are not visible in the console inspection. The overflow of the pre tag beyond the border can be observed here:

CSS

body {
    font:1.1em 'Source Sans Pro';
}

h1,
h2,
h3,
h4,
h5 {
    font-weight:400;
}

.hidden {
    display:none;
}

.wrapper {
    width:100%;
    max-width:600px;
    margin:0 auto;
}

.upload-console {
    background:#fefefe;
    border:2px solid #eee;
    padding:20px;
}

.upload-console-header {
    padding:0 0 20px 0;
    margin:0;
    border-bottom:2px solid #eee;
    font-weight:600;
    margin-bottom:20px;
}

.upload-console-drop {
    height:200px;
    border:2px dashed #ccc;
    line-height:200px;
    color:#ccc;
    text-align:center;
    margin-bottom:20px;
}

.upload-console-drop.drop {
    border-color:#222;
    color:#222;
}

.upload-console-body {
    margin-bottom:20px;
}

.bar {
    width:100%;
    background:#eee;
    padding:3px;
    border-radius:3px;
    box-shadow:inset 0 1px 3px rgba(0,0,0,.2);
    box-sizing:border-box;
    margin-bottom:20px;
}

.bar-fill {
    height:30px;
    display:block;
    background:cornflowerblue;
    width:0;
    border-radius:3px;
    -webkit-transition:width 0.8s ease;
    transition:width 0.8s ease;
}

.bar-fill-text {
    color:#fff;
    line-height:30px;
    margin-left:5px;
}

.upload-console-upload {
    border-bottom:2px solid #ccc;
    margin-bottom:10px;
    padding-bottom:10px;
}

.upload-console-upload span {
    float:right;
}

pre {
    border: 1px solid black;
}

How can I identify the source of an element's width and ensure that the code remains within the pre tag? Thank you.

Answer №1

Include white-space: pre-wrap; in the styling for the pre tag and ensure proper formatting of your code snippet

pre {
    border: 1px solid black;
    white-space: pre-wrap;
}

Answer №2

To create a horizontal scroll for code blocks, simply apply overflow-x: scroll; to the pre tag.

pre {
    border: 1px solid black;
    overflow-x: scroll;
}

Answer №3

Apply the style overflow: auto to your pre element in order to keep the content inside the border.

pre {
    overflow-x: auto;
}

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

Refresh the Dom following an Ajax request (issue with .on input not functioning)

I have multiple text inputs that are generated dynamically via a MySQL query. On the bottom of my page, I have some Javascript code that needed to be triggered using window.load instead of document.ready because the latter was not functioning properly. & ...

The onclick function is malfunctioning within the Node.js environment

Having trouble with Node.js not working with JavaScript code This is my File structure: app.js index.html index.js However, when I run it without Node, it works and the alert shows up. app.js var http = require('http'); var fs = require(&apo ...

Generate a custom map by utilizing JavaScript and HTML with data sourced from a database

Looking for guidance on creating a process map similar to this one using javascript, html, or java with data from a database. Any tips or suggestions would be appreciated. https://i.sstatic.net/tYbjJ.jpg Thank you in advance. ...

Position the float input to the right on the same line as an element

This Angular code contains a challenge where I aim to have text at the start of a column and an input box on the right side of the page, both aligned on the same line. The issue lies in the code which floats the input to the right but disrupts the alignme ...

Updating a Pandas Column in Python Using a for Loop

My lack of experience with web scraping is definitely showing as I am relatively new to this. The goal of my code is to scrape all the data from a webpage, which it does successfully. However, before the loop continues, I want pandas to write the current p ...

Drag and Drop Functionality in ReactJS for Organizing Multiple Lists

After hours of searching, I have yet to find a React library that can handle sorting between multiple lists. The closest solution I came across was in this article: There is also an example provided here: The issue with this solution is that you have to ...

Give GetElementsByClassName a shot

Hey, have you tried using js ref_doc_getelementsbyClassName? "I keep getting the error message 'Uncaught TypeError: Cannot set property 'value' of null' " Check out this HTML code snippet: <input type="text" cla ...

Efficiently loading Angular views with lazy loading techniques

I am currently working on a calculator website powered by Angular. This single-page site is fully responsive and divided into 7 sections, each featuring different calculators based on user preferences. To improve loading time, I am interested in implementi ...

Unable to download the jQuery Plugin

I am looking to install a gallery without using flash, and I came across this jQuery plugin called Grid-A-Licious. However, I am having trouble figuring out how to install and use it since it is distributed as a .zip archive with two .js files but no index ...

Is there a way to eliminate the black seam that is visible on my floor mesh that has been separated? I am utilizing A

I recently imported a large .glb file into AFrame. The model has baked textures and the floor is divided into multiple mesh parts for improved resolution. However, I am facing an issue where black seams appear on the separated parts of the floor, only dis ...

Making an asynchronous call from Index.html to PHP Script

I am currently working on implementing an AJAX call to my PHP Script. While I can successfully echo the results from my data.php file, I am now facing a challenge regarding how to initiate the call from index.html in order to retrieve the table results s ...

What is the source of these additional pixels that appear when percentages are used for defining height?

I have been working on implementing a sticky footer that I've successfully used in the past for various websites. You can find the link to the original method here: However, this time I am facing a challenge as I want to make the footer more responsi ...

Issue with PHP (functions correctly on local server, but encounters errors on online server)

I am encountering an issue with PHP on the web server I am utilizing. Despite my efforts, the solution seems to elude me completely. The PHP file I have uploads two files; a before and an after shot of the client. The script on my localhost server works p ...

javascript - Retrieving a JSON string

I am currently working on a stock website where I need to retrieve JSON information from either Google's API or Yahoo's API. To test this functionality, I have used a replacement function to log the data onto a text box for testing purposes. Howe ...

Connecting static CSS files to Django

I am fairly new to working with Django and I am having trouble linking CSS to my project. I have included the necessary static settings in my app's configuration, which allows me to access images in the static folder without any issues. However, when ...

Using javascript to color in cells of a grid of "pixels"

I have a project similar to an Etch-a-Sketch in progress. The main challenge I am currently facing is how to gradually darken each cell of the grid with every pass of the mouse cursor, based on the opacity of the cell being hovered over. When the grid cell ...

Determine whether the string includes any character during keyup event

I'm currently working on implementing a live search feature on my website. I have managed to make it work where the input field and link title match, but it only matches complete words. I am wondering if there is a way to display results that contain ...

Picking specific <button> items

Presented here are a series of buttons to choose from: <button id="hdfs-test" type="button" class="btn btn-default btn-lg">HDFS</button> <button id="hive-test" type="button" class="btn btn-default btn-lg">HIVE</button> <button id ...

Tips for Enhancing JavaScript Performance

Is there a way to enhance my JavaScript code like this: $(window).scroll(function() { if ($('#sec1').isVisible()) { $('.js-nav a.m1').addClass('active'); } else { $('.js-nav a.m1').removeClas ...

Ways to achieve an arched shadow effect for an image using React and Tailwind CSS?

Looking to add a unique touch to my React project with a shadow effect resembling an arch shape at the top of an image using Tailwind CSS. The ultimate goal is to create a semi-transparent arch-shaped shadow covering the top portion of the image, similar t ...