Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
How to use css property attr here?

I have next realized tooltips (see snippet code).

body
{
    font-family: 'Arial', sans-serif;
    line-height: 1;

    min-height: 100vh;

    display: flex;
    justify-content: center;
    align-items: center;
}

*,
*:before,
*:after
{
    box-sizing: border-box;

    margin: 0;
    padding: 0;
}

.button
{
    position: relative;
    cursor: pointer;
    border: none;
    text-transform: uppercase;

    font-family: 'Montserrat', sans-serif;

    color: #fff;
    background-color: #21262b;

    border-radius: 5px;
    padding: 10px;

    font-weight: 700;
}

.button {
    margin: 0 10px;
}

.button::after {
    position: absolute;
    content: attr(data-tooltip);
    background: #21262b;
    padding: 5px;
    white-space: nowrap;
    border-radius: 5px;
    font-weight: 400;
    text-transform: none;
    min-width: 50px;

    left: 50%;
    top: -100%;
    transform: translateX(-50%);
}

.button::before {
    content: "";
    width: 10px;
    height: 10px;
    background: #21262b;
    position: absolute;
    top: -50%;
    left: 50%;
    transform: rotate(45deg) translate(0, 50%);
}

.button::before,
.button::after {
    opacity: 0;
}

.button:hover::before,
.button:hover::after {
    opacity: 1;
}
<button data-tooltip="Lorem Ipsum" class="button">Tooltip Button</button>
<button data-tooltip="Lorem Ipsum" class="button">Tooltip Button</button>
<button data-tooltip="Lorem Ipsum" class="button">Tooltip Button</button>
<button data-tooltip="Lorem Ipsum" class="button">Tooltip Button</button>

I want to add an additional data attribute for each button. Let me say it would be data-tooltip-left, data-tooltip-bottom, data-tooltip-top, data-tooltip-right. And for separate pseudo element after i want to change position. Or i just should remove general attribute data-tooltip? And for each of data-tooltip-position applying same styles but different position.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Use attribute selectors.

In your case, you can set position like this data-tooltip-position="bottom".
The only one position attribute is enough, to prevent mistake for multiple position like this data-tooltip-bottom="" data-tooltip-top="". They are opposite positions.
For more combine position you can use data-tooltip-position="bottomleft".

Example:

<button data-tooltip="Lorem Ipsum" class="button">Tooltip Button</button>
<button data-tooltip="Lorem Ipsum bottom" class="button" data-tooltip-position="bottom">Tooltip Button</button>

In CSS, use selector like this.

.button[data-tooltip-position="bottom"]::after {
    top: auto;
    bottom: -100%;
}
.button[data-tooltip-position="bottom"]::before {
    top: 100%;
    transform: rotate(45deg) translate(0, 100%);
}

See it in action

about 4 years ago · Juan Pablo Isaza Denunciar

0

/try using this way/

a:after {
  content: " (" attr(href) ")";
}

/this link might help you as well/

https://developer.mozilla.org/en-US/docs/Web/CSS/attr()

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda