search
HomeWeb Front-endCSS TutorialSeveral methods and ideas for exchanging pictures for words_Experience exchange

Today, a friend encountered a problem when making a web page: he wanted to keep the background of the link, but also wanted the text in the link to disappear! But after working on it for a long time, I still couldn't get rid of this text. I think many friends who study standards have encountered this problem. Here I will write down several commonly used methods and explain the ideas, hoping to help friends who are just starting to learn.

"Replace pictures with words" means replacing text expressions with pictures. We all know that the representation of text in browsers is very poor. It is jagged, cannot be rounded, and cannot have many effects. Under normal circumstances, the content part of a web page does not need to be effected, but in WEB standards, these are often needed for logos and titles. If we use a table to do it, we just post a picture somewhere. This method is relatively simple, but it is not conducive to search. So we need to do it in a standard way to ensure that the web page is in a good state and is conducive to search. Usually displayed as shown in the figure

: (display:none;) This does not just make the contents of the container disappear but also the container itself. Therefore, we must make another container within the container to ensure that the background in the container can be displayed normally after the inner part disappears. Example:

Copy code The code is as follows:
#logo {display:none; background:URL; width:300px; height:100px;}

If it is written like this, you will not see anything at all. So what is the correct way to write it? Look at the example:

Copy code The code is as follows:
#logo {background:URL; width:300px; height:100px;}#logo span {display:none;}
Please pay attention to the above code , the background is defined under #logo, and #logo span has no style except display:none;. Because the container with the display:none; attribute defined will not see anything, it is a waste to define other styles. There are still problems with this alone. This is an example without a link. So what should we do when there is a link? Let’s look at another example:

Copy code The code is as follows:
#logo {background:URL; width:300px; height:100px;}#logo a {display:none;}

Can you guess what this code can display? The fact is that the background is displayed, but the link is gone. As we said above: the container itself that is assigned the display:none; attribute will also disappear. Then we know clearly that we must add a container to this A tag. Let’s look at the example again:

Copy code The code is as follows:
#logo {background:URL; width:300px; height:100px;}#logo a span {display:none;}
Is this correct? Still not working, why? We all know that A is not a block-level tag, which means that the height and width of A are determined by the content. Now that the content has disappeared, the height and width attributes will no longer exist, so the link will be It has become a link without a hot zone. It may not be lit. We need to modify the above code again.

Copy code The code is as follows:
#logo a {background:URL; width:300px; height:100px; display:block;}#logo a span {display:none;}

Note that the attribute of the A tag here must be added with display:block; to force it to be a block-level element. In this way, the A tag becomes a link form with a width of 300 and a height of 100, with a background and no text content. Everyone saw that a span tag was added to the A tag above, which seems a bit redundant. Can the effect be achieved without span? Yes, but the idea is different, it is the following position shifting method.

Position movement: that is, the content is moved out of the display area. Let’s look at the code to understand this method.

Copy code The code is as follows:
#logo, #logo a {width:300px; height:100px; overflow:hidden;}#logo a {background :URL; padding:100px 0 0; display:block;}
In CSS, #logo and A have an overflow hidden (overflow:hidden;), which means that if the size exceeds 300*100, it will be hidden. . We see that A is defined with a padding: 100px 0 0; This top padding just pushes the content outside the display area. So why does #logo also use overflow:hidden;? Because there will be a small bug under IE, the content of A cannot overflow and hide, so it is necessary to add an overflow:hidden on the parent tag;

The above are just two of my more commonly used methods. Of course, there are other methods, each of which has its own shortcomings, but the various methods are also complementary to each other. You can choose to use it according to the situation when applying.
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
A Little Reminder That Pseudo Elements are Children, Kinda.A Little Reminder That Pseudo Elements are Children, Kinda.Apr 19, 2025 am 11:39 AM

Here's a container with some child elements:

Menus with 'Dynamic Hit Areas'Menus with 'Dynamic Hit Areas'Apr 19, 2025 am 11:37 AM

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

Improving Video Accessibility with WebVTTImproving Video Accessibility with WebVTTApr 19, 2025 am 11:27 AM

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

Weekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteWeekly Platform News: CSS ::marker pseudo-element, pre-rendering web components, adding Webmention to your siteApr 19, 2025 am 11:25 AM

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

Making width and flexible items play nice togetherMaking width and flexible items play nice togetherApr 19, 2025 am 11:23 AM

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

Position Sticky and Table HeadersPosition Sticky and Table HeadersApr 19, 2025 am 11:21 AM

You can't position: sticky; a

Weekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryWeekly Platform News: HTML Inspection in Search Console, Global Scope of Scripts, Babel env Adds defaults QueryApr 19, 2025 am 11:18 AM

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

IndieWeb and WebmentionsIndieWeb and WebmentionsApr 19, 2025 am 11:16 AM

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment