How can I use CSS to hide a DIV during printing on my website?

I want to customize my page for printing.

Is there a way I can:

  • hide the heading <DIV id="heading"> when printing

  • display only the <DIV id="summary"> when printing?

Answer №1

@media screen { 
 #title{
  visibility:hidden;
 }
 #abstract{
  visibility:visible;
 }
}

Answer №2

One way to hide or show elements is by using @media blocks:

Here's an example of how you can do it in CSS:

@media print {
  #heading {
    display: none !important;
  }
}
@media screen {
  #summary{
    display: none !important;
  }
}

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 Jquery, update the class toggle to apply to multiple span elements instead

I am facing an issue where I need to change the class of a span child using a toggle feature when clicking on a browser row. The problem arises when there are multiple rows, as the span cannot be found and the functionality does not work properly. I have ...

How can you determine the CSS style value based on a different value?

Can I calculate a value based on another value? Here's an example: .my-div { width: 50px; height: calc(width * 2) } Is this doable? ...

Is there a way to use Selenium to perform testing on a web UI that generates XML content instead of HTML?

Utilizing Selenium for testing my Perl cgi script has been successful overall, but I've encountered a unique issue in one particular test case. In this scenario, the cgi script returns XML content to the web browser instead of the expected HTML conten ...

Show special characters with accents within an SVG element on a webpage written in HTML

I'm having trouble with accented characters (like á, é, etc) not displaying in my SVG object on an HTML page. Here's how the page is declared: <!DOCTYPE html> <html lang="en"> <head runat="server"> <meta charset="utf-8 ...

Error with Display of ASCII Character 62 in Superfish Menu

Currently, I have implemented the Superfish menu on my website. In order to indicate sub-menus within my menus, I have opted to utilize the character entity code &#62;, which historically has represented ">". Oddly enough, while viewing my website ...

Is it possible to incorporate a CSS3 transition into the styling of a list of images?

Looking to achieve a CSS3 linear transition for a "list-style-image" specifically for Firefox? You'll need to include "-moz-" in your code. -moz-transition: list-style-image 0.2s linear; However, the above code is not producing the desired result. I ...

Using Sass to dynamically add a parent class

Is there a method in SASS to automatically append "-center" to the CSS class for center alignment while maintaining the same width? I want both classes to have a width of 110px, but only the "-center" class should have text alignment set to center. .table ...

Choosing between setting a height of 100vh versus a minimum height of 100vh

In the development of my app, I noticed an interesting issue. When I set the background on the html with a height of 100vh and resize the viewport to cause vertical overflow, the background does not cover the overflowed content: html { height ...

Submit form only if the field value is valid

I created a form with an input field that captures the user's mobile number and validates it to ensure it begins with '0'. The validation process is functioning correctly, but I am encountering a problem when submitting the form. Even if the ...

Assigning a height of 100% to a div element results in the appearance of

In a div within the body, there are only 3 lines of text. The background color was only filling up to those 3 lines of text. To make the color fill up the entire vertical space of the browser, I adjusted the CSS height properties of html & body to be ...

Transferring a variable through a Navigation Bar selection

Currently, I have a PHP/HTML select box that is generated dynamically based on database variables. I utilize $_POST to identify the selection and handle it as needed. My goal is to transition this functionality into a dropdown menu within a navigation bar ...

Expand and reposition other div boxes by manipulating the div box dimensions

For my current project, I am aiming for a three-box style page. However, I am facing an issue where the boxes float over each other when they auto-expand to fit the content inside. This is due to the positioning that I have set for them. This is the HTML ...

What is the best way to design an element in HTML/CSS with a curved semicircle border at the top?

I'm looking to design an HTML/CSS element that features a semicircle at the top-middle with a border. Inside this semicircle, I want to place a smaller circle containing a single character (similar to the X in the provided image). Additionally, there ...

The function document.write does not display any content on the webpage

Check out this piece of code: <html> <head> <script language="JavaScript"> <!-- function myFunc() { var doc = parent.frames[1].document; doc.open(); doc.write(<htm ...

Unexpectedly, the boolean variables are turning true without any apparent cause

var Number1 = 0 var Number2 = 0 var ZeroVAR = "0" var OneVAR = "1" var TwoVAR = "2" var ThreeVAR = "3" var FourVAR = "4" var FiveVAR = "5" var SixVAR = "6" var SevenVAR = "7" var EightVAR = "8" var NineVAR = "9" var EquationN1 = 0 var EquationN2 = 0 var Ad ...

Images in the navigation bar are bouncing around on the page, even though the CSS and HTML configurations

We are experiencing some erratic behavior with our nav bar images that seems to occur only on page refreshes. The issue appears to be related to the loading of our sprite, which contains all the images for the nav bar links. Despite trying different float ...

Pop-Up Buttons Generated in Real-Time

As a backend developer, I often find myself struggling to understand how web browsers work when working on frontend tasks. In this case, I have left the JavaScript alert for ease of use. Depending on which button is clicked in the popover, it should displa ...

The initial child expands in width according to the content until it reaches the boundaries of the parent, triggering the

My goal is to achieve a layout where the parent container's width can vary. The first child element (red) should expand based on its content until it reaches the end of the parent, at which point text-overflow: ellipses should be applied. The second c ...

Is it possible to use only CSS to make a <div> element inherit the height of its parent <td>?

http://jsfiddle.net/ZAvDd/ I am facing an issue where as my table row increases in height, I want the div inside it to automatically adjust its height accordingly. Currently, the height of my div is always set to 0. I have tried using height: inherit, b ...

Using varied colors to style list items

Is there a way to apply three different colors to my list items? What is the best method for achieving this? This is what I have in my code: li { width: 33.333%; float: left; padding: 15px; list-style: none; } .light { background-color: #0 ...