Câu hỏi phỏng vấn CSS
Câu hỏi

What are the different ways to visually hide conte...

Câu trả lời

To visually hide content while making it available only for screen readers, several CSS techniques can be employed. These methods ensure that the content is not visible on the screen but remains accessible to screen readers, which are used by individuals with visual impairments. Here are the primary techniques:

  1. Using the clip or clip-path Property:
    This method involves using the CSS clip or clip-path property to create a small, invisible clipping region into which the content is placed. The content is technically on the page but is clipped to a tiny, invisible area. For example:

    css Copy
    .visually-hidden {
        position: absolute;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        height: 1px;
        width: 1px;
        overflow: hidden;
        white-space: nowrap;
    }

    This method is effective for hiding content visually but keeping it accessible to screen readers[1][2][4][7].

  2. Absolute Positioning Off-Screen:
    This technique involves positioning the content far off the visible area of the screen. Typically, this is done by using negative text-indent or positioning the content outside the visible viewport:

    css Copy
    .visually-hidden {
        position: absolute;
        left: -10000px;
        width: 1px;
        height: 1px;
        overflow: hidden;
    }

    This method ensures that the content is not visible on the screen but is still read by screen readers[2][4].

  3. Zero Size:
    Content can be made visually hidden by setting its size to zero:

    css Copy
    .visually-hidden {
        height: 0;
        width: 0;
        overflow: hidden;
    }

    This makes the element occupy no space visually, but it can still ...

senior

senior

Gợi ý câu hỏi phỏng vấn

middle

What's the difference between a relative , fixed , absolute and static ally
positioned element?

junior

What is a CSS rule?

junior

Have you played around with the new CSS Flexbox or Grid specs?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào