Printing with Bootstrap in HTML on Google Chrome

I've browsed through several SO questions, but haven't quite found a complete solution. My project involves using bootstrap with HTML 5 to create a page suitable for printing on standard paper sizes like 8.5x11 or A4 for reports. However, I'm encountering various issues when it comes to the printing process.

Whenever I try to print using ctrl+p, the bootstrap cells end up stacking on top of each other and lose their original formatting from the desktop view. Additionally, any extra styling such as font colors doesn't seem to appear in the print preview. The margins also lack consistency. How can I effectively utilize bootstrap to design a report page that maintains its appearance across both the desktop and printed versions?

Let me provide a brief snippet of the code I'm working with:

HTML

<div class="container">
  <div class="row">
   <div class="col-sm-6">
     <h2>Person Name</h2>
   </div>
   <div class="col-sm-6">
     <p>Height</p>
   </div>
 </div>
</div>

CSS

@media print{
   @page {
      size: A4;
      margin: 0cm;
    }
    html, body {
      width: 1024px;
    }
    body {
      margin: 0 auto;
    }
    nav {
      display: none;
    }
 }

Upon printing, instead of "Person Name" and "Height" appearing side by side as intended, they are stacked vertically, unlike how they appear on the desktop view.

Your assistance on this matter would be greatly appreciated! Thank you!

Answer №1

The printer margin may be causing issues with the column layout display.

CSS:

@media print{
   @page {
      size: A4;
      margin: 0cm;
    }
    html, body {
      width: 1024px;
    }
    .container {
      width: auto;
    }
    body {
      margin: 0 auto;
    }
    nav {
      display: none;
    }
    .col-6-print{
      flex:0 0 50% !important;
    }
 }

html:

<div class="container">
  <div class="row">
    <div class="col-sm- col-6-print6">
      <h2>Name of Individual</h2>
    </div>
    <div class="col-sm-6 col-6-print">
      <p>Height Information</p>
    </div>
  </div>
</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

Using the margin property creates an odd spacing issue that seems out of place

Here is the HTML and CSS code that I am using: div { background: yellow; width: 77px; height: 77px; border: 1px dotted red } #one { margin: 0px 21px 41px 41px } <html> <head> <meta charset="UTF-8"> ...

Angular 1.5 - Component for fetching HTML content with dynamic data

Help needed with using Angular Component method. Developing a main html file with its main controller containing a JSON list of client data: clients: [{ "name": "John Jackson", "age": "21", "hair": "brown", }, { "name": "Janet Doe", ...

What causes scope to be undefined in Angular?

Using ionic to develop a hybrid app has been a smooth experience, especially with android! This is my login HTML: <body ng-app="starter"> <head> <script src="phonegap.js"></script> </head> <ion-header-ba ...

The CSS styles are not being applied correctly in the HTML document

I have this snippet in my .css file: .attachment-label { font-size: 10px; font-style: italic; color: rgba(0,0,0,.5); } When I try to use it in my HTML like this: <div class="card-body"> <span class=" ...

"Redirecting to an HTML page from the POST method is not supported in the Flask backend and Vanilla JS frontend setup

Utilizing the selected dropdown value from the frontend to perform calculations on the backend, resulting in an HTML page being returned. It's worth noting that no response is needed from the POST method, such as using return jsonify. Currently, I am ...

Maintain the collapsing of links in the navbar with the help of Bootstrap

Currently, I am designing a responsive navigation bar utilizing Bootstrap. The current layout displays as follows: https://i.sstatic.net/KglsX.png in expanded view, and: https://i.sstatic.net/DKvex.png in collapsed view. While the design appears satis ...

I want to create a custom jQuery slider totally from scratch

Greetings everyone, I have been tasked with creating a slider using only HTML / jQuery code. Here is the template: And here is the HTML code for the template above: <div id="viewport-container"> <section id="sliding-container"> & ...

Inspecting, Manipulating, and Analyzing Request Headers prior to sending them with Google Chrome

I have been on a quest to find a solution for my dilemma, but it seems to be eluding me. I am eager to set a breakpoint in Google Chrome just before a request is sent, enabling me to inspect and modify the request from the browser to the server. Furthermo ...

Creating a chat interface with chat bubbles in React JS can be done by implementing components such as Message

Having some JSON data stored in dummyData, I am seeking guidance on how to position chat bubbles on the left and right based on the direction. My framework of choice is Material UI along with the context API. The attached image serves as a visual reference ...

The contents of the div do not display when the button is pressed except in jsfiddle

I have written a script that triggers the appearance of a div where users can adjust the time settings for a timer. The functionality works perfectly on JSFiddle, with the div displaying as intended. However, when tested on other online IDEs such as Coding ...

Tips for converting plain text output into HTML tags

I recently set up a contact form 7 on my website, and I'm trying to customize the message that appears after submission. However, I'm running into an issue when attempting to split the message into two different colors. I created a span class to ...

Is CDATA insertion automatic in JavaScript within Yii framework?

Currently I am working with Yii and have noticed that whenever I insert any JavaScript code, it is automatically encapsulated in CDATA. I am curious as to why this is happening. Will there be any issues if I were to remove the CDATA tags, considering that ...

Solving the problem of Hover Effects in CSS

I am struggling to get the nav-link to be blue in color with a dark-blue hover effect. I managed to set the color correctly, but for some reason, the hover effect is not working. Can anyone help me figure out what the issue might be? Additionally, does any ...

Applying CSS classes to my div element

Check out the following code snippet: <div class="page-template-default logged-in"></div> I am trying to apply a class like this: .page-template-default .logged-in { } However, it doesn't seem to work. Any idea why? ...

The grid is out of alignment, causing elements to jump to the next row

After taking an online course at TreeHouse, I used the provided HTML & CSS code and made some adjustments to create a layout with 10 columns instead of the original 12 within a 1000px container. The columns were converted to percentages to fit my needs. I ...

The divs with the specified class are not applying the desired styles to my document. However, the input and labels are functioning correctly. What could I be overlooking?

Web Development : <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> The Coding Academy Survey</title> <link rel="stylesheet" href="styles.css" ...

having numerous collapsible elements that trigger a single django view function, each one submitting a distinct value

I have multiple collapsible items that need to trigger the same Django function when submitted with different values. https://i.sstatic.net/1BO19.png Is there a way to achieve this without using a dropdown menu in Django forms? What modifications should ...

Tips for updating the chosen value with jquery or javascript

I am facing a situation where I need to change the selected option in a dropdown menu using a function triggered onClick later in the application. <select id="myselect"> <option value=aa>aa</option> <option value=bb>bb</option&g ...

Loading Ajax dropdown with a preselected value in the dropdown menu

There are two pages, each containing a form. Page 1 - Form A) Includes a dropdown menu (with values populated from the database) and a continue button. <select name="form[formA][]" id="dropdown1"> <option value="1">Option 01</opti ...

What is the best way to incorporate a fresh array into the existing array element stored in local storage?

I stored a group of users in the local storage: let btnSignUp = document.getElementById("btnSignUp"); btnSignUp.addEventListener('click', (e) => { let existingUsers = JSON.parse(localStorage.getItem("allUsers")); if (existingUsers == null ...