V - slot, can't style or access it - css

I add the v-flip on my nuxt webpage. So my template looks like this:
<div class="about__cards">
<vue-flip class="about__single-card" active-click width = "350px" height="450px">
<template v-slot:front>
<p class="about__title">Stacks</p>
</template>
<template v-slot:back>
<h4>My stacks</h4>
<ul>
<li>Javascript</li>
<li>Css</li>
<li>HTML</li>
<li>Vue</li>
<li>Nuxt</li>
</ul>
</template>
</vue-flip>
...
This was my styling:
.about__cards{
display:flex;
justify-content: space-evenly;
/* background-color: transparent; */
}
.about__single-card{
border:1px red solid;
border-radius: 16px;
overflow: hidden;
box-shadow: 0 5px 18px rgba(0, 0, 0, 0.6);
cursor: pointer;
transition: 0.5s;
position: relative;
text-align: center;
transition: transform 0.6s;
transform-style: preserve-3d;
}
.front{
background: red;
width: 100%;
height: 100%;
/* line-height: 448px; */
text-align: center;
vertical-align: middle;
/* display: flex;
flex-direction: column;
align-content: flex-end; */
}
I put front because when inspecting the element I saw that was given that class. All all seems working. Then I realized that I haven't scoped the style so was messing with other pages. I did, restart the server and now it's not working anymore the styling of the v-slot. But If I go to inspect the element and I go to the "front"class that was pre-given I can change it there... I read that you can style v-slots, but before I did it so I am kind of confused. What I am missing here?
Thank you

It's because scoped styles are "scoped" by using component unique id as part of the selector.
If you inspect your app, you will see things like this (1d328d7a is the uid)
<div
data-v-1d328d7a=""
class="field-input-wrapper"
...
.field-input-wrapper[data-v-1d328d7a] {
...
In order to bypass this, you can use deep selector like this
.about__single-card >>> .front{
background: red;
width: 100%;
height: 100%;
text-align: center;
vertical-align: middle;
}

Related

When one element is hovered, change :before pseudo element as well

I have this button I am trying to make, when hovered, the button itself, and :before pseudo element
swap color schemes, as well as the arrow just inversing its color to still be visible, attached is the design system to visually represent the end goal.
I am unsure if pseudo elements can be changed in this manner, so I understand if I have to refactor a little bit, but here is the current snippet of code I am using:
HTML:
<header className="hero">
<div className="hero__img"></div>
<h1 className="hero__title">Modern Art Gallery</h1>
<p className="hero__desc">
The arts in the collection of the Modern Art Gallery all started from
a spark of inspiration. Will these pieces inspire you? Visit us and
find out.
</p>
<button className="hero__cta">Our Location</button>
</header>
SCSS:
&__cta {
font-family: $font-heading;
font-size: 2rem;
letter-spacing: 3.64px;
text-transform: uppercase;
color: $white;
background-color: $black;
border: none;
padding: 20px 25px;
text-align: center;
width: 204px;
height: 72px;
margin: 25px 15px;
position: relative;
transition: all 0.25s ease;
&::before {
position: absolute;
content: '';
content: url('../../public/assets/icon-arrow-right.svg');
width: 58px;
height: 72px;
background-color: $gold;
top: 0;
right: 0;
bottom: 0;
transform: translateX(100%);
display: flex;
justify-content: center;
align-items: center;
}
Thanks all!

css - how to center the span text in rounded button [duplicate]

This question already has answers here:
How can I center text (horizontally and vertically) inside a div block?
(27 answers)
Closed 1 year ago.
CodeSandbox:
https://codesandbox.io/s/eloquent-haibt-1bnib?file=/src/main.js
I want to center the - text in the button, but I cannot find a way to do it.
html
<button class="round-button align-middle mr-1">
<span>-</span>
</button>
css
.round-button {
min-width: 20px;
max-height: 20px;
text-decoration: none;
display: inline-block;
outline: none;
cursor: pointer;
border-style: none;
color: white;
background-color: #3498db;
border-radius: 100%;
overflow: none;
text-align: center;
padding: 0;
}
.round-button:before {
content: "";
display: inline-block;
vertical-align: middle;
}
html
<button class="round-button align-middle mr-1">-</button>
css
.round-button {
min-width: 20px;
height: 20px;
border-style: none;
color: white;
background-color: #3498db;
border-radius: 50%;
text-align: center;
padding: 0;
line-height: 20px; // to center text vertically
}
You just need to add the same line-height as your button's height and don't need an extra span element to add text. I've also removed unnecessary styles.
Try setting line-height: 20px to that. If it still looks off, you might be using a custom font with non-standard line height. In this case play with the line-height property until it looks okay.
Add the following style properties to .round-button:
.round-button {
display: flex;
align-items: center;
justify-content: center;
}
And, remove style for .round-button:before.
Try this.
.round-button {
background-color: #3498db;
border-style: none;
border-radius: 100%;
color: #fff;
cursor: pointer;
aspect-ratio: 1 / 1;
width: 48px;
display: flex;
align-items: center;
justify-content: center;
}
<button class="round-button">
<span>-</span>
</button>
Try changing <span>-</span> to <span style="position:relative; left:0px; top:-3px">-</span>. If it doesn't look right you can play around with it.

How can I make this transition work and let the hamburger icon stay on top?

I am new to programming, just started a few months ago, but trying to create a portfolio page, I have watched other peoples examples, and trying to create my own.
My problem is that I am trying to transition the navbar with a hamburger icon, which is working, but I have set the navbar to be fixed(this also works) and span across the viewport, which doesn't work. The width and the height of the element is just as much as my list elements. I cannot see where the problem is, also when I toggle the class, i.e. click the button to close the navbar it does not transition it just disappears. I will past my code here, will be glad if somebody can give me a hint. Also, I have the hamburger icon on the right and title on the left which I want to stay on top always, added z-index but it does not work.. Thanks, and apologies if I did not make my question very clear.
HTML code
<body>
<div>
<!-- create navbar with hamburger icon -->
<nav class="navbar">
<h2 class="myName">this.szabi<span class="braces">( )</span></h2>
<div class="menu-btn">
<div id="menuButtonBurger"></div>
</div>
</nav>
<div class="info">
<ul>
<li>About Me</li>
<li>Projects</li>
<li>Contact</li>
</ul>
</div>
<section id="about"></section>
<!-- create a small introduction place with a picture -->
<!-- create a div for technologies ive learnt -->
<!-- create a div to place my projects -->
<!-- create a div for contact information, social icons -->
<!-- create a footer -->
</div>
<script type="text/javascript" src="script.js"></script>
</body>
CSS code
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.navbar {
background-color: transparent;
width: 100%;
position: fixed;
display: flex;
justify-content: space-between;
}
.myName {
font-family: Comfortaa;
font-weight: 500;
color: #f05454;
z-index: 101;
}
.braces {
font-size: 2rem;
}
.menu-btn {
position: relative;
width: 3rem;
height: 3rem;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
border: 3px solid #f05454;
border-radius: 50%;
z-index: 102;
}
#menuButtonBurger {
width: 2rem;
height: 0.25rem;
background-color: #f05454;
border-radius: 5px;
}
#menuButtonBurger::before,
#menuButtonBurger::after {
content: "";
position: absolute;
width: 2rem;
height: 0.25rem;
background-color: #f05454;
border-radius: 5px;
}
#menuButtonBurger::before {
transform: translateY(-8px);
}
#menuButtonBurger::after {
transform: translateY(8px);
}
.info {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: -webkit-linear-gradient(-45deg, #000000, #434343);
background: linear-gradient(-45deg, #000000, #434343);
display: flex;
justify-content: center;
align-items: center;
color: white;
font-family: Comfortaa, Helvetica, sans-serif;
font-size: 2.5rem;
font-weight: bold;
line-height: 2.5;
z-index: 100;
transform: translateX(1500px);
}
.info .open {
background: -webkit-linear-gradient(-45deg, #000000, #434343);
background: linear-gradient(-45deg, #000000, #434343);
transform: translateX(-1500px);
transition: all 500ms linear;
}
.info ul li {
list-style: none;
}
.info li a,
.info li a:link,
.info li a:visited,
.info li a:active {
text-decoration: none;
color: #fff;
}
.info li a:hover {
color: #f05454;
}
/* change it */
#about {
width: 100%;
height: 1000px;
background-color: teal;
}
JavaScript code
const hamburger = document.querySelector('.menu-btn');
const info = document.querySelector('.info');
const list = document.querySelector('ul');
hamburger.addEventListener('click', menuToggle);
function menuToggle() {
console.log('clicked')
info.classList.toggle('open');
list.classList.toggle('open');
}
The width and the height of the element is just as much as my list elements.
Yes, that is the default behavior of elements in a div.
To change that, either define a custom width for your info div in your existing CSS section, just like that:
.info .open {
background: -webkit-linear-gradient(-45deg, #000000, #434343);
background: linear-gradient(-45deg, #000000, #434343);
transform: translateX(-1500px);
transition: all 500ms linear;
width: 270px; // Defining a custom width for the div
}
Or set a custom padding for the ul elements, like that:
.info ul {
padding-left: 30px; // Defining a padding to every list item, which causes outer div to grow according to that.
padding-right: 30px;
}
Now, regarding the transition. I tried to do something that would not change your code so much. First, We add a html class for handling when the info menu and the ul are closed:
div class="info closed">
<ul class="closed">
<!-- Rest of the code... -->
Then we create a new CSS code for handling the closed transition:
.info .closed {
background: -webkit-linear-gradient(-45deg, #000000, #434343);
background: linear-gradient(-45deg, #000000, #434343);
transition: all 500ms linear;
}

CSS wrap "up" so first line is shortest?

I want to show a list of tags at the bottom of the screen and if they don't all fit, I want it to wrap so that it's the first line that is the shortest - not the last line.
Once the bottom line is full, I would prefer if the next item added would be what would then appear above instead of below. But if it's easier to make the first item move up that would be ok too.
This example should make it clear:
div {
position: fixed;
bottom: 0%;
right: 0%;
line-height: 1.4;
text-align: right;
}
span {
border-radius: 5px;
padding: 1px 3px;
font-family: sans-serif;
color: white;
background-color: #7B68EE;
}
<div>
<span>Apple</span>
<span>Orange</span>
<span>Banana</span>
<span>Pear</span>
<span>Apricot</span>
<span>Cranberry</span>
<span>Blackcurrant</span>
<span>Raspberry</span>
<span>Strawberry</span>
<span>Plum</span>
<span>Tomato</span>
<span>Lemon</span>
<span>Lime</span>
<span>Coconut</span>
</div>
This can be achieved by adding flexbox styles to the parent container like so:
div {
position: fixed;
bottom: 0%;
right: 0%;
line-height: 1.4;
text-align: right;
/* flexbox styles */
display: flex;
flex-wrap: wrap-reverse;
justify-content: flex-end;
}
span {
border-radius: 5px;
padding: 1px 3px;
font-family: sans-serif;
color: white;
background-color: #7B68EE;
/* margin to separate tags */
margin: 0.1em;
}
<div>
<span>Apple</span>
<span>Orange</span>
<span>Banana</span>
<span>Pear</span>
<span>Apricot</span>
<span>Cranberry</span>
<span>Blackcurrant</span>
<span>Raspberry</span>
<span>Strawberry</span>
<span>Plum</span>
<span>Tomato</span>
<span>Lemon</span>
<span>Lime</span>
<span>Coconut</span>
</div>
Try using display:flex, also use flex-wrap:wrap-reverse in order to wrap the elements the way you want.
div {
display: flex;
flex-wrap: wrap-reverse;
position: fixed;
bottom: 0%;
right: 0%;
line-height: 1.4;
text-align: right;
}
span {
border-radius: 5px;
padding: 1px 3px;
font-family: sans-serif;
color: white;
background-color: #7B68EE;
}
Using flex property to align like this,
div {
display: flex;
flex-wrap: wrap-reverse; // reverse the wrapping
flex-direction: row-reverse; // reverse the row
}
also add some margin to span
span{
margin:3px;
}
flex-wrap - The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked.
flex-direction: row-reverse - Work in a left-to-right language such as English. If you are working in a right-to-left language like Arabic then row would start on the right, row-reverse on the left.
Result:-
LIVE DEMO
div {
position: fixed;
bottom: 0%;
right: 0%;
line-height: 1.4;
display: flex;
flex-wrap: wrap-reverse;
flex-direction: row-reverse;
}
span {
border-radius: 5px;
padding: 1px 3px;
font-family: sans-serif;
color: white;
background-color: #7B68EE;
margin:3px;
}
<div>
<span>Apple</span>
<span>Orange</span>
<span>Banana</span>
<span>Pear</span>
<span>Apricot</span>
<span>Cranberry</span>
<span>Blackcurrant</span>
<span>Raspberry</span>
<span>Strawberry</span>
<span>Plum</span>
<span>Tomato</span>
<span>Lemon</span>
<span>Lime</span>
<span>Coconut</span>
</div>

css - remove white space below anchor tag

See if i can get it working here: https://codepen.io/canovice/pen/pVoBXJ
I have searched a bit for this answer but have had no luck resolving the issue. Here is a screenshot of an anchor tag in a react component of mine:
Notice the 3px margin (orange) and 3px padding (green), and also notice that below the text is a massive amount of white space that I would like to get rid of, but am struggling to do so. Any help is appreciated.
*Note: I've tried the suggestions at this link here with no luck...
*Edit: let me know if theres more i can share on my app, ie. the current stylings, that will help.
Javascript for the React component:
import React from 'react';
import FaTwitter from 'react-icons/lib/fa/twitter';
import './TopPageHeader.css'
const TopPageHeader = () =>
<div className="top-page-container">
Canova's Analytics Dashboards
<div className="social-links">
<a href="https://twitter.com/SmokeyCanova">
<FaTwitter />
</a>
</div>
</div>
export default TopPageHeader;
and CSS:
.top-page-container {
padding: 15px 20px;
margin: 0;
min-height: 30px;
height: auto;
width: 100%;
border-bottom: 1px solid #000;
display: flex;
justify-content: space-between;
}
.top-page-container a {
/*display: block;*/
/*height: auto;*/
vertical-align: bottom;
padding: 3px;
margin: 3px;
font-size: 1.75em;
/*padding: 15px 0px;*/
color: #000;
}
.top-page-container .social-links {
font-size: 1.75em;
/*padding: 15px 0px;*/
}
Lastly, here's what the component looks like on the top of my page. Canova Analytics Dashboard is not centered, but rather offcenter up a bit (due to this extra white space below the anchor tag)... Ideally, the vertical center of the text, and the vertical center of the twitter logo, would both be vertically centered on the div they are contained in.
Here's what the component is contained within...
This is a top page header component, and hence nothing before it. I don't think the css is being impacted anywhere else, but i could be wrong.
You're using flexbox on your .top-page-container element, with a min-height. This is then correctly forcing the child element to occupy the full container height.
Add the align-items property of .top-page-content with something like flex-start, center, etc.
.top-page-container {
padding: 15px 20px;
margin: 0;
min-height: 30px;
height: auto;
width: 100%;
border-bottom: 1px solid #000;
align-items: flex-start; // <-- add this
display: flex;
justify-content: space-between;
}
.top-page-container a {
/*display: block;*/
/*height: auto;*/
vertical-align: bottom;
padding: 3px;
margin: 3px;
font-size: 1.75em;
/*padding: 15px 0px;*/
color: #000;
}
.top-page-container .social-links {
font-size: 1.75em;
/*padding: 15px 0px;*/
}
<div class="top-page-container">
Canova's Analytics Dashboards
<div class="social-links">
<a href="https://twitter.com/SmokeyCanova">
<FaTwitter />
</a>
</div>
</div>
Play with the line-height CSS property.
For example set it to 1 or 0.
You haven't provide any example code though.

Resources