I wanted to have a vertical line below a rotated text, but the behaviour I am attaining with my code is that the line starts at the center of the text.
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
}
.email::after {
content: "";
width: 1px;
height: 5rem;
background: red;
}
<div class="email">
test#mail.com
</div>
Following is an image of my actual output:
How can I have the line below the rotated text?
You can add transform: rotate(90deg); also to the pseudo-element (and maybe also add some margin to create a bit of a distance to the text.
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
}
.email::after {
content: "";
width: 1px;
height: 5rem;
background: red;
transform: rotate(90deg);
margin-top: 0.5rem;
}
<div class="email">
test#mail.com
</div>
(Note: Use full page mode to view the example, otherwise you won't see the text.)
writing-mode: vertical-rl; you can achieve this. for more information visit this.
:root {
--height-for-line: 60px;
}
.email {
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
}
.email a {
color: white;
text-transform: none;
writing-mode: vertical-rl;
background-color: blue;
padding: 12px;
position: relative;
}
.email a::after {
content: "";
position: absolute;
height: calc(var(--height-for-line) - 15px);
width: 2px;
bottom: 5px;
right: 50%;
transform: translateX(-50%);
background-color: red;
}
<div class="email">
test#mail.com
</div>
Border as pseudo element. (the one you tried in question post)
(I would suggest using the text-decoration or border-bottom solution under this code snippet.)
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
}
.email::after {
content: "";
width: 1px;
height: 6.2rem;
background: red;
transform: translateY(-60%);
margin-right: 15px;
}
<div class="email">
test#mail.com
</div>
Solution with text-decoration: underline;
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
text-decoration: underline;
-webkit-text-decoration-color: red; /* Safari */
text-decoration-color: red;
}
<div class="email">
<u>test#mail.com</u>
</div>
Solution using border-bottom
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
border-bottom: 1px solid red;
}
<div class="email">
<u>test#mail.com</u>
</div>
I wanted to have a vertical line below a rotated text
I've shifted things around for you a little:
I've applied the ::after pseudo-element to the <a> element
I've swapped dimensions of the ::after pseudo-element so that it represents a horizontal (rather than a vertical) line
I've applied transform: rotate(90deg); to .email (rather than .email a)
Working Example
.email {
position: fixed;
top: 0;
left: 3em;
transform: rotate(90deg);
transform-origin: 0 0;
}
.email a {
font-weight: 300;
font-size: 1rem;
}
.email a::after {
content: '';
display: inline-block;
width: 5rem;
height: 1px;
background: red;
}
<div class="email">
test#mail.com
</div>
Instead of a pseudo, you could use box-shadow
(inset to work better with transform)
.email {
display: flex;
flex-direction: column;
align-items: center;
position: fixed;
left: 3rem;
bottom: 10rem;
}
.email a {
transform: rotate(90deg);
font-weight: 300;
font-size: 1rem;
box-shadow: inset 0 -1px 0 0 red;
padding-bottom: 1rem;
}
<div class="email">
test#mail.com
</div>
Related
So I've got a problem where I've got two tabs (https://codepen.io/databell/pen/LYjxvyx) where the first tab opens up content and the second opens up a modal.
Now to be clear, those functions work. That's not the issue. So for those purposes, I deleted those out of my example. Focusing on CSS here.
My problem is I want plus + symbols to appear to the right side of each tab (really a div) and instead one tab has the symbol to the far right of the container, even though the tab is set to width 100%. So I'm stumped as to what the problem is.
This is meant to go into a Shopify store using the Dawn theme, so I'm using their elements here to create this interface.
Here's the code.
<div id="info-additions" class="product__accordion accordion info-additions-content" >
<details>
<summary>
<div class="summary__title info-additions-tab g-flex">
<h2 class="h4 accordion__title t-body benefits">
Tab One
<span></span>
</h2>
</div>
<div class="summary__title info-additions-tab g-flex">
<modal-opener class="product-popup-modal__opener no-js-hidden" data-modal="#PopupModal-ingr">
<button id="ProductPopup-ingr" class="summary__title t-body ingredients" type="button" aria-haspopup="dialog" data-additions-tab="ingredients">
<h2 class="h4 accordion__title">
Tab Two
<span></span>
</h2>
</button>
</modal-opener>
</div>
</summary>
<div class="accordion__content rte">
<p>Content</p>
</div>
</details>
</div>
CSS:
body {
font-size: 1.6rem;
}
*, ::before, ::after {
box-sizing: inherit;
}
.h0, .h1, .h2, .h3, .h4, .h5, h1, h2, h3, h4, h5 {
letter-spacing: .06rem;
line-height: 1.3;
}
.h4, h4 {
font-size: 1.6rem;
}
.grid {
list-style: none;
}
.g-flex {
display: flex;
display: -webkit-flex;
flex-wrap: wrap;
-webkit-flex-wrap: wrap;
}
.accordion summary {
cursor: pointer;
display: flex;
position: relative;
list-style: none;
line-height: 1;
padding: 1.5rem 0;
}
.accordion__title {
display: inline-block;
max-width: calc(100% - 6rem);
min-height: 1.6rem;
margin: 0;
word-break: break-word;
}
details > * {
box-sizing: border-box;
}
.accordion__title {
word-break: break-word;
}
.accordion .summary__title {
display: flex;
flex: 1;
}
#info-additions {
clear: both;
height: auto;
margin: 15px 0 0;
border-top: 2px solid;
border-bottom: 2px solid;
width: 100%;
}
.info-additions-content {
position: relative;
height: 0;
transition: .6s var(--a-cubic-1);
}
.info-additions-tab {
justify-content: space-between;
}
.info-additions-tab span {
display: block;
position: absolute;
width: 18px;
height: 18px;
top: 13px;
right: 2rem;
}
.info-additions-tab button {
position: relative;
padding: 16px 0!important;
line-height: 1;
font-weight: 500;
text-align: left;
}
.info-additions-tab button.benefits {
width: 50%;
}
.info-additions-tab .product-popup-modal__opener {
width: 100% !important;
}
.info-additions-tab button.ingredients {
width: 100%;
}
.info-additions-tab span {
display: block;
position: absolute;
width: 18px;
height: 18px;
top: 13px;
right: 2rem;
}
.info-additions-tab span:before,
.info-additions-tab span:after {
content: '';
display: block;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%) rotate(90deg);
transform: translate(-50%, -50%) rotate(90deg);
width: 2px;
height: 18px;
background-color: black;
transition: 0.3s;
}
.info-additions-tab button:not(.active) span:after {
-webkit-transform: translate(-50%, -50%) rotate(180deg);
transform: translate(-50%, -50%) rotate(180deg);
}
.info-additions-content {
position: relative;
height: 0;
transition: 0.6s var(--a-cubic-1);
}
.info-additions-content [data-additions-content] {
position: absolute;
width: 100%;
top: 0;
left: 0;
padding: 5px 0 20px;
opacity: 0;
pointer-events: none;
transition: 0.3s 0s;
}
.info-additions-content [data-additions-content].active {
opacity: 1;
pointer-events: auto;
transition-delay: 0.4s;
}
#info-additions button {
padding: 0;
background: transparent;
color: inherit;
cursor: pointer;
border: 0;
border-radius: 0;
outline: none;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
transition: 0.2s;
}
if you want an absolute element like + to stay in the parent element you have to set the position of the parent to "relative".
you have two problems. summary__title doesn't have a position so + doesn't stay in it .
for the second tab, your modal button has a relative position that makes the + stay inside of it instead of the summary__title.
.accordion .summary__title {
...
position: relative; // add position
}
#info-additions button {
...
position: unset; // unset the position of the button
}
I use css to show colors around div when hover but I want to make it more than one color live demo I want it to be multiple colors instead of one
.container{
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.container a{
position: relative;
width: 200px;
height: 60px;
display: inline-block;
background: #fff;
margin: 20px;
}
.container a::before,
.container a::after
{
content: '';
position: absolute;
inset: 0;
background: rgb(26, 214, 58);
transition: 0.5s;
}
.container a:hover:before
{
inset: -3px;
}
<style>
#import url('https://fonts.googleapis.com/css2?family=Zilla+Slab:ital,wght#1,300&display=swap');
body {
background-color: #0e1538;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
a {
text-decoration: none;
}
.btn-wrapper {
width: 200px;
height: 60px;
}
.btn {
font-family: 'Zilla Slab', serif;
font-size: 2em;
color: #ffffff;
background-color: #0e1538;
width: 190px;
height: 50px;
}
.center-flex {
display: flex;
justify-content: center;
align-items: center;
}
.btn-wrapper:hover {
background-image: linear-gradient(90deg, #00C0FF 0%, #FFCF00 49%, #FC4F4F 100%);
}
</style>
<body>
<div class="btn-wrapper center-flex">
Hover Me</div>
</div>
</body>
Instead of having a background set as a single RGB color you can set it as a background-image with multi colors introduced through a gradient.
This snippet uses a linear-gradient (which gives a sort of image type) with just 3 colors but you can have more and you can adjust how much of each you get and whether the changes go from top to bottom or left to right - see MDN documentation for the various options.
The result here is:
#import url('https://fonts.googleapis.com/css2?family=Zilla+Slab:ital,wght#1,300&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Zilla Slab', serif;
}
body {
display: flex;
justify-content: center;
min-height: 100vh;
background: #0e1538;
}
.container {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.container a {
position: relative;
width: 200px;
height: 60px;
display: inline-block;
background: #fff;
margin: 20px;
}
.container a::before,
.container a::after {
content: '';
position: absolute;
inset: 0;
background: rgb(26, 214, 58);
background-image: linear-gradient(red, green, blue);
/* ADDED */
transition: 0.5s;
}
.container a:hover:before {
inset: -3px;
}
.container a span {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: inline-block;
background: #0e1538;
z-index: 10;
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
text-transform: uppercase;
letter-spacing: 2px;
color: #fff;
}
<div class="container">
<a href="#">
<span>Hover Me</span>
</a>
</div>
I have some trouble with bootstrap carousel. I cannot remove blue under lines.
Can someone help me? It's not text decoration (text-decoration: none; doesn't work).
.carousel {
width: 100%;
position: absolute;
z-index: 3;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
text-decoration: none !important
}
.carousel-inner,.carousel,.carousel-indicators {
text-decoration: none;
box-shadow: none;
}
.carousel-indicators {
bottom: -150px;
text-decoration: none !important
}
.section1-text {
line-height: 1.55;
display: flex;
justify-content: space-between;
align-items: center;
color: white;
width: 100%;
text-decoration: none !important
}
.section1-text p {
color: white;
font-size: 25px ;
margin-bottom: 30px;
width: 80%;
z-index: 2;
}
I'm trying to make my page automatically go to scroll when the window is at a small height instead of trying to adjust to the height by getting squishy. I've tried different ways of using overflow, but I can't seem to find a way to make it scroll the page as a whole no matter where I put it. The codepen is here: CODEPEN Thank you in advance!
#import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Oleo+Script&display=swap');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
overflow-y: scroll;
}
a {
color: #8524C6;
text-decoration: none;
}
section {
width: 100%;
height: 100vh;
color: #fff;
background: linear-gradient(-45deg, #F5D0E4, #F6D5F2, #EAD5F6, #D9D5F6, #D5E1F6, #D5ECF6);
background-size: 400% 400%;
position: relative;
animation: change 10s ease-in-out infinite;
overflow: hidden;
align-items: center;
justify-content: center;
}
h1 {
display: flex;
align-items: center;
justify-content: center;
color: #000;
font-size: 1.3em;
font-family: 'Oleo Script', cursive, 'Helvetica', sans-serif;
letter-spacing: .07rem;
transform: translateY(15vh);
}
h1 span {
display: flex;
text-align: center;
vertical-align: middle;
}
h1:hover span {
animation: animate .5s infinite;
}
#keyframes animate {
0% {
transform: translateY(0)
}
50% {
transform: translateY(-30px)
}
100% {
transform: translateY(0)
}
}
h1 span:nth-child(1) {
animation-delay: 0s;
}
h1 span:nth-child(2) {
animation-delay: .1s;
}
h1 span:nth-child(3) {
animation-delay: .2s;
}
h2 {
display: flex;
align-items: center;
justify-content: center;
text-align: center;
vertical-align: top;
color: #000;
font-size: .4rem;
font-family: 'Press Start 2P', cursive, serif;
text-transform: uppercase;
transform: translateY(15.5vh)
}
.dancing-hamsters {
display: flex;
position: relative;
margin: auto;
align-content: center;
width: 100%;
height: 1.3rem;
width: 5.1rem;
transform: translateY(18vh);
z-index: 1;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #d3d3d3;
align-content: center;
position: absolute;
top: 50%;
bottom: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
padding: 5px;
padding-right: 3%;
box-shadow: inset 0 0 10px #000;
}
.top-note {
/* display: flex; */
display: none;
font-family: 'Helvetica', sans-serif;
font-size: .65rem;
text-align: center;
justify-content: center;
align-items: center;
color: #000;
transform: translate(4%, -5%);
}
.box {
display: flex;
flex-direction: column;
background-color: #d3d3d3;
text-align: center;
justify-content: center;
align-items: center;
text-align: center;
transform: translateX(50%);
width: 1rem;
height: 1rem;
font-family: 'Press Start 2P', cursive, serif;
font-size: .5rem;
margin: 2rem;
}
img {
display: flex;
width: 85%;
height: 75%;
}
.container img {
cursor: url('https://i.postimg.cc/6338xsj2/oie-nr-M8-Ct-Mr-SPb-H.png'), auto;
}
.box-text {
margin-top: 10%;
cursor: url('https://i.postimg.cc/6338xsj2/oie-nr-M8-Ct-Mr-SPb-H.png'), auto;
}
.nav {
margin: auto;
text-align: center;
transform: translateY(70vh);
font-size: .5rem;
text-transform: uppercase;
line-height: .8rem;
}
.nav a {
color: #000;
font-family: 'Press Start 2P', cursive, serif;
text-shadow: 2px 2px 7px #8524C6;
}
footer {
margin: auto;
width: 100%;
height: 1rem;
font-family: Helvetica, sans-serif;
font-size: .75rem;
background-color: transparent;
border-top: 1px solid #fff;
text-align: center;
padding-top: 1rem;
bottom: 0;
transform: translateY(80vh);
}
#keyframes change {
0% {
background-position: 0 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0 50%;
}
}
/* Media Queries */
#media screen and (min-width: 740px) {
h1 {
font-size: 3em;
transform: translateY(8vh);
word-spacing: 2em;
}
h2 {
font-size: 1rem;
transform: translateY(8vh);
}
.dancing-hamsters {
height: 2rem;
width: 9rem;
transform: translateY(10.5vh);
}
.container {
display: flex;
flex-direction: row;
}
.top-note {
display: none;
}
.box {
width: 15rem;
height: 15rem;
transform: translateX(15%);
font-size: .75rem;
}
.img {
width: 100%;
height: 100%;
}
.nav li {
margin: .5em;
display: inline;
text-align: center;
align-items: center;
justify-content: center;
font-size: .85rem;
}
.nav {
transform: translateY(64vh);
}
footer {
transform: translateY(75vh);
}
}
A quick solution will be to add min-height to the main section element:
section {
width: 100%;
height: 100vh;
min-height: 500px; // I just add 500px for demo
color: #fff;
background: linear-gradient(-45deg, #F5D0E4, #F6D5F2, #EAD5F6, #D9D5F6, #D5E1F6, #D5ECF6);
background-size: 400% 400%;
position: relative;
animation: change 10s ease-in-out infinite;
overflow: hidden;
align-items: center;
justify-content: center;
}
You have specified the height of the section, but with min-height you will guarantee that regardless of the screen height, your content will not get smaller than what you have set.
I want to create a button which changes on hover. Here you can check it: https://drive.google.com/file/d/1fIcil2Xyky8DC2NRcfZBKXCMHk9gpat2/view?usp=sharing.
Here you can see my attempt: https://codepen.io/koravski/pen/BEvKRP
body {
display: flex;
justify-content: center;
align-items: center;
background: #333;
font-family: 'Lato', sans-serif;
}
.txt {
position: absolute;
color: #fff;
}
.box {
width: 200px;
height: 50px;
background-color: red;
transition: all 1s;
}
.box:hover {
width: 50px;
height: 5px;
margin-top: 40px;
}
<div class="txt">Call to action</div>
<div class="box"></div>
The problem is that when I hover it, it starts looping. It should be on the red rectangle so it won't loop.
If you have any suggestions it will be nice.
Thanks.
It's not quite clear what effect you are after but you're changing the size so when it shrinks you're not hovering on it any more.
I'd suggest a transform instead (two actually, one for the size and another for the position).
html,
body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
background: #333;
font-family: 'Lato', sans-serif;
}
.txt {
position: absolute;
color: #fff;
}
.box {
width: 200px;
height: 50px;
background-color: red;
transition: all 1s;
}
.box:hover {
transform: translateY(40px) scale(.1);
}
<div class="txt">Call to action</div>
<div class="box"></div>
There are other issues but it depends on what this actually supposed to do.
In fact, you can do this with a single div.
html,
body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
background: #333;
font-family: 'Lato', sans-serif;
}
.txt {
position: relative;
color: #fff;
width: 200px;
height: 50px;
line-height: 50px;
text-align: center;
transition: all 1s;
}
.txt:before {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-color: red;
z-index: -1;
transition: all 1s;
}
.txt:hover:before {
transform: translateY(40px) scale(.1);
}
<div class="txt">Call to action</div>
This is happening because whenever the button shrinks, your mouse is no longer hovering over it, so the animation comes back up and hits the box (causing it to trigger once again. I'd suggest using a pseudo element -
.box::before {
background-color: red;
content: '';
position: absolute;
height: 100%;
width: 100%;
z-index: 0;
transition: all 1s;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
.box:hover.box::before {
width: 50px;
height: 5px;
}
https://codepen.io/aedenmurray/pen/XQodQj
Here is an idea using background animation where you will need only one element:
body {
display: flex;
justify-content: center;
align-items: center;
font-family: 'Lato', sans-serif;
}
.txt {
color: #fff;
padding:20px 50px;
background-image:linear-gradient(red,red);
background-size:100% 100%;
background-position:bottom center;
background-repeat:no-repeat;
transition:1s;
}
.txt:hover {
background-size:20% 5%;
color:#000;
}
<div class="txt">Call to action</div>
I would wrap your .box and .txt in a container, and then when that container is hovered, do the transition. That way, your hover area isn't being resized - instead the contents are.
html, body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
background: #333;
font-family: 'Lato', sans-serif;
}
.txt {
position:absolute;
color: #fff;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 100px;
}
.box {
width: 200px;
height: 50px;
background-color: red;
transition: all 1s;
}
.container {
position: relative;
}
.container:hover > .box {
width: 50px;
height: 5px;
margin-top: 40px;
}
<div class="container">
<div class="txt"> Call to action</div>
<div class="box"></div>
</div>
View Updated CodePen
The trick is to apply the :hover to a surrounding element.
So you keep hovering over the element and just the included block will change.
FYI:
translate3d is used for better performance than normal translateX.
You could improve the code further. The red element could be a ::before element, and you might want to attach :focus, too for better accessibility. And maybe use a button element.
html, body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
background: #333;
font-family: 'Lato', sans-serif;
}
.btn {
position: relative;
}
.btn-txt {
color: #fff;
text-align: center;
vertical-align: middle;
position: relative;
padding: 20px 30px;
}
.btn-box {
background-color: red;
transition: all 1s;
position: absolute;
bottom: 0;
left: 0;
height: 100%;
width: 100%;
}
.btn:hover .btn-box {
width: 50px;
height: 5px;
transform: translate3d(50px, 0, 0);
top: auto;
}
<div class="btn">
<div class="btn-box"></div>
<div class="btn-txt">Call to action</div>
</div>