The answer is generally no, but technically it is possible.
While the other answer here focuses upon a scenario in which Wake-on-LAN is used to turn other machines on, in order to infect them, that doesn't really directly answer the question of whether or not a machine can be infected while it is powered off.
First, it's worth clarifying what "powered off" means. When you shut your laptop's lid, what power state is it actually in? This is actually rather complicated. Modern systems support quite a wide range of sleep states, each with its own specific details around which system resources are powered.
At a high level, "sleep" means that the system's state is maintained through some means, in such a way that the computer will retain that state when powered back on. The exact implementation details of this depend on the specific sleep state that the system is in.
Sleep states are part of the ACPI specification for computers. S0 is the running state, i.e. what your computer is in right now if you're reading this.
S1, known as Power on Suspend (POS), is the type of suspend you might expect your laptop to be in if you shut the lid and then opened it again a moment later - the CPU and RAM are still powered, but the CPU is halted and does not execute instructions. Non-essential peripherals may be powered off. This is used in order to maintain responsiveness if the user quickly resumes use after the device starts to go to sleep. The power savings are low to moderate, but the system doesn't use this state long-term.
S2 is a slightly deeper sleep state, where the CPU is powered off, but RAM remains powered, and CPU cache information is backed up to RAM. The RAM continues to be fully powered and is refreshed at full speed. Some system peripherals may stay on, but most are powered down.
S3 is what most people are familiar with, and what the "Sleep" button usually does in an OS. The CPU is powered off, like with S2, but the RAM is refreshed at a lower speed, most onboard supervisory circuits are put into a sleep state, the power supply runs in more efficient low-power mode, and all peripherals are powered off or put into a standby mode. This takes longer to resume from, but is the lowest power mode where the RAM stays active.
For all three states above, you lose the system state if you disconnect power from the system, because the RAM loses power.
S4 is an interesting one, because it's functionally the same as powering the system off. It is more commonly known as "Hibernate". The contents of memory are written to non-volatile storage, such as a hard drive, and the system is powered down. The CPU is off, the RAM is not powered, and the system is effectively switched off in the same way that it would be on a normal shutdown. When the computer is powered back on, it recovers the system state from storage and resumes from where it was before. This is separated out as its own power state because it is important for devices to be aware that the system is resuming from an S4 state when it powers back up, rather than doing a "fresh" boot.
S5 is the Soft Off state, which most of us would think of as shutdown. This is where the system is effectively "off", but the PSU is still plugged into a power source. In this state, the PSU continues to provide a small amount of standby power to the motherboard, allowing it to be powered on when the user presses the power switch. Supervisory circuits on the motherboard continue to be powered, and standby functions of peripherals (e.g. Wake-on-LAN on NICs, USB charging ports, etc.) remain operational.
Below S5 is G3, aka. "Mechanical Off". This is where the system has been disconnected from its power source, e.g. by removing the power cable or laptop battery. Supervisory circuits are powered down and no standby functionality can operate.
Another more recent approach is "Hybrid Sleep", wherein the operating system performs the setup steps for S4 (i.e. writing system state to disk) but enters S3 instead. This offers the responsiveness of resuming from S3 sleep without a full power on sequence, but retains state if the system loses power (G3) or is moved into Soft Off state (effectively S4) by the onboard supervisory circuits.
Even when the computer is operating in a Mechanical Off state, some components still retain power through a small onboard battery. The primary two components that are powered by this battery are the real-time clock (RTC) used to maintain the date/time on the system, and the volatile memory IC (aka "CMOS", although this is a misnomer) used to store BIOS/UEFI settings. Modern systems may use an non-volatile EEPROM for the latter, which does not require battery power.
The reason this all matters is because a computer that is quiet and has no display may be in any number of sleep states. The question of "can my computer be attacked while it is off?" is dependent on exactly how "off" it is.
A basic rule of thumb here is that the operating system is not functional in any other sleep state than S0, i.e. fully running. If we're talking about regular malware trying to exploit an OS vulnerability or write malicious files into shared folders, S0 is the only state this can occur in. The applications and operating system are not executing in the S1 state or lower, so any regular vulnerabilities in them are effectively moot at that point.
But that doesn't mean the system isn't vulnerable to attack over the network.
The clearest example here is out-of-band management, also known as lights-out management. OOB management allows you to communicate with the system while it is powered off (Soft Off), over the network, independently of the system state and operating system. You may be familiar with implementations such as AMT, iLO, and DRAC. This functionality is implemented by a Baseboard Management Controller (BMC), which remains powered independently of the current sleep state. This allows administrators to remotely monitor the system, change hardware settings (think of it like remote BIOS/UEFI config), change the boot device, power the system on and off, and other administrative tasks. An OOB management solution may offer other features like remote access (VNC) so that POST and the OS display can be viewed and interacted with remotely.
Most consumer systems do not come with a BMC. On server platforms the BMC is usually a dedicated piece of hardware that plugs into the motherboard, with its own CPU, RAM, and network interface. Higher-end Intel CPUs come with a feature called Active Management Technology (AMT), which is effectively an integrated BMC. This feature is implemented by the CPU itself, and the Intel Platform Controller Hub (PCH), which is more commonly referred to as the chipset.
These systems have access to privileged system resources such as memory. If an attacker can gain control over the BMC, they can maintain access to the system as long as it is in a Soft Off power state or higher. Vulnerabilities in the OOB management stack can be very powerful, and many have been found over the years.
A more advanced approach would be to attack the peripheral devices themselves. Network controllers (NICs) are extremely feature-rich these days, and have a significant amount of firmware. It is entirely possible that a network card could be compromised over the network using a vulnerability in its firmware. Once the card is compromised, it could be leveraged to access system memory using DMA over the PCIe bus. This may still occur in low sleep states if a wired network card is kept running.
As for why you're not hearing about attackers using these tricks all the time: it's really hard work to develop these exploits, and it's generally not worth the effort. Vulnerabilities in iLO, DRAC, and network cards only work against specific targets (i.e. systems with a vulnerable version of that technology) and require a ton of knowledge and development time to build. Discovering and exploiting vulnerabilities in more widespread management technologies like AMT also requires a lot of advanced R&D, and it makes no sense to burn a capability like that on an average bit of banking malware or ransomware - you can make a lot more money selling it to governments, with the added bonus of not worrying about jail in the process.