Automatically wrapping and centering characters within pre tags in HTML

I decided to add a box to highlight certain queries on a specific page, rather than the entire website. In order to test out this change, I added an inline style. I found that I had to adjust the characters within the pre tags in order to make them fit inside the border box. Is there a way to automatically wrap and center the characters within the div class box, without manually trimming the characters within the pre tags?

<!DOCTYPE html>
<html lang="en>
<!-- header, sitebranding, tagline, and bodycontent -->

<head>
  <title> Casper Support  </title>
  <meta charset="utf-8"/>
  <link type="text/css" rel="stylesheet" href="wiki.css" />
  <style>
    .box {
      height: 70px ;
      width:  1000px ;
      position: relative  ;
      border: 2px solid #287EC7 ;
      background: #F5F5F5 ;
     }
  </style>
</head>
 <body>
 <h3 id="overdue_meeting"> The overdue Jira Query </h3>
 <p> query </p>
 <div class="box">
 <pre> <code> 
  project = Casper AND status != Closed AND (component = "Queue - Support" OR assignee in (casper1, casper2, casper3, casper4, casper5, casper6, casper7, casper8)) AND (duedate < 7d OR duedate < endOfDay() OR duedate is EMPTY) ORDER BY id ASC 
 </code> </pre>
 </div>
 </body> 
</html>

Answer №1

To achieve vertical centering, utilize flexbox

.box {
    display:flex;
    align-items:center;
}

For horizontal centering and to wrap text properly, disable white-space:pre and apply text-align:center.

.box pre {
  white-space:normal; /* or white-space:pre-wrap to maintain spaces */
  text-align:center;
}

.box {
    height: 70px ;
    width:  1000px ;
    position: relative  ;
    border: 2px solid #287EC7 ;
    background: #F5F5F5 ;
    display:flex;
    align-items:center;
   }
.box pre {
  white-space:normal;
  text-align:center;
}
 <h3 id="overdue_meeting"> The overdue Jira Query </h3>
 <p> query </p>
 <div class="box">
 <pre> <code> 
  project = Casper AND status != Closed AND (component = "Queue - Support" OR assignee in (casper1, casper2, casper3, casper4,                      casper5, casper6, casper7, casper8)) AND (duedate < 7d OR duedate < endOfDay() OR duedate is EMPTY) ORDER BY id ASC 
 </code> </pre>
 </div>

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

Looking to extract and upload a thumbnail image from an HTML5 video element

I am trying to extract and upload a thumbnail from an HTML5 video tag, Below is my code snippet: var w = 135;//video.videoWidth * scaleFactor; var h = 101;//video.videoHeight * scaleFactor; var canvas = document.createElement('canvas&apo ...

Creating a standalone Wordpress child theme with its own CSS

After creating a child theme based on the responsive i-transform theme from http://templatesnext.org/itrans/, I found myself continuously undoing the i-transform CSS, which is taking up a lot of my time. However, if I remove the entire parent stylesheet, t ...

Experiencing the issue of receiving unexpected commas following a div

Here is the code written in TypeScript for creating an HTML table that displays items from nested objects. The code is functional, but there seems to be an issue with extra commas being printed which are not part of any specific line being executed. im ...

Scrolling glitch detected on the Telegram web application

Currently, I am working on building an app with Bubble.io that will be used in the Telegram webapp. However, when I pull down (scrolling up) at the top of the page, Telegram interprets it as a close gesture and attempts to minimize the app window. I would ...

Trick for using :checked in CSS

Is it possible to change the color of a deep linking div using an input checkbox hack in the code below? <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /&g ...

How can you toggle the visibility of a div based on detecting a specific class while scrolling?

My webpage features a sticky header that gains an extra .header-scrolled class when users scroll down. I am looking to switch the logo displayed in the header once it has been scrolled. Below is a simplified version of my HTML code: <header class=".he ...

What happens when there is a 1-second delay in loading CSS on an HTML page?

Lately, I've been working on creating HTML and CSS pages. However, whenever I load a page, I notice that there's always a brief half-second flash of the HTML content without any styling applied. Does anyone have an idea why this is happening and ...

What is causing my css elements to appear larger compared to other instances?

As someone who is not a designer, I find myself doing a lot of cutting and pasting for my side hustles. I believe many others can relate to this experience. Currently, I am working on a personal project that involves using tailwindcss, appwrite, and svelte ...

How can I toggle the visibility of an item on click using jQuery?

I need to toggle the visibility of a specific div when clicking on an anchor. Here is the code I have written for this: jQuery('.mycart').click(function(e){ e.preventDefault(); var target = jQuery(".basket"); ...

Utilize jQuery to dynamically update the box-shadow property with inset added

I have a situation similar to this: $('.inset').click(function(){ if($('.inset').is(':checked')){ $('.box-shadow').css('boxShadow','inset'); }else{ $('.box-shadow&ap ...

Buttons within the Bootstrap carousel caption cannot be clicked

I am currently designing a webpage with a Bootstrap carousel that includes a paragraph caption and two buttons. However, the buttons are not functioning as clickable links - when clicked, nothing happens. {% block body %} <div id ="car-container"> ...

The getElementById function can only select one option at a time and cannot select multiple options

I'm having an issue with a JavaScript function that is supposed to allow me to select multiple options, but it's only selecting the first one. Here is the JavaScript code: function index(){ var a="${staffindex}".replace("[",""); ...

Unable to modify text color after implementing mat-sort-header in Angular Datatable

My current setup involves using an Angular data table to display data. I recently added the mat-sort-header functionality, which allowed me to change the font color of the header text. Below is a breakdown of my code: <section id="main-content" ...

Access the URL or link in an email using Chrome, as opposed to the default browser, IE8

I have an application that sends out an email with a URL link. When the link is clicked, it opens a new tab in the browser. Currently, the application works fine on Chrome but is not compatible with IE8. However, the client's machine has IE8 as the ...

Ways to eliminate excess space at the top of a page while utilizing float elements

After doing some research online, I've come across advice on how to remove the space at the top of a web page which usually involves setting the margin and padding of the body element to 0: body { margin: 0; padding: 0; } You can find more i ...

The image will come to life with animation as the background position is adjusted using Skrollr

Trying to create a div that switches the background image every X pixels scrolled. Initially experimented with changing the background-image, including using sprites and adjusting background position, but encountered a distracting "flickering" effect. Exa ...

Conceal only the anchor tag's text and include a class during the media query

In the anchor tag below, I have a text that says "Add to cart," but on mobile view, I want to change it to display the shopping cart icon (fa fa-cart). <a class="product"><?php echo $button_add_to_cart ?></a> Currently, the variable $bu ...

Updating the background image of individual users in a Laravel blade template in real-time

I'm working on an application with different types of users, and each user has a unique background image for their wall similar to Facebook. However, I am struggling to figure out how to dynamically change the background image for each user. The image ...

Maintaining uniformity in Python by assigning and populating empty values for any missing HTML tags to ensure consistency across structures

Here are the HTML lines I currently have: <nonDerivativeTable> <nonDerivativeHolding> # First Holding <securityTitle> <value>Common Stock</value> </securityTitle> <ownershipNat ...

Using jquery to toggle active nav links in Bootstrap

I'm currently working on integrating a jQuery function to automatically update the active status of the navigation links in my Bootstrap Navbar. The structure involves a base HTML file that extends into an app-specific base file, which is further exte ...