Using media queries, following standards with SASS and BEM? - sass

I am following the BEM practice and want to add specific break points, it appears 2 formats work for me. Does anyone know the advantage of either ?
Here is the first, I embed the media directly into the element (BEM)
.my-component {
&__section-field {
display: flex;
flex-wrap: wrap;
}
&__section-sep {
width: 100%;
#media(min-width: 900px) {
width: 50%;
}
}
}
Here is the second, where I embed the media query outside of the section and redefine the section again.
.my-component {
&__section-field {
display: flex;
flex-wrap: wrap;
}
&__section-sep {
width: 100%;
}
#media(min-width: 900px) {
&__section-sep {
width: 50%;
}
}
}
As you can see the, I am basically changing the width of an item between either 50% or 100% depending if it's mobile only resolution. I am using flexbox with flex-wrap and it wraps depending on there is space left on the line.
They both seem to work the same as far as I can say. Would anyone confirm if there is a difference and which one would be more scalable and maintainable?
Maybe there is something that I haven't thought of, I did think about storing my media queries in a separate file but I was trying to keep everything together and follow the bem methodology.

I prefer the 2nd variant for the following reason: when you have many media queries, indeed, the 1st variant requires less copy/paste.
But though, the code becomes much less readable if you have many elements or modifiers in the block, i.e. selectors. It's common to face a situation when it's needed to change style for several elements/modifiers at exact screen. And when that case appears - as for me - it's easier to navigate between media queries, find the needed media and change code there - so you work at one place in the file, whereas in the 1st variant you would need to jump between selectors. In my opinion when it comes to work with media queries - it's faster to navigate between them, then to navigate between selectors.
imagine the following code with media query inside every selector :
.section_name_educational {
display: flex;
flex-direction: row;
padding: 0px;
.fp-tableCell {
display: flex;
flex-direction: row;
}
.section {
&__inner {
display: flex;
flex-direction: row-reverse;
height: 100vh;
height: calc(100vh - 80px);
box-sizing: border-box;
width: 50%;
padding-left: 40px;
margin-top: auto;
padding-bottom: 40px;
}
&__header {
position: relative;
width: 100%;
top: 62px;
left: 40px;
}
&__text-holder {
width: 100%;
}
&__title {
font-size: 48px;
}
&__subtitle {
width: 150%;
margin: 20px 0px;
}
&__description {
color: #669900;
font-size: 18px;
}
&__primary {
height: 100%;
display: flex;
box-sizing: border-box;
flex-direction: column;
justify-content: space-between;
width: 100%;
}
&__additional {
display: none;
}
&__kettles {
display: flex;
}
&__kettle {
height: auto;
margin-right: 20px;
&_order {
&_1 {
width: 183px;
min-width: 183px;
max-width: 183px;
}
&_2 {
width: 108px;
min-width: 108px;
max-width: 108px;
}
&_3 {
width: 127px;
min-width: 127px;
max-width: 127px;
}
}
}
&__background-holder {
overflow: hidden;
max-height: 100vh;
}
&__background {
position: relative;
width: auto;
height: 100vh;
}
}
}
#media all and (max-height: 600px) {
.section_name_educational {
.section {
&__kettle {
&_order {
&_2 {
width: 68px;
max-width: 68px;
min-width: 68px;
height: 120px;
margin-left: 30px;
}
&_3 {
width: 78px;
max-width: 78px;
min-width: 78px;
height: 120px;
}
}
}
}
}
}
#media all and (max-height: 760px) {
.section_name_educational {
.section {
&__header {
top: 40px;
}
&__subtitle {
width: 100% !important;
}
&__additional {
display: none !important;
}
}
}
}
#media (--large) {
.section_name_educational {
.section {
&__subtitle {
width: 120%;
}
}
}
}
#media (--xlarge) {
.section_name_educational {
padding-top: 120px;
.section {
&__inner {
height: calc(100vh - 60px);
margin-top: 0;
}
&__header {
transition-delay: 1s;
opacity: 0;
right: -100px;
bottom: -40px;
transform: translateY(20px);
}
&__subtitle {
width: 120%;
}
&__primary {
width: calc(100% - 160px);
}
&__additional {
display: flex;
flex-direction: column;
justify-content: space-between;
}
&__bubbles {
display: block;
position: relative;
top: 40px;
width: 160px;
min-width: 160px;
max-width: 160px;
height: auto;
transform: translateY(20px);
opacity: 0;
transition-delay: 1s;
}
&__kettle {
opacity: 0;
transform: translateY(20px);
transition-delay: 1s;
}
}
&.active {
.section {
&__header {
transition: opacity 1s ease-out 0.8s,
transform 0.8s ease-out 0.8s;
opacity: 1;
transform: translateY(0px);
}
&__kettle {
opacity: 1;
transform: translateY(0px);
transition: opacity 0.6s ease-out,
transform 0.6s ease-out;
&_order {
&_1 {
transition-delay: 1.6s;
display: block;
}
&_2 {
transition-delay: 1.9s;
}
&_3 {
transition-delay: 2.1s;
}
}
}
&__bubbles {
transition: opacity 0.8s ease-out 2.5s,
transform 0.8s ease-out 2.3s;
transform: translateY(0px);
opacity: 1;
}
}
}
}
}
#media all and (min-width: 1400px) {
.section_name_educational {
.section {
&__header {
left: 60px;
}
&__subtitle {
width: 110%;
}
}
}
}
#media (--xxlarge) {
.section_name_educational {
.section {
&__primary {
width: calc(100% - 148px);
}
&__subtitle {
width: 80%;
margin: 40px 0px;
}
&__description-inner {
width: 60%;
}
&__bubbles {
width: 148px;
min-width: 148px;
max-width: 148px;
top: 40px;
}
}
}
}
#media (--monster) {
.section_name_educational {
.section {
&__primary {
width: calc(100% - 227px);
}
&__header {
left: 200px;
top: 150px;
}
&__title {
font-size: 58px;
}
&__subtitle {
font-size: 24px;
width: 80%;
}
&__description {
font-size: 24px;
}
&__bubbles {
width: 227px;
min-width: 227px;
max-width: 227px;
left: 0px;
}
}
}
}
As for me - it would be difficult to read it if I had done it with the 1st variant.

Related

Why is safari does not react to my media queries?

I have a bunch of queries in my page. Chrome responds to all of them and Safari just won't render almost all of them and I'm wondering why. I can't even see them in Safari DevTools.
I thought that maybe there's something going on with root font-size or maybe browser scale so I set font-size to 100% and added specific value for breakpoints but I didn't worked out.
Here are queries from my .scss
#mixin respond ($breakpoint){
#if $breakpoint == ipadLand {
#media screen and (width: 1024px) and (height: 768px) {
body {
font-size: 75%;
}
.button_text{
font-size: 0.9rem;
}
.contacts_section_row{
top: 4.5rem;
}
.contact_header{
margin-top: 2rem;
}
.skills_container_row3{
margin-bottom: 0.5rem;
}
.contacts_section_col{
width: $picture_width;
}
.contacts_section_row{
width: calc(#{$picture_width} * 3);
}
.vk_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.tg_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.hh_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
}}
#if $breakpoint == ipadpro12_port {
#media screen and (width: 1024px) and (height: 1366px){
$contact_section_height: 20rem;
body {
font-size: 120%;
}
.name_text{
font-size: 2.5rem;
padding-top: 1rem;
padding-left: 5vw;
}
.role_text{
font-size: 1.7rem;
padding-top: 0.6rem;
padding-left: 1rem;
}
.main_div{
height: 985.3px;
//height: calc((100vh + (#{$head_div_height} * 2)));
}
.photo_box{
height: 40%;
width: 100vw;
}
.photo{
margin: 0 auto;
margin-top: 50px;
width: auto;
height: 85%;
}
.vk_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.tg_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.hh_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.contacts_section_col{
width: calc((#{$picture_width} * 3) / 3);
}
.contacts_section_row{
margin-top: 1rem;
width: calc(#{$picture_width} * 3)
}
.contact_header{
text-align: center;
height: auto;
width: inherit;
margin: 0 auto;
margin-top: 1rem;
transform: translate(0);
}
.skills_container_row{
font-size: 2.5rem;
margin: 0px;
}
.skillsandprojects-col-one{
font-size: 2rem;
height: auto;
text-align: left;
}
.skillsandprojects_container{
position: absolute;
top: 40%;
right: 0;
left: 0;
width: 100%;
height: 35%;
margin: 0;
background-color: white;
border: none;
}
.contacts_section{
position: relative;
bottom: calc(100vh - (#{$main_div_height} + #{$head_div_height} + #{$contact_section_height}));
width: 100vw;
height: $contact_section_height;
//background-color: blue; }
//background-color: $header_text_color;
}
.button_text{
font-size: 1.6rem;
}
.skillsandprojects_container2{
position: absolute;
top: 75%;
right: 0;
left: 0;
height: 35%;
width: 100%;
}
.skills_container_row3{
width: 100%;
height: 39px;
border: none;
margin-bottom: 1rem;
}
}}
#if $breakpoint == ipad_port {
#media screen and (width: 768px) and (height: 1024px){
body {
font-size: 70%;
}
.name_text{
font-size: 1.5rem;
padding-top: 2rem;
padding-left: 5vw;
}
.role_text{
font-size: 0.7rem;
padding-top: 0.6rem;
padding-left: 0.5rem;
}
.main_div{
height: calc((100vh - (#{$head_div_height} + #{$contact_section_height})));
//height: 985.3px;
//height: calc((100vh + (#{$head_div_height} * 2)));
}
.photo_box{
height: 40%;
width: 100vw;
}
.photo{
margin: 0 auto;
margin-top: 25px;
width: auto;
height: 75%;
}
.vk_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.tg_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.hh_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.contacts_section_col{
width: calc((#{$picture_width} * 3) / 3);
}
.contacts_section_row{
width: calc(#{$picture_width} * 3)
}
.contact_header{
text-align: center;
height: auto;
width: inherit;
margin: 0 auto;
transform: translate(0);
}
.skills_container_row{
font-size: 1.5rem;
margin: 0px;
}
.skillsandprojects-col-one{
font-size: 1.8rem;
height: auto;
text-align: left;
}
.skillsandprojects_container{
position: absolute;
top: 40%;
right: 0;
left: 0;
width: 100%;
height: 35%;
margin: 0;
background-color: white;
border: none;
}
.button_text{
font-size: 0.79rem;
}
.skillsandprojects_container2{
position: absolute;
top: 75%;
right: 0;
left: 0;
height: 35%;
width: 100%;
}
.skills_container_row3{
width: 100%;
height: 39px;
border: none;
}
.contacts_section{
margin-top: 6rem;
}
}}
#if $breakpoint == phone {
#media screen and (max-width: 573px) and (max-height: 926px){
.name_text{
font-size: 1.5rem;
padding-top: 2rem;
padding-left: 5vw;
}
.role_text{
font-size: 0.7rem;
padding-top: 0.6rem;
padding-left: 0.5rem;
}
.main_div{
height: 985.3px;
//height: calc((100vh + (#{$head_div_height} * 2)));
}
.contact_header{
text-align: center;
height: auto;
width: inherit;
//height: $contacts_section_header_height;
transform: translate(0);
//margin: 0 auto;
margin-bottom: 0.2rem; }
.photo_box{
height: 40%;
width: 100vw;
}
.vk_picture{
width: 3.437rem;
height: 3.437rem;
}
.tg_picture{
width: 3.437rem;
height: 3.437rem;
}
.hh_picture{
width: 3.437rem;
height: 3.437rem;
}
.contacts_section_col{
width: calc((#{3.437rem} * 3) / 3);
}
.contacts_section_row{
width: calc(#{3.437rem} * 3)
}
.skills_container_row{
font-size: 1.5rem;
margin: 0px;
}
.skillsandprojects-col-one{
font-size: 1.8rem;
height: auto;
text-align: left;
}
.skillsandprojects_container{
position: absolute;
top: 40%;
right: 0;
left: 0;
width: 100%;
height: 35%;
margin: 0;
background-color: white;
border: none;
}
.button_text{
font-size: 0.9rem;
}
.skillsandprojects_container2{
position: absolute;
top: 75%;
right: 0;
left: 0;
height: 35%;
width: 100%;
}
.skills_container_row3{
width: 100%;
height: 39px;
//height: calc((100% - #{$skills_head-row})/3);
border: none;
}
}
}
#if $breakpoint == mac13 {
#media screen and (width: 1366px) and (height: 768px) {
.button_text{
font-size: 0.8rem;
}
}
}
#if $breakpoint == ipad11pro_port {
#media screen and (height: 1112px) and (width: 834px) {
body {
font-size: 70%;
}
.name_text{
font-size: 2.5rem;
padding-top: 1rem;
padding-left: 5vw;
}
.role_text{
font-size: 1.7rem;
padding-top: 0.6rem;
padding-left: 1rem;
}
.main_div{
height: 985.3px;
//height: calc((100vh + (#{$head_div_height} * 2)));
}
.photo_box{
height: 40%;
width: 100vw;
}
.photo{
margin: 0 auto;
margin-top: 50px;
width: auto;
height: 85%;
}
.vk_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.tg_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.hh_picture{
height: $picture_width;
width: $picture_width;
margin: auto;
}
.contacts_section_col{
width: calc((#{$picture_width} * 3) / 3);
}
.contacts_section_row{
margin-top: 1rem;
width: calc(#{$picture_width} * 3)
}
.button_text{
font-size: 1.3rem;
}
.contact_header{
text-align: center;
height: auto;
width: inherit;
margin: 0 auto;
margin-top: 1rem;
transform: translate(0);
}
.skills_container_row{
font-size: 2.5rem;
margin: 0px;
}
.skillsandprojects-col-one{
font-size: 2rem;
height: auto;
text-align: left;
}
.skillsandprojects_container{
position: absolute;
top: 40%;
right: 0;
left: 0;
width: 100%;
height: 35%;
margin: 0;
background-color: white;
border: none;
}
.contacts_section{
position: relative;
bottom: calc(100vh - (#{$main_div_height} + #{$head_div_height} + #{$contact_section_height}));
width: 100vw;
height: $contact_section_height;
}
.skillsandprojects_container2{
position: absolute;
top: 75%;
right: 0;
left: 0;
height: 35%;
width: 100%;
}
.skills_container_row3{
width: 100%;
height: 39px;
border: none;
margin-bottom: 1rem;
}
}
}
#if $breakpoint == ipad11pro_land {
#media screen and (width: 834px) and (height: 1112px) {
body {
font-size: 1200%;
}
.button_text {font-size: 1rem;}
}
}}
Okay, I figured this.
I haven't made it work the way I planned initially but I guess this will be the best thing to do.
THE ANSWER
So apparently Safari doesn't react to media queries with specific resolutions and you have to use ranges with either min or max height or width. Just rewrite your queries and Safari will handle them right
Before you throw me a comment - yes, I'm aware that it's not the best practice to put specific resolutions and media queries. I was trying to make this way so I can tailor the design for each resolution. I didn't wanted to expand mobile design for tablets and I did wanted them to keep desktop version in landscape while preserve mobile in portrait.
The easier way to achieve that effect was to aim in specific green sizes - it didn't work out and now I realize that I can achieve the same effect with different queries for width and height.
As a bonus I'm willing to share queries sizes I found perfect for screens from iPhone SE to MacBook Pro 16
#mixin respond ($breakpoint){
#if $breakpoint == phone {
#media screen and (max-width: 1024px) and (max-height: 1366px){
//this is for phones and tablets in portrait
// query styles go here }}
#if $breakpoint == tab_land {
#media screen and (min-width: 1024px) and (max-height: 1366px){
//query styles go here}
}}
#if $breakpoint == mac13 {
#media screen and (min-width: 1366px) {
// query styles go here }}
#if $breakpoint == mac15 {
#media screen and (min-width: 1600px) {
// query styles go here
}}
#if $breakpoint == mac16 {
#media screen and (min-width: 2560px) {
// query styles go here
}
}

Why does my <ul> become hidden in desktop mode?

Sorry if this question has already been asked, I don't find anything similar.
So I am following a course and I have created the mobile navbar, which works. Then I write the mediaquery for larger screens and the list, instead of being displayed to the right of the navbar, is hidden.
If I inspect the page I can see that the list and the list items are on the right spot, but they are not visible. I have tried with "visibility: visible" but it doesnt' work.
Where is the mistake?
const collapsibles = document.querySelectorAll(".collapsible");
collapsibles.forEach((item) =>
item.addEventListener("click", function () {
this.classList.toggle("collapsible--expanded");
})
);
/* Typography */
html {
font-size: 62.5%;
}
:root {
--color-primary: #2584ff;
--color-secondary: #00d9ff;
--color-accent: #ff3400;
--color-headings: #1b0760;
--color-body: #918ca4;
--color-border: #ccc;
--border-radius: 30px;
--color-body-darker: #5c5577;
}
body {
font-family: Inter, Arial, Helvetica, sans-serif;
font-size: 2.4rem;
line-height: 1.5;
color: var(--color-body);
}
h1,
h2,
h3 {
color: var(--color-headings);
margin-bottom: 1rem;
}
h1 {
font-size: 7rem;
}
h2 {
font-size: 4rem;
}
h3 {
font-size: 3rem;
}
p {
margin-top: 0;
}
#media screen and (min-width: 1024px) {
body {
font-size: 1.8rem;
}
h1 {
font-size: 8rem;
}
h2 {
font-size: 4rem;
}
h3 {
font-size: 2.4rem;
}
}
/* Links */
a {
text-decoration: none;
}
.link-arrow {
color: var(--color-accent);
text-transform: uppercase;
font-size: 2rem;
font-weight: bold;
}
.link-arrow::after {
content: "-->";
margin-left: 5px;
transition: margin 0.15s;
}
.link-arrow:hover::after {
margin-left: 10px;
}
#media screen and (min-width: 1024px) {
.link-arrow {
font-size: 1.5rem;
}
}
/* Badges */
.badge {
border-radius: 20px;
font-size: 2rem;
font-weight: 600;
padding: 0.5rem 2rem;
white-space: nowrap;
}
.badge--primary {
background: var(--color-primary);
color: white;
}
.badge--secondary {
background: var(--color-secondary);
color: white;
}
.badge--small {
font-size: 1.6rem;
padding: 0.5rem 1.5rem;
}
#media screen and (min-width: 1024px) {
.badge {
font-size: 1.5rem;
}
.badge--small {
font-size: 1.2rem;
}
}
/* Lists */
.list {
list-style: none;
padding-left: 0;
color: var(--color-headings);
}
.list--inline .list__item {
display: inline-block;
margin-right: 2rem;
}
.list--tick {
list-style-image: url(/images/tick.svg);
padding-left: 3rem;
}
.list--tick .list__item {
padding-left: 0.5rem;
margin-bottom: 1rem;
}
#media screen and (min-width: 1024px) {
.list--tick .list__item {
padding-left: 0;
}
}
/* Icons */
.icon {
width: 40px;
height: 40px;
}
.icon--small {
width: 30px;
height: 30px;
}
.icon--primary {
fill: var(--color-primary);
}
.icon--white {
fill: white;
}
.icon-container {
background: #f3f9fa;
width: 64px;
height: 64px;
border-radius: 100%;
display: inline-flex;
justify-content: center;
align-items: center;
}
.icon-container--accent {
background: var(--color-accent);
}
/* Buttons */
.btn {
border-radius: 40px;
border: none;
cursor: pointer;
font-size: 1.8rem;
font-weight: 600;
margin-left: 5px;
margin-top: 5px;
padding: 2rem 3rem;
text-transform: uppercase;
white-space: nowrap;
}
.btn--primary {
background-color: var(--color-primary);
color: white;
}
.btn--primary:hover {
background: #8a91f3;
}
.btn--secondary {
background-color: var(--color-secondary);
color: white;
}
.btn--accent {
background-color: var(--color-accent);
color: white;
}
.btn--accent:hover {
background: #e66545;
}
.btn--outline {
background-color: white;
color: black;
border: 2px solid var(--color-headings);
}
.btn--block {
display: inline-block;
width: 100%;
}
.btn--stretched {
padding-left: 6rem;
padding-right: 6rem;
}
/* Input */
.input {
border-radius: 30px;
border: 1px solid #ccc;
color: var(--color-headings);
font-size: 2rem;
outline: 0;
padding: 1.5rem 3.5rem;
}
::placeholder {
color: #cdcbd7;
}
.input-group {
border: 1px solid var(--color-border);
border-radius: var(--border-radius);
display: flex;
}
.input-group .input {
border: 0;
flex-grow: 1;
padding: 1rem 1rem;
}
.input-group .btn {
margin: 4px;
}
#media screen and (min-width: 1024px) {
.input {
font-size: 1.5rem;
}
}
/* Cards */
.card {
border-radius: 7px;
box-shadow: 0 0 20px 10px #f3f3f3;
overflow: hidden;
min-width: 300px;
}
.card__header,
.card__body {
padding: 2rem 3rem;
}
.card--primary .card__header {
background: var(--color-primary);
color: #fff;
}
.card--secondary .card__header {
background: var(--color-secondary);
color: #fff;
}
.card--secondary .badge--secondary {
background: #02cdf1;
}
/* Plans */
.plan__name {
color: #fff;
margin: 0;
font-weight: 500;
font-size: 2.4rem;
}
.plan__price {
font-size: 6rem;
}
.plan__billing-cycle {
font-size: 2.4rem;
font-weight: 300;
opacity: 0.8;
margin-right: 1rem;
}
.plan__description {
font-size: 2rem;
font-weight: 300;
letter-spacing: 1px;
display: block;
}
.plan .list__item {
margin-bottom: 2rem;
}
.plan--popular .card__header {
position: relative;
}
.plan--popular .card__header::before {
content: url(/images/popular.svg);
width: 40px;
display: inline-block;
position: absolute;
top: -6px;
right: 5%;
}
#media screen and (min-width: 1024px) {
.plan__name {
font-size: 1.4rem;
}
.plan__price {
font-size: 5rem;
}
.plan__billing-cycle {
font-size: 1.6rem;
}
.plan__description {
font-size: 1.7rem;
}
}
/* Media */
.media {
display: flex;
max-width: 500px;
}
.media__title {
margin-top: 0;
}
.media__body {
margin: 0 2rem;
}
.media__image {
margin-top: 1rem;
}
/* Quotes */
.quote {
font-size: 3rem;
font-style: italic;
color: var(--color-body-darker);
line-height: 1.3;
}
.quote__text::before {
content: open-quote;
}
.quote__text::after {
content: close-quote;
}
/* footer p {
font-size: 1.6rem;
}
*/
.quote__company {
font-size: 1.6rem;
opacity: 0.4;
color: var(--color-headings);
font-style: normal;
}
/* Grids */
.grid {
display: grid;
}
#media screen and (min-width: 768px) {
.grid--1x2 {
grid-template-columns: 1fr 1fr;
}
}
#media screen and (min-width: 1024px) {
.grid--1x3 {
grid-template-columns: 1fr 1fr 1fr;
}
}
/* testimonials */
.testimonial {
padding: 3rem;
}
.testimonial__image {
position: relative;
}
.testimonial__image > img {
width: 100%;
}
.testimonial__image > .icon-container {
position: absolute;
top: 3rem;
right: -32px;
}
/* Callout */
.callout {
padding: 4rem;
border-radius: 5px;
}
.callout--primary {
background: var(--color-primary);
color: white;
}
.callout__heading {
color: white;
margin-top: 0;
font-size: 3rem;
}
.callout .btn {
justify-self: center;
align-self: center;
}
.callout__content {
text-align: center;
}
#media screen and (min-width: 768px) {
.callout .grid--1x2 {
grid-template-columns: 1fr auto;
}
.callout__content {
text-align: left;
}
.callout .btn {
justify-self: start;
margin: 0 2rem;
}
}
/* COLLAPSIBLES */
.collapsible__header {
display: flex;
justify-content: space-between;
}
.collapsible__heading {
margin-top: 0;
font-size: 3rem;
}
.collapsible__chevron {
transform: rotate(-90deg);
transition: transform 0.3s;
}
.collapsible__content {
max-height: 0;
overflow: hidden;
transition: all 0.3s;
opacity: 0;
}
.collapsible--expanded .collapsible__chevron {
transform: rotate(0);
}
.collapsible--expanded .collapsible__content {
display: block;
max-height: 100vh;
opacity: 1;
}
/* Blocks */
.block {
--padding-vertical: 6rem;
padding: var(--padding-vertical) 2rem;
}
.block__heading {
margin-top: 0;
}
.block--dark {
background: black;
color: #7b858b;
}
.block--dark .block__heading {
color: white;
}
.block--skewed-right {
clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 80%);
padding-bottom: calc(var(--padding-vertical) + 4rem);
}
.block--skewed-left {
clip-path: polygon(0% 0%, 100% 0%, 100% 80%, 0% 100%);
padding-bottom: calc(var(--padding-vertical) + 4rem);
}
.block__header {
text-align: center;
}
/* nav */
.nav {
background: black;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
padding: 0 1rem;
align-items: center;
}
.nav__list {
width: 100%;
margin: 0;
}
.nav__item {
padding: 0.5rem 2rem;
border-bottom: 1px solid #222;
}
.nav__item > a {
color: #d2d0db;
transition: color 0.3s;
}
.nav__item > a:hover {
color: #fff;
}
.nav__toggler {
opacity: 0.5;
transition: box-shadow 0.15s;
cursor: pointer;
}
.nav.collapsible--expanded .nav__toggler {
opacity: 1;
box-shadow: 0 0 0 3px #666;
border-radius: 5px;
}
#media screen and (min-width: 768px) {
.nav__toggler {
display: none;
}
.nav__list {
width: auto;
display: flex;
visibility: ;
}
}
<!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>
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght#400;600;700&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="/css/normalize.css" />
<link rel="stylesheet" href="/css/styles.css" />
</head>
<body>
<nav class="nav collapsible">
<img src="/images/logo.svg" alt="" />
<svg class="icon icon--white nav__toggler">
<use xlink:href="images/sprite.svg#menu"></use>
</svg>
<ul class="list nav__list collapsible__content">
<li class="nav__item">Hosting</li>
<li class="nav__item">VPS</li>
<li class="nav__item">Domain</li>
<li class="nav__item">Pricing</li>
</ul>
</nav>
<script src="/js/main.js"></script>
</body>
</html>
Problem was solved by adding max-height: 100%; opacity:1 to the .nav__list rule in CSS.

How do I make hover for my ".pic" class to get effected?

I want to add :hover this class ".pic".
So it can contain more description on .pic:hover
I use transform SASS, width, and height on .pic:hover that seems not working.
I can't find out the problem.
Please help to find out my question.
Please watch it on my codepen for any details
.pic
width: 250px
height: 250px
//it doesn't get bigger when mouse is hovering over it
.pic:hover
width: 400px
height: 400px
Codepen
Your code isn't formatted correctly. With CSS, make sure to surround everything with brackets {}. Also make sure to add a semicolon after every line in a class so it knows where to break it up. Change your code to the below and it'll work:
// Adding {} and ; fixed this issue
.pic {
width: 250px;
height: 250px;
}
.pic:hover {
width: 400px;
height: 400px;
}
You can do something like this,
.item {
position: relative;
border: 1px solid #333;
margin: 2%;
overflow: hidden;
width: 540px;
}
.item img {
max-width: 100%;
-moz-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
.item:hover img {
-moz-transform: scale(1.5);
-webkit-transform: scale(1.5);
transform: scale(1.5);
}
<div class="item">
<img src="https://image.freepik.com/free-vector/technological-background-with-circular-shapes_1035-4291.jpg" alt="pepsi" width="540" height="548">
<div class="item-overlay top"></div>
</div>
Your code,
#charset "UTF-8";
* {
font-family: 微軟正黑體;
position: relative;
}
html, body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.wrapper {
height: 100%;
background: linear-gradient(#fc68d7, #8a3ab9, #bc2a8d, #cd486b, #e95950, #fbad50, #fccc63);
display: flex;
justify-content: center;
align-items: center;
}
.camera {
width: 200px;
height: 200px;
border: 10px solid #fff;
border-radius: 50px;
position: absolute;
transform: translateY(-50%);
animation: ballUp 0.5s 1s both, ballDown 0.2s 1.5s ease-in both, cameraIn 0.3s 1.7s both;
perspective: 500;
-webkit-perspective: 500;
}
.lens {
width: 100px;
height: 100px;
border-radius: 50%;
border: 15px solid #fff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: lensIn 0.3s 1.85s backwards;
}
.flashlight {
width: 20px;
height: 20px;
background: #fff;
border-radius: 50%;
position: absolute;
right: 20px;
top: 20px;
animation: flashlightIn 0.3s 2.15s backwards;
}
.flashlight:after {
content: "";
width: 200px;
height: 200px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.5);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: flash 0.3s 2.45s both;
}
.pic {
width: 250px;
height: 250px;
border: 5px solid #fff;
border-bottom: 25px solid #fff;
background: #ccc;
display: inline-block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: picIn 1s 2.48s both, picFlip 1s 3.5s both;
overflow: hidden;
transition: 0.3s;
box-sizing: border-box;
}
.pic:hover img {
-moz-transform: scale(1.5);
-webkit-transform: scale(1.5);
transform: scale(1.5);
}
.pic img {
max-width: 100%;
-moz-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
#keyframes ballUp {
0% {
top: 50%;
width: 5px;
height: 5px;
opacity: 0;
}
10% {
opacity: 1;
}
100% {
top: 10%;
width: 5px;
height: 5px;
}
}
#keyframes ballDown {
0% {
top: 10%;
}
100% {
top: 50%;
}
}
#keyframes cameraIn {
0% {
width: 5px;
height: 5px;
}
80% {
width: 250px;
height: 250px;
}
100% {
height: 200px;
width: 200px;
}
}
#keyframes lensIn {
0% {
width: 0;
height: 0;
opacity: 0;
}
10% {
opacity: 1;
}
80% {
width: 120px;
height: 120px;
}
100% {
width: 100px;
height: 100px;
}
}
#keyframes flashlightIn {
0% {
transform: scale(0);
}
80% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
#keyframes flash {
0% {
opacity: 0;
}
25% {
opacity: 1;
}
50% {
opacity: 0;
}
75% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes picIn {
0% {
height: 0;
width: 0;
top: 100%;
transform: translate(-50%, 0);
opacity: 0;
}
100% {
height: 120px;
width: 120px;
top: 100%;
transform: translate(-50%, 0);
opacity: 1;
}
}
#keyframes picFlip {
0% {
transform: translate(-50%, 0) rotateX(0deg);
top: 100%;
width: 120px;
height: 120px;
}
100% {
transform: translate(-50%, -50%) rotateX(360deg);
top: 50%;
width: 250px;
height: 250px;
}
}
#keyframes showImg {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="wrapper">
<div class="camera">
<div class="lens"></div>
<div class="flashlight"></div>
<div class="pic">
<div class="imgbox"><img src="https://image.freepik.com/free-vector/technological-background-with-circular-shapes_1035-4291.jpg" alt=""/></div>
<div class="text">
<h1>Hello</h1>
<h2>This is my memory</h2>
</div>
</div>
</div>
</div>
or zoom out with text inside,
#charset "UTF-8";
* {
font-family: 微軟正黑體;
position: relative;
}
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.wrapper {
height: 100%;
background: linear-gradient(#fc68d7, #8a3ab9, #bc2a8d, #cd486b, #e95950, #fbad50, #fccc63);
display: flex;
justify-content: center;
align-items: center;
z-index: 1;
}
h5 {
position: absolute;
left: 0px;
top: 0px;
bottom: 0;
z-index: -1;
}
.camera {
width: 200px;
height: 200px;
border: 10px solid #fff;
border-radius: 50px;
position: absolute;
transform: translateY(-50%);
animation: ballUp 0.5s 1s both, ballDown 0.2s 1.5s ease-in both, cameraIn 0.3s 1.7s both;
perspective: 500;
-webkit-perspective: 500;
}
.lens {
width: 100px;
height: 100px;
border-radius: 50%;
border: 15px solid #fff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: lensIn 0.3s 1.85s backwards;
}
.flashlight {
width: 20px;
height: 20px;
background: #fff;
border-radius: 50%;
position: absolute;
right: 20px;
top: 20px;
animation: flashlightIn 0.3s 2.15s backwards;
}
.flashlight:after {
content: "";
width: 200px;
height: 200px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.5);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: flash 0.3s 2.45s both;
}
.pic {
width: 250px;
height: 250px;
border: 5px solid #fff;
border-bottom: 25px solid #fff;
background: #ccc;
display: inline-block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
animation: picIn 1s 2.48s both, picFlip 1s 3.5s both;
overflow: hidden;
transition: 0.3s;
box-sizing: border-box;
}
.pic:hover img {
-moz-transform: scale(0.65);
-webkit-transform: scale(0.65);
transform: scale(0.65);
}
.pic img {
max-width: 100%;
-moz-transition: all 0.3s;
-webkit-transition: all 0.3s;
transition: all 0.3s;
}
#keyframes ballUp {
0% {
top: 50%;
width: 5px;
height: 5px;
opacity: 0;
}
10% {
opacity: 1;
}
100% {
top: 10%;
width: 5px;
height: 5px;
}
}
#keyframes ballDown {
0% {
top: 10%;
}
100% {
top: 50%;
}
}
#keyframes cameraIn {
0% {
width: 5px;
height: 5px;
}
80% {
width: 250px;
height: 250px;
}
100% {
height: 200px;
width: 200px;
}
}
#keyframes lensIn {
0% {
width: 0;
height: 0;
opacity: 0;
}
10% {
opacity: 1;
}
80% {
width: 120px;
height: 120px;
}
100% {
width: 100px;
height: 100px;
}
}
#keyframes flashlightIn {
0% {
transform: scale(0);
}
80% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
#keyframes flash {
0% {
opacity: 0;
}
25% {
opacity: 1;
}
50% {
opacity: 0;
}
75% {
opacity: 1;
}
100% {
opacity: 0;
}
}
#keyframes picIn {
0% {
height: 0;
width: 0;
top: 100%;
transform: translate(-50%, 0);
opacity: 0;
}
100% {
height: 120px;
width: 120px;
top: 100%;
transform: translate(-50%, 0);
opacity: 1;
}
}
#keyframes picFlip {
0% {
transform: translate(-50%, 0) rotateX(0deg);
top: 100%;
width: 120px;
height: 120px;
}
100% {
transform: translate(-50%, -50%) rotateX(360deg);
top: 50%;
width: 250px;
height: 250px;
}
}
#keyframes showImg {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="wrapper">
<div class="camera">
<div class="lens"></div>
<div class="flashlight"></div>
<div class="pic">
<div class="imgbox">
<h5>
Tech-Background
</h5>
<img src="https://image.freepik.com/free-vector/technological-background-with-circular-shapes_1035-4291.jpg" alt="" />
</div>
<div class="text">
<h1>Hello</h1>
<h2>This is my memory</h2>
</div>
</div>
</div>
</div>
Your problem is wrong css. You have to use curly braises and semi colons as well.
.pic{
width: 250px;
height: 250px;
}
.pic:hover{
width: 400px;
height: 400px;
}

Image not clickable

I have a cover of a book that I want to be clickable but I can't get the link to be the image.
<div class="imagePage">
<a href="../index.php">
<img src="../images/covers/denmark.jpg" alt="Denmark">
</a>
</div>
.imagePage {
float: left;
border-top: 30px;
padding-right: 30px;
}
Please can anyone help. I wonder if my media queries are interfering:
/* xs */
img {
width: 150px;
height: auto;
}
/* sm */
#media (min-width: 768px) {
img {
width: 200px;
}
}
/* md */
#media (min-width: 992px) {
img {
width: 350px;
}
}
/* lg */
#media (min-width: 1200px) {
img {
width: 500px;
}
}
Edit: I am using bootstrap. Here is my whole CSS:
body {
padding-top: 30px;
font-size: 16px;
font-family: Candara, Calibri, Segoe, "Segoe UI", Optima, Arial, sans-serif !important;
}
#media (max-width: 979px) {
body {
padding-top: 30px;
}
}
/* xs */
img {
width: 150px;
height: auto;
}
/* sm */
#media (min-width: 768px) {
img {
width: 200px;
}
}
/* md */
#media (min-width: 992px) {
img {
width: 350px;
}
}
/* lg */
#media (min-width: 1200px) {
img {
width: 500px;
}
}
/* xs */
p {
font-size: 12px;
}
/* sm */
#media (min-width: 768px) {
p {
font-size: 14px;
}
}
/* md */
#media (min-width: 992px) {
p {
font-size: 16px;
}
}
/* lg */
#media (min-width: 1200px) {
p {
font-size: 18px;
}
}
/* xs */
h1 {
font-size: 28px !important;
}
/* sm */
#media (min-width: 768px) {
h1 {
font-size: 50px !important;
}
}
/* md */
#media (min-width: 992px) {
h1 {
font-size: 84px !important;
}
}
/* lg */
#media (min-width: 1200px) {
h1 {
font-size: 96px !important;
}
}
.navbar-left img {
width: auto;
}
.sm-bt img {
width: auto;
}
.end img {
width: auto;
}
.titlePage img {
max-width: 280px;
}
/*---Start Parallax---*/
.parallax-top {
background-image: url("../images/hero3.jpg");
height: 1200px;
background-attachment: fixed;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
}
.main .caption {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
height: auto;
padding: 0;
}
.main .caption h1 {
margin-top: 0px;
}
.main .caption p {
width: 80%;
margin: auto;
margin-bottom: 10px;
}
.parallax-middle {
background-image: url("../images/hero1.jpg");
height: 1200px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.caption-middle {
position: relative;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
font-size: 20px;
background-color: black;
opacity: 0.75;
height: auto;
padding: 1%;
}
.parallax-bottom {
background-image: url("../images/hero2.jpg");
height: 1200px;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.caption-bottom {
position: relative;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
padding: 1%;
height: auto;
}
/*---End Parallax---*/
.box {
height: 200px;
font-size: 40px;
margin-top: 80px;
text-align: center;
}
.thumbs {
margin-right: 15px;
max-width: auto;
}
.thumbnail {
border: none !important;
}
.fb-page {
margin-right: 50px;
}
.footer {
padding-top: 5px;
position: relative;
bottom: 0;
width: 100%;
height: auto;
background-color: #fff;
text-align: center;
}
.footer p {
font-size: 12px;
}
#media (min-width: 768px) {
.footer p {
font-size: 14px;
}
}
#media (min-width: 992px) {
.footer p {
font-size: 16px;
}
}
.sm-bt a {
float: right;
margin-top: 12px;
margin-right: 5px;
}
hr {
display: block;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 1px;
}
.pageOuter {
padding-top: 20px;
}
.imagePage {
float: left;
border-top: 30px;
padding-right: 30px;
}
.blurb {
display: block;
position: relative;
}
/*---Title Pages---*/
.pageOuter {
background-image: url("../images/background.png");
}
.titlePage {
width: 80%;
margin: auto;
padding-top: 30px;
padding-bottom: 30px
}
.titlePage .jumbotron {
width: 45%;
font-size: 14px;
float: right;
padding: 25px !important;
margin-right: 0px;
opacity: 0.7;
}
#media screen and (min-width: 468px) {
.titlePage .jumbotron p {
font-size: 16px;
}
.titlePage .jumbotron h3 {
font-size: 18px;
}
}
#media screen and (min-width: 1200px) {
.titlePage .jumbotron p {
font-size: 20px;
}
.titlePage .jumbotron h3 {
font-size: 24px;
}
}
.titlePage .container {
width: 100% !important;
margin-right: 0px;
}
.titlePage h1 {
text-align: center;
}
.titlePage h2 {
text-align: center;
}
.titlePage h3 {
text-align: center;
}
.titlePage p {
color: #4d4d4d;
line-height: 1.59;
margin-top: 0em;
margin-bottom: 1em;
}
.titleDetails ul {
list-style-type: none;
padding-left: 0;
}
.titleDetails ul li {
font-size: 14px;
color: #4d4d4d;
line-height: 1.59;
}
#media (min-width: 768px) {
.titleDetails ul li {
font-size: 16px;
color: #4d4d4d;
line-height: 1.59;
}
}
#media (min-width: 992px) {
.titleDetails ul li {
font-size: 18px;
color: #4d4d4d;
line-height: 1.59;
}
}
.titleDetails h3 {
text-align: left;
font-size: 20px;
}
.titleDetails {
margin-right: 0px;
float: left;
}
/*---End Title Pages---*/
/*---Start Contact---*/
.contactPage {
width: 80%;
margin: auto;
padding-top: 30px;
padding-bottom: 30px;
}
.contactPage h1 {
text-align: center;
}
.contactPage .jumbotron {
width: 40%;
padding: 10px;
position: center;
}
#media screen and (min-width: 468px) {
.contactPage .jumbotron p {
font-size: 16px;
}
.contactPage .jumbotron h3 {
font-size: 18px;
}
}
#media screen and (min-width: 1200px) {
.contactPage .jumbotron p {
font-size: 20px;
}
.contactPage .jumbotron h3 {
font-size: 24px;
}
}
.home-btn {
text-align: center;
}
/*---end Contact---*/
.regionPage {
width: 80%;
margin: auto;
padding-top: 20px;
}
/*---Start Africa---*/
.africaHero {
background-image: url("../images/africaHero.jpg");
height: 1200px;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.africaHero .caption {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
height: auto;
padding: 0.5%;
}
/*---end Africa---*/
/*---Start Author---*/
.authorHero {
background-image: url("../images/hero4.jpg");
height: 1200px;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.authorHero .caption {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
height: auto;
padding: 0.5%;
}
/*---end Author---*/
/*---Start Asia--*/
.asiaHero {
background-image: url("../images/asiaHero.jpg");
height: 1200px;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.asiaHero .caption {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
height: auto;
padding: 0.5%;
}
/*---end asia---*/
/*---Start Australasia---*/
/*---End Australasia---*/
.australasiaHero {
background-image: url("../images/australasiaHero.jpg");
height: 1200px;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.australasiaHero .caption {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
height: auto;
padding: 0.5%;
}
/*---Start N America---*/
.namericaHero {
background-image: url("../images/namericaHero.jpg");
height: 1200px;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.namericaHero .caption {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
height: auto;
padding: 0.5%;
}
/*---end N America---*/
/*---Start S America---*/
.samericaHero {
background-image: url("../images/samericaHero.jpg");
height: 1200px;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.samericaHero .caption {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
height: auto;
padding: 0.5%;
}
/*---End S America--*/
/*---Start Europe---*/
.europeHero {
background-image: url("../images/europeHero.jpg");
height: 1200px;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.europeHero .caption {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
height: auto;
padding: 0.5%;
}
/*---Start Why CS---*/
.whyHero {
background-image: url("../images/hero5.jpg");
height: 1200px;
background-position: top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.whyHero .caption {
position: absolute;
left: 0;
top: 40%;
width: 100%;
text-align: center;
color: white;
background-color: black;
opacity: 0.75;
height: auto;
padding: 0.5%;
}
/*---end Why CS---*/
/*---Start authors---*/
.authors .caption {
text-align: center;
}
.authorPage img {
display: block;
margin: auto;
}
.authorPage p {
margin-top: 25px;
}
.authorPage {
width: 80%;
margin: auto;
}
.authorPage h1 {
text-align: center;
}
.authorPage .container{
display: flex
}
.authorPage .jumbotron {
width: 40%;
padding: 3px;
position: center;
margin: 5%;
}
.authorPage ul {
list-style-type: none;
padding-left: 0;
}
#media screen and (min-width: 468px) {
.authorPage .jumbotron p {
font-size: 16px;
}
.author .jumbotron h3 {
font-size: 18px;
}
}
#media screen and (min-width: 1200px) {
.authorPage .jumbotron p {
font-size: 20px;
}
.authorPage .jumbotron h3 {
font-size: 24px;
}
}
/*---End authors---*/
/*---start team---*/
h1 {
text-align: center;
}
.team1 {
padding: 2%;
}
.team2 {
padding: 2%;
}
.team1 img {
float: right;
margin-left: 10px;
padding: 10px;
}
.team2 img {
float: left;
margin-right: 15px;
padding: 10px;
}
CodePen
Hi i have fixed the issue by adding position and z-index to your imagePage div. Please check the styling below and please let me know.
.imagePage {
float: left;
border-top: 30px;
padding-right: 30px;
position: relative;
z-index: 10;
}

Issue mixing variable with mixin with keyframe animation?

First time using SCSS, and testing my knowledge from the Sass-Lang.com guide. According to the guide, it is possible to both set variables and use mixins to simplify your CSS.
I was coding an animation where the div is clipped from bottom to top. I used variables to set the initial and final clip-path settings, and used them while calling a mixin. Yet I get the error, 'Invalid CSS after "...slider-initial)": expected "{", was "; }"'. What am I doing wrong?
Here is my code:
<body>
<section id='main'>
<div id='left'></div>
<div id='right'></div>
<section>
</body>
$slider-initial: inset(0 0 0 0);
$slider-final: inset(0 0 100% 0);
#mixin slider-clip($slider-state) {
-webkit-clip-path: $slider-state;
clip-path: $slider-state;
}
body {
height: 100%; width: 100%;
margin: 0 auto;
}
#main {
height: 64vh; width: 38vw;
margin: 0 auto;
margin-top: 10%;
position: relative;
display: flex;
flex-direction: row;
justify-content: center;
border: 1vh solid black;
}
#left {
order: 1;
width: 4%;
height: 100%;
margin-left: 46%;
background: green;
}
#right {
opacity: 1;
order: 2;
width: 4%;
height: 100%;
margin: auto;
margin-left: 0;
animation-name: dropdown;
animation-duration: 4s;
background: red;
}
#keyframes dropdown {
from { #mixin slider-clip($slider-initial); }
to { #mixin slider-clip($slider-final); }
}
You called your mixin in a wrong way:
#keyframes dropdown {
from { #mixin slider-clip($slider-initial); }
to { #mixin slider-clip($slider-final); }
}
In the guide on sass-lang.com, you can see the following example of how to include a mixin:
.box { #include border-radius(10px); }
Applied to your case, your code should look like this:
#keyframes dropdown {
from { #include slider-clip($slider-inital); }
to { #include slider-clip($slider-final); }
}

Resources