Managing the css @print feature within the WordPress admin interface

When attempting to use 'window.print()' to print only a specific div inside the WordPress admin area, I tried enqueueing CSS to load on the desired page and hide all elements except for the target div. However, the issue arises when the text formatting and background image are missing from the print preview.
Here is the CSS code:

#brgprint .toplogo{
        background-image: url(https://www.agilsaude.com.br/wp-content/uploads/2013/09/logo_agilsaude3.png);
        width:100px;
        height:60px;
        margin:auto;
    }
    #brgprint p.assinatura{
        width:200px;
        margin: 20px auto;
        border-top: 1px black;
    }
@media print {
    #adminmenuback, #adminmenuwrap, #wpfooter, #wpbody-content .update-nag, #contextual-help-link-wrap, #wpbody-content .wrap h2, #woo_vou_check_voucher_code_container .handlediv, #woo_vou_check_voucher_code_container h3, .woo-vou-check-code tbody tr, .woo-vou-voucher-code-submit-wrap .button-primary {display:none}
    #brgprint {width:100%!important;margin:0!important;
    display:block!important;
    top: 0px;
    left: 0px;
    margin: 0px;
    padding: 0px;
    position: absolute;
    width: 640px;
    }
    #brgprint .toplogo{
        display:block!important;
        background-image: url(https://www.agilsaude.com.br/wp-content/uploads/2013/09/logo_agilsaude3.png)!important;
        width:100px!important;
        height:60px!important;
        margin:auto!important;
    }
    #brgprint p.assinatura{
        width:200px!important;
        margin: 20px auto!important;
        border-top: 1px black!important;
    }
    #wpwrap, #wpcontent, #wpbody, #wpbody-content, #woo_vou_check_voucher_code_wrap.post-box-container,     #woo_vou_check_voucher_code_container.postbox, #woo_vou_check_voucher_code_container.postbox.inside, tr.woo-vou-voucher-code-submit-wrap, tr.woo-vou-voucher-code-submit-wrap td {
    position: absolute;
    margin: 0;
    padding: 0;
    border: none;
    width:100%;
    }
}

The specific div intended for printing:

<div class="brgprint">
  <div class="toplogo" style="background-image: url(https://www.agilsaude.com.br/wp-content/uploads/2013/09/logo_agilsaude3.png);width:100px;height:60px;margin:auto;display:block;float:none;"></div>
  <h2 style:"text-align:center"="">Declaração de atendimento</h2>
  <p>Declaro que o cliente Helder Lima, portador do CPF , na presente data está realizando o atendimento do produto e/ou serviço Teste de Voucher na clínica e/ou profissional Agil Saude.</p><p> Receberei o valor de R$ 100 pela prestação de serviços.</p><p>14 / 08 / 2014</p>
  <p style="width:200px;margin: 20px auto;border-top: 1px;">Assinatura</p></div>

While it displays correctly in the browser, the printed output shows plain-text without the top logo.

Answer №1

Opt for using the img tag instead of applying inline styles to the logo. Customize its appearance in your CSS file by assigning a class.

<img class="toplogo" src="https://www.agilsaude.com.br/wp-content/uploads/2013/09/logo_agilsaude3.png">

DEMO JSFiddle

EDIT Also, note that brgprint is not an ID but a class. In your CSS, make sure to reference it as .brgprint instead of #brgprint. Check out this modified version on JSFiddle where I changed it to an ID in the HTML: http://jsfiddle.net/r5k4mxa2/1/

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

Modifying the class of an HTML element using JavaScript

Is it possible to dynamically change the class of an HTML element based on a user's selection with a radio button? I am facing an issue where I receive the following error message: "Error: missing ) after argument list Source File: website Line: 1, C ...

Encountering issues due to overriding JSON.stringify

Recently, I developed a customized function for JSON.stringify implementation as shown below: JSON.stringify = function (item, replacer, space) { return JSON.stringify(item, replacer, space); } This modification led to multiple errors in AngularJS w ...

What is the best way to transfer data from a div tag to an li tag using JavaScript?

https://i.stack.imgur.com/se2qk.pngI am attempting to change the div tag content to li tag. Here is a snippet of the code from inspect for reference. I need to remove the div tag with the "domTitle" class. <li style="display: inline;" id="list_name"> ...

gulp-open not functioning properly following the use of createWriteStream

I am utilizing gulp, gulp-eslint, and gulp-open to generate a report detailing ESLint outcomes. The linting and file creation processes function correctly; however, the task aimed at opening the file containing my report encounters issues. gulp.task(&apos ...

AngularJS/Restangular index-based extraction of JSON data

I have developed an application that takes input for quotes (purity, weight, total) and stores it in the $scope.quote array: // Controller action // $scope.quote.push({ total: ((($scope.karat * $scope.spot) * $scope.percentage) / 20) * $scope.estimated ...

Challenges with PHP registration forms, data not being stored in database

My login system was working perfectly until my PC crashed while I was editing it. Now there seems to be a mistake somewhere that I can't pinpoint. Can someone help me spot the error? <?php if(isset($_SESSION['login_user'])){ ...

Once chosen, zoom in on the map to view the results

I am facing an issue with multiple selects in my code, where one select depends on the result of another. The ultimate goal is to zoom in on the area that has been searched and found, but unfortunately, it is not functioning as expected. If you'd lik ...

Troubleshooting MySQL Database Insertion Errors caused by Dynamic Forms

<body> <?php $con = mysqli_connect('localhost','root','','cash'); $query = "SELECT DISTINCT category FROM cash"; $result = mysqli_query($con,$query); $dropDownList = &apo ...

Result box not displaying the expected JQuery UI Autocomplete results

Can someone assist me with Autocomplete? When I search for an RTO code, the result box appears but without a list (refer to Screen : 1). However, when I press the down arrow button on the keyboard, the list starts appearing one by one (as shown in Screen : ...

Develop content specific to different geographic locations for a web application using PHP

I have been working on a PHP-based online shopping website but have not had much success with it. example.com After trying multiple approaches without success, I have decided to implement an admin feature for adding locations. For instance, if I add "Mad ...

Using the combination of PHP and AJAX, modify files in real-time

Looking to dynamically change files based on screen resolution, I have three files: index.php main.js testA.php testB.php The index.php file will dynamically call testA and testB. If the screen resolution is desktop size, index.php should include testA ...

Why is the code able to execute following the setState hook without any listener declared in the useEffect hook?

Recently, I came across an expo barcode scanner example where a function is executed after a setState hook. This puzzled me as I thought that calling the setState hook would trigger a re-render of the component. Can anyone explain why the function runs aft ...

Modify the style of an element using a media query and Angular 4

Is there a way to update a class of an element based on the browser's width in my .ts file? matchMedia('(max-width: 400px)').addListener((mql => { if (mql.matches) { this.myclass = 'toggled'; } })); In the HTML, it shou ...

Utilizing jQuery for clearing specific input fields within a WTForm

Within my Flask application, I encounter a scenario where I have a form with multiple fields. The form contains two submit buttons, with the objective of only submitting data from fields one and two, while ignoring the other fields even if they have conten ...

Modify the value of a variable inside another {{variable}} (not sure what it's called)

I am looking to update the variable "prefs" to reflect either "easy, medium, or hard" options based on user interaction. For instance: THIS {{choice.prefs.title}} NEEDS TO BE UPDATED TO {{choice.easy.price}} or {{choice.medium.price}} or {{choice.hard. ...

The PasswordResetView in Django using Vue.js encounters a 403 Forbidden error when attempting to post with Axios due to an

I'm currently working on building a unique Email Restore page in the frontend using Vue.js. My goal is to send email input data via Axios to /api/v1/accounts/password_reset/, essentially utilizing the original ResetPasswordView as an endpoint instead ...

Utilizing JavaScript Callbacks in HTML Image Tags

Currently I am working on a small application and looking to include a YouTube section. I have come across a method for obtaining the user's YouTube icon: This is included in the head section of my code: <script type="text/javascript" src="http:/ ...

Bootstrap's inline form features a button on a separate line from the rest of the form

I grabbed this code directly from bootstrap's official documentation: <form class="form-inline"> <div class="form-group"> <label class="sr-only" for="exampleInputAmount">Amount (in dollars)</label> <div class="inp ...

Ensure that only numerical values in decimal form are permitted when entering data in Angular

How can I restrict user input to only decimal values? Here is the HTML code for my input field: <label for="conversion-factor">Conversion Factor:</label> <input type="text" class="form-control form-control-sm" id="conversion-factor" ...

Guide on how to utilize JavaScript to redirect to a URL for PUT or POST requests by clicking a button

I have a button <button class="delivery-orders-button" onclick="markDone(${order.order_id})">Dispatch order</button> and my goal is to have the markDone function redirect the user to a designated page, similar to how forms ...