Skip to content

Instantly share code, notes, and snippets.

@distancify-oscar
Last active July 13, 2022 09:11
Show Gist options
  • Save distancify-oscar/01634270498c5ad60e8cdf9e70809c22 to your computer and use it in GitHub Desktop.
Save distancify-oscar/01634270498c5ad60e8cdf9e70809c22 to your computer and use it in GitHub Desktop.
CSS tricks by Oscar
.textContainer {
background-image: url(imageUrl);
background-clip: text;
color: transparent;
}
<!-- The solution adds a bold psuedo element containing the text
'Content' which increases the width of the containing span slightly.
If the text-content of the span becomes bold on hover or select, the
size of the span will not increase thanks to this.-->
<span
class="text-container"
text="Content"
>
Content
</span>
<style>
.text-container {
display: inline-block;
text-align: center;
}
.text-container::after {
display: block;
content: attr(text);
font-weight: bold;
height: 0px;
color: transparent;
overflow: hidden;
visibility: hidden
}
</style>
<!-- The overlay class enables the grey background on
an image with an otherwise white background, without
affecting the color of the item in the image -->
<div class="container">
<div class="spacer"></div>
<div class="overlay"></div>
<img class="image" src="example.jpg">
</div>
<style>
.container {
overflow: hidden;
position: relative;
width: 100%;
}
.spacer {
padding-top: 150%; /* this value is based on the parent containers WIDTH */
}
.image {
position: absolute;
top: 0;
height: 100%;
width: 100%;
object-fit: cover;
margin: auto;
}
.overlay {
z-index: 10;
position: absolute;
inset: 0;
background-color: #efefef;
mix-blend-mode: darken;
}
/* Fix IE11 opacity bug */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
.overlay {
opacity: 0;
}
}
</style>
.text-container {
/* limits the displayed text to 2 lines and puts
ellipsis on last word if sentence is longer */
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
.container-with-scroll {
scroll-snap-type: x mandatory;
overflow-x: auto;
scroll-behavior: smooth;
-ms-overflow-style: none; /* IE & Edge */
scrollbar-width: none; /* Firefox */
}
.container-with-scroll::-webkit-scrollbar {
display: none; /* Chrome, Safari, and Opera */
}
.container-child {
scroll-snap-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="product-card__compare-wrapper">
<div class="product-card__compare-text">{{ compareText }}</div>
<div
class="product-card__compare-switch"
:class="{
'product-card__compare-switch--enabled': compareProduct,
}"
@click.stop.prevent="toggleCompare"
>
<div
class="product-card__compare-button"
:class="{
'product-card__compare-button--enabled': compareProduct,
}"
></div>
</div>
</div>
</body>
<style>
.product-card__compare-wrapper {
margin-left: auto;
position: relative;
}
.product-card__compare-text {
font-size: 11px;
font-weight: 700;
text-align: center;
position: absolute;
top: -16px;
left: 4px;
}
.product-card__compare-switch {
height: 22px;
width: 45px;
border-radius: 11px;
border: 1px solid #979797;
display: flex;
align-items: center;
padding: 2px;
}
.product-card__compare-button {
height: 16px;
width: 16px;
border-radius: 50%;
background: #979797;
}
.product-card__compare-switch--enabled {
border-color: var(--color-main-100);
justify-content: flex-end;
}
.product-card__compare-button--enabled {
background: var(--color-main-100);
}
</style>
</html>
<!-- TODO - implement shit -->
<div>
<svg class="nuxt-logo" viewBox="0 0 45 30" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M24.7203 29.704H41.1008C41.6211 29.7041 42.1322 29.5669 42.5828 29.3061C43.0334 29.0454 43.4075 28.6704 43.6675 28.2188C43.9275 27.7672 44.0643 27.2549 44.0641 26.7335C44.0639 26.2121 43.9266 25.6999 43.6662 25.2485L32.6655 6.15312C32.4055 5.70162 32.0315 5.32667 31.581 5.06598C31.1305 4.8053 30.6195 4.66805 30.0994 4.66805C29.5792 4.66805 29.0682 4.8053 28.6177 5.06598C28.1672 5.32667 27.7932 5.70162 27.5332 6.15312L24.7203 11.039L19.2208 1.48485C18.9606 1.03338 18.5864 0.658493 18.1358 0.397853C17.6852 0.137213 17.1741 0 16.6538 0C16.1336 0 15.6225 0.137213 15.1719 0.397853C14.7213 0.658493 14.3471 1.03338 14.0868 1.48485L0.397874 25.2485C0.137452 25.6999 0.000226653 26.2121 2.8053e-07 26.7335C-0.000226092 27.2549 0.136554 27.7672 0.396584 28.2188C0.656614 28.6704 1.03072 29.0454 1.48129 29.3061C1.93185 29.5669 2.44298 29.7041 2.96326 29.704H13.2456C17.3195 29.704 20.3239 27.9106 22.3912 24.4118L27.4102 15.7008L30.0986 11.039L38.1667 25.0422H27.4102L24.7203 29.704ZM13.0779 25.0374L5.9022 25.0358L16.6586 6.36589L22.0257 15.7008L18.4322 21.9401C17.0593 24.2103 15.4996 25.0374 13.0779 25.0374Z" fill="#00DC82" />
</svg>
</div>
<style>
.nuxt-logo {
height: 180px;
filter: /* This filter allows the shadow to follow the shape of an SVG to make it stand out more */
drop-shadow(
3px 3px 10px hsl(220deg 60% 50% / 1)
)
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment