I did not use the standard approach in CSS, is there a more semantically correct approach and moree cross-browser to solving such problems?
Problems:
Many code.
Using the property ::after (I think this is superfluous).
The button has a fixed size.
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
background: #050B1F;
}
#button-continue {
margin-top: 46px;
width: 331px;
height: 54px;
border: 3px solid transparent;
border-radius: 56px;
background-color: rgba(11, 27, 55, 1);
position:relative;
cursor:pointer;
}
#button-continue::after {
content: "";
width:337px;
height:60px;
position:absolute;
z-index:-5;
top:-6px;
left:-6px;
border-radius: 56px;
background-image: radial-gradient(circle closest-side at 40% -40px, rgba(255, 255, 255, 1), rgba(31, 119, 200, 1) 120px);
}
.button-continue__text {
text-transform: uppercase;
font-size: 0.875em;
color: #99CEFF;
font-weight: 400;
}
.button-continue__text::after {
content: url('img/icon-continue.svg');
position: relative;
top: 3px;
left: 10px;
}
<button id="button-continue">
<span class="button-continue__text">Continue</span>
</button>
I found this example online.
By using this you can avoid using a pseudo-element. But the problem I found was that the created border-image does not bend around the border-radius. So this is probably not what you are looking for.
Using a plain-coloured border would work, but the background image is not made to work with rounded borders. So what you did is probably the way to do it.
I'll just include my code for completeness, but be warned.
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
background: #050B1F;
}
#button-continue {
margin-top: 46px;
width: 331px;
height: 54px;
border-width: 3px;
border-style: solid;
border-radius: 56px;
border-image: radial-gradient(circle closest-side at 40% -40px, rgba(255, 255, 255, 1), rgba(31, 119, 200, 1) 120px) 1 round;
background-color: rgba(11, 27, 55, 1);
position: relative;
cursor: pointer;
overflow: hidden;
}
.button-continue__text {
text-transform: uppercase;
font-size: 0.875em;
color: #99CEFF;
font-weight: 400;
}
<button id="button-continue">
<span class="button-continue__text">Continue</span>
</button>
Related
I have problem with adding transition on gradient. I know that its impossible to transition gradient and I found a solution. https://keithjgrant.com/posts/2017/07/transitioning-gradients/
The background-image should be revealed in time. This button have background-color: black; and should change on gradient with hover. Any idea how can I make this on a hover pseudoclass?
.register {
float: right;
padding: 0 20px;
text-transform: uppercase;
}
.register a {
border: 1px solid white;
border-radius: 4px;
}
.register a:hover {
background-image: linear-gradient( to bottom right, rgb(40, 40, 40), rgb(60, 60, 60));
}
<li class="register">register</li>
You could try doing a transition from white to black (if, by your suggested code snippet, that is what you'd like).
<a class="btn btn-1">Hover me</a>
Accompanied by CSS:
.btn {
flex: 1 1 auto;
margin: 10px;
padding: 30px;
text-align: center;
text-transform: uppercase;
transition: 0.5s;
background: linear-gradient(90deg, var(--c1, #fff), var(--c2, #333) 51%, var(--c1, #000)) var(--x, 0)/ 200%;
color: white;
}
.btn:hover { --x: 100%; }
.btn-1 {
--c1: #fff;
--c2: #000;
}
See my fiddle for more
https://jsfiddle.net/80f7t1ej/
I have an input field that has a gradient border, but the text inside is too close to it.
And I have already tried padding-left, but that made the border on the left bigger, and the text was still close to the border.
The picture of the input field:
.inputfield {
margin-top: 5px;
-moz-appearance: none;
outline:0;
width: 170px;
height: 40px;
font-family: 'Montserrat', sans-serif;
color: white;
position: relative;
padding: 5px;
background-color: rgb(11, 15, 31);
border: solid 0.5px transparent;
border-radius: 80px;
background-image: linear-gradient(rgb(11, 15, 31), rgb(11, 15, 31)), radial-gradient(circle at top
left, rgb(76, 133, 242),rgb(144, 104, 235));
background-origin: border-box;
background-clip: content-box, border-box;
}
This is what it does when add padding-left
You could introduce a wrapper element around your input. A quick example built into your existing code would look something like this:
.input-wrapper {
width: 170px;
height: 40px;
padding: 5px;
border-radius: 80px;
background-image: linear-gradient(rgb(11, 15, 31), rgb(11, 15, 31)), radial-gradient(circle at top
left, rgb(76, 133, 242),rgb(144, 104, 235));
background-clip: content-box, border-box;
display: flex;
align-items: center;
}
.input-field {
outline: 0;
background-color: transparent;
color: white;
border: none;
width: 100%;
margin: 0 10px;
font-size: 16px;
}
<div class="input-wrapper">
<input class="input-field" value="TEXT">
</div>
Simply add padding-left to input[type=text].
I am animating a background to move but as expected using Background-position results in poor performance.
I am unable to alter or change the HTML or add any scripts
I have attempted using translate but this moves the entire div element rather than just the background, As mentioned I am not able to create a separate div for the background alone resulting in this roadblock.
.wm-outer-div {
width: auto !important;
min-width: 400px !important;
max-width: 500px !important;
padding: 0 !important;
-moz-box-sizing: border-box !important;
box-sizing: border-box !important;
border-radius: 15px !important;
box-shadow: rgba(50, 50, 50, 0.45) 0px 0px 10px 0px;
background-color: rgb(255, 255, 255);
padding: 18px 22px 20px;
position: absolute;
width: 304px;
color: rgb(55, 55, 55);
font-family: walkme-opensans, sans-serif;
display: block;
margin: 0px;
vertical-align: baseline;
border-collapse: inherit;
background-image: none;
line-height: normal;
height: 300px;
text-indent: inherit;
letter-spacing: normal;
text-transform: none;
text-shadow: none;
border-style: none;
border-width: medium;
transition: none 0s ease 0s;
box-sizing: content-box;
direction: ltr;
z-index: 2147483632;
opacity: 1;
}
.wm-outer-div:after {
content: "" !important;
z-index: -1 !important;
background-color: #1E365E !important;
background-image: url("https://www.dropbox.com/s/zrzzbsa5b39w8ra/image.jpg dl=1") !important;
position: absolute !important;
top: 0;
left: 0;
width: 100% !important;
height: 100% !important;
animation: slide 120s linear infinite !important;
repeat: repeat !important;
-moz-box-sizing: border-box !important;
box-sizing: border-box !important;
border-radius: 15px !important;
}
#keyframes slide {
from {
transform: translateY(0);
}
to {
transform: translateY(-187%);
}
}
<div class="wm-outer-div wm-shoutout wm-shoutout-165013 wm-template-bg wm-template-small-corner wm-ltr wm-chrome wm-design-template-207418 wm-position-center" id="wm-shoutout-165013"></div>
Is there a way to target the background image separately to use translate without the addition of another div/wrapper so only the background moves and not the entire div element?
Failing that is there another option that could improve the performance of the background animation?
Make the pseudo element bigger to be sure you will cover the needed area when translating:
.wm-outer-div {
min-width: 400px !important;
max-width: 500px !important;
padding: 0 !important;
-moz-box-sizing: border-box !important;
box-sizing: border-box !important;
border-radius: 15px;
box-shadow: rgba(50, 50, 50, 0.45) 0px 0px 10px 0px;
background-color: rgb(255, 255, 255);
padding: 18px 22px 20px;
width: 304px;
color: rgb(55, 55, 55);
height: 300px;
z-index: 0;
position:relative;
overflow:hidden;
}
.wm-outer-div:after {
content: "";
z-index: -1;
background-color: #1E365E !important;
background-image:url(https://i.stack.imgur.com/DpyrV.jpg);
background-size:cover;
position: absolute;
top: -100%;
left: -100%;
width: 300% ;
height: 300%;
animation: slide 2s linear infinite alternate;
box-sizing: border-box;
}
#keyframes slide {
from {
transform: translateY(33%);
}
to {
transform: translateY(-33%);
}
}
<div class="wm-outer-div wm-shoutout wm-shoutout-165013 wm-template-bg wm-template-small-corner wm-ltr wm-chrome wm-design-template-207418 wm-position-center" id="wm-shoutout-165013"></div>
.wm-outer-div {
width: auto !important;
min-width: 400px !important;
max-width: 500px !important;
padding: 0 !important;
-moz-box-sizing: border-box !important;
box-sizing: border-box !important;
border-radius: 15px !important;
box-shadow: rgba(50, 50, 50, 0.45) 0px 0px 10px 0px;
background-color: rgb(255, 255, 255);
padding: 18px 22px 20px;
position: absolute;
width: 304px;
color: rgb(55, 55, 55);
font-family: walkme-opensans, sans-serif;
display: block;
margin: 0px;
vertical-align: baseline;
border-collapse: inherit;
background-image: none;
line-height: normal;
height: 300px;
text-indent: inherit;
letter-spacing: normal;
text-transform: none;
text-shadow: none;
border-style: none;
border-width: medium;
transition: none 0s ease 0s;
box-sizing: content-box;
direction: ltr;
z-index: 2147483632;
opacity: 1;
overflow: hidden
}
.wm-outer-div:after {
content: "";
background-image: url("https://thumbs-prod.si-cdn.com/c3phl1TZgQ92bLQugItmtovLZhs=/fit-in/1600x0/https://public-media.si-cdn.com/filer/54/10/5410da58-2295-4e3a-a847-fecd41cdcdd9/scarlet_tanager.jpg") !important;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform: translateX(-150px) translateY(150px)
}
<div class="wm-outer-div wm-shoutout wm-shoutout-165013 wm-template-bg wm-template-small-corner wm-ltr wm-chrome wm-design-template-207418 wm-position-center" id="wm-shoutout-165013"></div>
How would I achieve this look without images/paths?
I need text with a thick border, and a shadow that won’t show through transparent text.
I have already tried normal text-shadow, but it didn’t work the way I needed.
I tried using an SVG, but it didn’t provide the flexibility I needed, and same for images.
* {
box-sizing: border-box;
font-family: inherit;
}
html {
font-size: 62.25%;
}
body {
font-family: sans-serif;
font-size: 1.6rem;
background: linear-gradient(to right, rgb(0, 128, 111), rgb(199, 189, 57));
}
h1 {
background: transparent;
color: transparent;
font-family: sans-serif;
font-size: 50px;
font-weight: bold;
text-shadow: 3px 3px 0 rgb(54, 54, 54);
-webkit-text-fill-color: transparent;
-webkit-text-stroke-width: 2px;
-webkit-text-stroke-color: rgb(0, 0, 0);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
text-align: center;
}
<h1>Hello World</h1>
I want to make a text effect with shadow behind letter, like this:
This is my code:
span {
font-family: Calibri;
font-size: 110pt;
text-shadow: -14pt 18pt 4pt rgba(0,0,0,0.5);
}
<span>Text</span>
but this it simple text shadow, I need to transform it. How can I create this effect using CSS and only one HTML tag like <span>?
Thanks for help.
You can do this using a psuedo element instead of a shadow:
[data-shadowtext] {
position: relative;
font-size: 150px;
}
[data-shadowtext]::before,
[data-shadowtext]::after {
content: attr(data-shadowtext);
}
[data-shadowtext]::before {
position: absolute;
z-index: 0;
top: -60px;
left: 3px;
font-size: 1.2em;
/* the text is 20% larger than the parent */
color: transparent;
/* hide the text */
text-shadow: 0 0 25px black;
/* create a shadow only from the blur */
transform-origin: bottom;
transform: rotateX(75deg) skew(15deg);
letter-spacing: -15px;
}
[data-shadowtext]::after {
position: relative;
z-index: 1;
}
body {
margin: 20px 0 0 80px;
}
<div data-shadowtext="Text"></div>
This is not possible with writing core CSS.
You can only use as generated by Text Shadow.
You can use translate method and its matrix property.:
My JS Fiddle Example : https://jsfiddle.net/gsmjjm7b/
HTML:
<div id="relative">
<h1 id="title">TEXT</h1>
<h1 class="shadow">TEXT</h1>
</div>
CSS :
#relative{position:relative;margin:100px}
h1 {font-size:80px;margin:0}
h1.shadow {
position:absolute;
top:0;
left:-25px;
-ms-transform: matrix(1, 0, 0.7, 1, 0, 0); /* IE 9 */
-webkit-transform: matrix(1, 0, 0.7, 1, 0, 0); /* Safari */
transform: matrix(1, 0, 0.7, 1, 0, 0);
text-shadow:2px 2px 4px rgba(0,0,0,0.6);
opacity:1;color:rgba(0,0,0,0)
}
Another way of displaying,
span {
color: black;
position: relative;
font-family: Calibri;
font-size: 110pt;
}
span:before {
bottom: 2px;
color: rgba(0, 0, 0, 0.1);
content: attr(title);
left: 9px;
position: absolute;
text-shadow: 0 0 20px grey;
transform-origin: bottom;
transform: skew(30deg) scale(0.8, 1);
z-index: -1;
}
<span title="Text">Text</span>
It's not exactly the same but you can get the idea !!
span {
display: inline-block;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
position: relative;
padding: 20px;
border: none;
font: normal 100px/1 "Oswald", Helvetica, sans-serif;
color: #e74c3c;
text-align: center;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
letter-spacing: 15px;
text-shadow: 1px 1px 1px rgba(0,0,0,0.2) ;
}
span:after {
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
z-index: -1;
position: absolute;
content: "Text";
top: 34px;
left: 28px;
padding: 20px;
border: none;
font: normal 77px/1 "Oswald", Helvetica, sans-serif;
color: rgba(255,255,255,0.2);
text-align: center;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
letter-spacing: 23px;
text-shadow: 1px 1px 1px rgba(0,0,0,0.2) ;
-webkit-transform: rotateX(50deg) skewX(-30deg);
transform: rotateX(50deg) skewX(-30deg);
}
<span title="Text">Text</span>