Circle image on hover occupy 100% height and width - css

Hi I'm trying to do an animation on hover, without the hover I would like my circle to make 100% of the height and width
and for some reason I am not able to leave my circle with 100% border radius
like this:
code:
export const TeamCard = styled.div`
background: red;
padding: 10px 0;
& .bgCircle {
border-radius: 50%;
padding: 64px;
background: hotpink;
}
`;
export default function App() {
return (
<TeamCard>
<div className="bgCircle" />
<div class="description">
<h3>huhuehu</h3>
<h3>testing</h3>
</div>
</TeamCard>
example:
https://codesandbox.io/s/dry-river-09ft0

Try using the following styled-div:
export const TeamCard = styled.div`
position: relative;
background: red;
height: 300px;
width: 300px;
& .bgCircle {
border-radius: 100%;
height: 50px;
width: 50px;
background: hotpink;
transition: all ease 333ms;
}
&:hover {
.bgCircle {
position: absolute;
top: 0;
height: 300px;
width: 300px;
border-radius: 0;
left: 0;
right: 0;
}
}
& .description {
position: absolute;
bottom: 0;
}
`;
This is making use of absolute positioning to correctly set where the circle should go. In order to make absolute positioning work, the containing element needs to have a position of something other than 'static'.
The transition property is what provides the animation.

Related

CSS - stack two elements on top of each other

I have a stackblitz here
This should be the simplest thing but I can't see why its not working.
I have react app with Typescript and a styled components, I'm sure none of that is the problem this is just css.
I'm trying to position two divs on top of each other.
The container has position: relative;
And then the div are absolutely positioned.
.FlexContainerColOne,
.FlexContainerColTwo{
position: absolute;
top: 0;
left: 0;
}
But both div disappear, what am I missing
From what I am seeing here is that they are not disappearing, you just can't see them because they don't have a width assigned or content. See the following, I added width, and opacity to show the two divs merging over each other.
stackblitz snippet
Result:
flexcontainer {
position: relative;
}
.FlexContainerColOne,
.FlexContainerColTwo {
position: absolute;
top: 0;
left: 0;
}
.FlexContainerColOne {
background: red;
height: 500px;
width: 500px;
opacity: 0.5;
}
.FlexContainerColTwo {
background: green;
height: 500px;
width: 500px;
opacity: 0.3;
}
<flexcontainer>
<div class="FlexContainerColOne"></div>
<div class="FlexContainerColTwo"></div>
</flexcontainer>

How to implement a CSS overlay which is partially transparent? [duplicate]

This question already has answers here:
Hole in overlay with CSS
(6 answers)
How to show an animation that is hidden behind a colored div using a "reveal" div on the surface
(5 answers)
Closed 1 year ago.
Here's sort of what I'm going for:
I have a scanner component (plays back what the camera is seeing) but I need to wrap it somehow to create a semi-opaque overlay with a transparent rectangle directly in the center of the screen.
How can this be done?
Similar to the "border" solution, you can use an inset box-shadow, some what effectively.
.wrap {
position: relative;
}
.wrap::before {
position: absolute;
height: 100%;
width: 100%;
overflow: hidden;
box-shadow: inset 0 0 0 150px rgb(0 0 0 / 70%);
content: '';
}
body {
margin: 0;
}
<div class="wrap">
<img src="https://www.fillmurray.com/1000/1000">
</div>
You can try this workaround using clip-path.
You may adjust the dimensions of the highlight by editing the
style="--left: 30%; --top: 30%; --width: 40%; --height: 40%;"
part of the .frame element.
.frame {
position: relative;
display: inline-block;
}
.frame::after {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1;
clip-path: polygon(
0% 0%,
0% 100%,
var(--left) 100%,
var(--left) var(--top),
calc(var(--left) + var(--width)) var(--top),
calc(var(--left) + var(--width)) calc(var(--top) + var(--height)),
var(--left) calc(var(--top) + var(--height)),
var(--left) 100%,
100% 100%,
100% 0
);
}
<div class="frame" style="--left: 30%; --top: 30%; --width: 40%; --height: 40%;">
<img src="https://picsum.photos/id/16/640/320" />
</div>
You can use border to produce the 'overlay' portion - that way you have a true 'transparent' block that darkens everything outside it. The trick is to have the borders extend to the edges of the element (or the screen) - you can do that by specifying the border-width in viewport units, like this:
.container {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
}
.container img{
margin: auto;
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.loupe {
width: 24rem;
height: 18rem;
border: 0 solid rgba(0,0,0,0.5);
border-width: 50vh 50vw;
position: absolute;
top: -9rem; /* Half of height */
bottom: 0;
right: 0;
left: -12rem; /* Half of width */
margin: auto;
}
/* Optional - apply a shadow effect under the loupe */
.loupe::after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
box-shadow: 0 0.1rem 1.5rem rgba(0,0,0,0.25);
}
<div class="container">
<img src="https://images.unsplash.com/photo-1621135177072-57c9b6242e7a?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1534&q=80"/>
<div class="loupe">
</div>
</div>
If you need to fine-tune the position of the loupe, you can use transform: translate(); to adjust the position.

How can I overlay a ProgressSpinner in PrimeNG?

I have a progressBar spinner like this :
<p-progressSpinner></p-progressSpinner>
I want to make it center and overlay. How can I do that ?
Thanks .
This works for me: Original Url
html
<div class="progress-spinner" *ngIf="true">
<p-progressSpinner></p-progressSpinner>
</div>
css
.progress-spinner {
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: show;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
/* Transparent Overlay */
.progress-spinner:before {
content: '';
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.53);
}
Not sure what you mean by overlay, but if you want to have a progress spinner inside dialog then
<p-dialog [(visible)]="display" [showHeader]="false" [resizable]="false" [modal]="true" [focusOnShow]="false" >
<i class="pi pi-times" style="float:right" (click)="onCancel()"></i>
<div style="width: 900px;height: 500px;padding-top: 20%;">
<p-progressSpinner></p-progressSpinner>
</div>
</p-dialog>
I'm using PrimeVue (similar to PrimeNG, I think) and this is what I do to get a full-screen overlay with a progress spinner.
In my HTML, I have this...
<BlockUI :blocked="isLoading" :fullScreen="true"></BlockUI>
<ProgressSpinner v-show="isLoading" class="overlay"/>
Then in my css file I have this style...
.overlay {
position:fixed !important;
top: 0;
left: 0;
width: 100% !important;
height: 100% !important;
z-index: 100; /* this seems to work for me but may need to be higher*/
}
In my TypeScript, I have a reactive variable...
const isLoading = ref(false)
Then in various functions, I set the state of that variable as needed...
isLoading.value = true /* to show overlay + spinner */
isLoading.value = false /* to hide overlay + spinner */

How can I display scroll bars in the left direction too?

I wrote the following code.
This code hoped to display scroll bars on both left and right.
However, in fact you can only scroll to the right.
Is this behavior mentioned in the W3C specification?
How can I scroll left and right?
body {
overflow: auto;
}
.box1 {
position: absolute;
height: 100px;
width: 100px;
left: -50px;
background-color: red;
}
.box2 {
position: absolute;
height: 100px;
width: 100px;
right: -50px;
background-color: blue;
}
<div class="box1"></div>
<div class="box2"></div>
thank you.
Like other comments said, left overflow is hidden "by design" but...
What you could do is leave the left element at position left: 0; and then position your right element out of the view port with right: -100px; after what you would need to calculate the width of the actual view port and the width of the scrollable area and automatically position the horizontal scrollbar using the formula (scrollWidth - viewWidth) / 2.
You can see the result by running the snippet below.
// get view port width
const viewWidth = document.documentElement.clientWidth;
// get scroll width
const scrollWidth = document.documentElement.scrollWidth;
// position horizontal scroll
document.documentElement.scrollLeft = (scrollWidth - viewWidth) / 2;
body {
overflow: auto;
}
.box1 {
position: absolute;
height: 100px;
width: 100px;
left: 0; /* modified value from -50px to 0 */
background-color: red;
}
.box2 {
position: absolute;
height: 100px;
width: 100px;
right: -100px; /* modified value from -50px to -100px */
background-color: blue;
}
<div class="box1"></div>
<div class="box2"></div>

Aligning div overlay on percentage width element

I'm building a "staff" page with a liquid, four-column layout. I've placed a div element, absolutely positioned on top of the photo of each staff member to act as a button/link. My problem is that when I align this overlay div to bottom:0 and right:0 I will get the occasional 1 pixel gap between the image and the overlay as I resize the window. It seems this is a function of some sort of round-off error.
I've searched this site and others for help on this, but I haven't found this issue explicitly discussed anywhere. Any insights are greatly appreciated.
The page in question can be seen here:
communicationdesign.com/cwt-beta/about.html
Resize the window to see the occasional error/gap...
Here is the relevant markup:
<div class="staff-block">
<div class="staff-photo">
<img src="img/gruber.jpg" class="portrait" />
<a href="gruber.html">
<div class="plus-link">
<div class="plus-sign">+</div>
</div>
</a>
</div>
<div class="caption">
Drew Gruber<br /><span class="job-title">Executive Director</span>
</div>
</div>
And here is the CSS:
.staff-block {
position: relative;
width: 22.3%;
float: left;
background-color: #ffc;
margin-right: 3.5%;
}
.staff-photo{
position: relative;
}
.staff-photo img, .board-photo img, .bio-photo img {
width: 100%;
}
.portrait {
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
.plus-link {
transition: .5s ease;
opacity: 1;
position: absolute;
bottom: 0;
right: 0;
}
.plus-sign {
background-color: rgba(255,204,78,0.8);
color: white;
font-size: 40px;
line-height: 30px;
padding: 4px 8px 6px;
}
This is an occupational hazard when using percentages. You could use a hack like this:
.staff-photo{
overflow: hidden;
}
.plus-link {
background-color: rgba(255,204,78,0.8); // color on the plus sign parent
position: absolute;
bottom: -5px; // position it over the edge
right: -5px;
padding: 0 5px 5px 0; // and correct the extra space
}
.plus-sign {
background-color: transparent; // or remove bg color
}

Resources