I'd like to simulate a "scan" light that will reveal words in a box, this is my code by now:
const e = document.getElementsByClassName('scan')[0];
document.onmousemove = function(event){
e.style.left = `${event.clientX}px`;
};
*{
margin: 0;
padding: 0;
}
html, body{
width: 100%;
min-height: 100vh;
overflow-x: hidden;
display: flex;
}
.banner{
width: 100vw;
height: 100vh;
display: flex;
flex-grow: 1;
flex-direction: row;
align-items: center;
background-color: #031321;
}
.banner .scan{
width: 7px;
height: 80%;
position: absolute;
left: 30px;
z-index: 3;
transition: left 50ms ease-out 0s;
border-radius: 15px;
background-color: #fff;
box-shadow:
0 0 15px 5px #fff, /* inner white */
0 0 35px 15px #008cff, /* inner blue */
0 0 350px 20px #0ff; /* outer cyan */
}
.banner .description{
width: 100%;
color: white;
font-size: 3em;
text-align: center;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
<div class="banner">
<div class="scan"></div>
<div class="description">
Just trying something
</div>
</div>
The idea is the show the words in the .description div according to the scan light position. If possible I'd like to use CSS only to make this effect, and use JavaScript only to move the scan (which will further become a CSS animation). I tried to use some pseudo elements, but it didn't work well. Here's an example of how this animation should work.
You can use transparent text with gradient background. I used background-attachment: fixed and a CSS variable to control background position.
You can increase the background-size (500px in this example) to increase transition smoothing.
const e = document.getElementsByClassName('scan')[0];
const hidden = document.getElementsByClassName('hidden')[0];
document.onmousemove = function(event) {
e.style.left = `${event.clientX}px`; // ↓ background width (500px) / 2
hidden.style.setProperty("--pos", `${event.clientX - 250}px`);
};
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
min-height: 100vh;
overflow-x: hidden;
display: flex;
}
.banner {
width: 100vw;
height: 100vh;
display: flex;
flex-grow: 1;
flex-direction: row;
align-items: center;
background-color: #031321;
}
.banner .scan {
width: 7px;
height: 80%;
position: absolute;
left: 30px;
z-index: 3;
transition: left 50ms ease-out 0s;
border-radius: 15px;
background-color: #fff;
box-shadow: 0 0 15px 5px #fff, /* inner white */
0 0 35px 15px #008cff, /* inner blue */
0 0 350px 20px #0ff;
/* outer cyan */
}
.banner .description {
width: 100%;
color: white;
font-size: 3em;
text-align: center;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.hidden {
background: radial-gradient(dodgerblue 10%, #031321 50%) var(--pos) 50% / 500px 500px no-repeat fixed;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<div class="banner">
<div class="scan"></div>
<div class="description">
Just <span class="hidden">hidden</span> something
</div>
</div>
Here is another example with very long paragraph and multiple hidden text. We control both X and Y axis in here.
const hiddens = document.querySelectorAll('.hidden');
document.addEventListener("mousemove", e => {
hiddens.forEach(p => {
// ↓ background width (400px) / 2
p.style.setProperty("--posX", `${e.clientX - 200}px`);
p.style.setProperty("--posY", `${e.clientY - 200}px`);
});
});
html,
body {
width: 100%;
overflow-x: hidden;
}
body {
background: #031321;
color: #fff;
font-size: 3rem;
line-height: 1.5;
padding: 20px;
box-sizing: border-box;
}
.hidden {
background: radial-gradient(dodgerblue 10%, #031321 50%) var(--posX) var(--posY) / 400px 400px no-repeat fixed;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
Lorem ipsum dolor sit amet, <span class="hidden">consectetur</span> adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. <span class="hidden">Excepteur sint</span> occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum
dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea <span class="hidden">commodo</span> consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat
non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim
id est laborum.
Here is an idea using transformation to have better performance
document.onmousemove = function(event){
document.body.style.setProperty("--p", `${event.clientX}px`);
};
body{
margin: 0;
overflow:hidden;
}
.banner{
height: 100vh;
display: flex;
align-items: center;
background-color: #031321;
}
.banner::before{
content:"";
width: 7px;
height: 80%;
position: absolute;
left: 0;
transform:translateX(var(--p,30px));
z-index: 3;
transition: transform 50ms ease-out 0s;
border-radius: 15px;
background-color: #fff;
box-shadow:
0 0 15px 5px #fff, /* inner white */
0 0 35px 15px #008cff, /* inner blue */
0 0 350px 20px #0ff; /* outer cyan */
}
.banner .description{
color: white;
font-size: 3em;
text-align: center;
width:100%;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
overflow:hidden;
position:relative;
}
.banner .description::before {
content:"";
position:absolute;
top:0;
right:0;
bottom:0;
width:200%;
background:linear-gradient(to right,#031321 40%,transparent,#031321 60%);
transform:translateX(var(--p,0px));
}
<div class="banner">
<div class="description">
Just trying something
</div>
</div>
To apply it to only few words, you play with z-index
document.onmousemove = function(event){
document.body.style.setProperty("--p", `${event.clientX}px`);
};
body{
margin: 0;
overflow:hidden;
}
.banner{
height: 100vh;
display: flex;
align-items: center;
background-color: #031321;
}
.banner::before{
content:"";
width: 7px;
height: 80%;
position: absolute;
left: 0;
transform:translateX(var(--p,30px));
z-index: 3;
transition: transform 50ms ease-out 0s;
border-radius: 15px;
background-color: #fff;
box-shadow:
0 0 15px 5px #fff, /* inner white */
0 0 35px 15px #008cff, /* inner blue */
0 0 350px 20px #0ff; /* outer cyan */
}
.banner .description{
color: white;
font-size: 3em;
text-align: center;
width:100%;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
overflow:hidden;
position:relative;
z-index:0;
}
.banner .description::before {
content:"";
position:absolute;
z-index:-1;
top:0;
right:0;
bottom:0;
width:200%;
background:linear-gradient(to right,#031321 40%,transparent,#031321 60%);
transform:translateX(var(--p,0px));
}
.banner .description > span {
position:relative;
z-index:-2;
color:lightblue;
font-weight:bold;
}
<div class="banner">
<div class="description">
Just <span>trying</span> something <span>cool</span>
</div>
</div>
Another idea to make it working with any background in case you want transparency:
document.onmousemove = function(event){
document.body.style.setProperty("--p", `${event.clientX}px`);
};
body{
margin: 0;
overflow:hidden;
}
.banner{
height: 100vh;
display: flex;
align-items: center;
justify-content:center;
color: white;
font-size: 3em;
background: url(https://picsum.photos/id/1018/800/800) center/cover;
position:relative;
z-index:0;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
.banner::before{
content:"";
width: 7px;
height: 80%;
position: absolute;
left: 0;
transform:translateX(var(--p,30px));
z-index: 3;
transition: transform 50ms ease-out 0s;
border-radius: 15px;
background-color: #fff;
box-shadow:
0 0 15px 5px #fff, /* inner white */
0 0 35px 15px #008cff, /* inner blue */
0 0 350px 20px #0ff; /* outer cyan */
}
.banner::after {
content:"";
position:absolute;
z-index:-1;
top:0;
right:0;
bottom:0;
left:0;
background:inherit;
-webkit-mask:
linear-gradient(to right,#fff 45%,transparent,#fff 55%)
right calc(-1*var(--p,0px)) top 0/200% 100% no-repeat;
}
.banner > span {
position:relative;
z-index:-2;
color:red;
font-weight:bold;
}
<div class="banner">
Just <span>trying</span> something <span>cool</span>
</div>
Cool glow stick!
I'm assuming that this is for a logo, and that the text should continue to be shown when the glow stick has passed the text.
I would use a pseudo-element on the description element, place it on top and use a gradient-background going from transparent to the darkblue background color. By using a gradient, you can achieve a nice fade in of the text.
I would then set the starting point of the dark background color with a CSS variable that I update through your onmousemove method.
The code doesn't take different screen sizes into account, so you probably need to convert pixels to percentage, if you want your animation to be responsive.
I also changed your classes to id. I think it's more appropriate to show, by using ids, that the element is somehow used by javascript. It's easier to bind the elements to variables too.
const scanEl = document.getElementById('scan');
const descEl = document.getElementById("description")
document.onmousemove = function(event){
let descriptionDisplacement = 100;
scanEl.style.left = `${event.clientX}px`;
descEl.style.setProperty("--background-shift", `${event.clientX + descriptionDisplacement}px`);
};
*{
margin: 0;
padding: 0;
}
html, body{
width: 100%;
min-height: 100vh;
overflow-x: hidden;
display: flex;
}
.banner{
width: 100vw;
height: 100vh;
display: flex;
flex-grow: 1;
flex-direction: row;
align-items: center;
background-color: #031321;
}
.banner > #scan{
width: 7px;
height: 80%;
position: absolute;
left: 30px;
z-index: 3;
transition: left 50ms ease-out 0s;
border-radius: 15px;
background-color: #fff;
box-shadow:
0 0 15px 5px #fff, /* inner white */
0 0 35px 15px #008cff, /* inner blue */
0 0 350px 20px #0ff; /* outer cyan */
}
.banner > #description{
width: 100%;
color: white;
font-size: 3em;
text-align: center;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
/* ADDED */
--background-shift: 0px;
--background-shift-transparent: calc(var(--background-shift) - 150px);
position: relative;
}
.banner > #description::before {
content: '';
background: linear-gradient(to right, transparent var(--background-shift-transparent), #031321 var(--background-shift));
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
<div class="banner">
<div id="scan"></div>
<div id="description">
Just trying something
</div>
</div>
I just tried clipPath. Technically it does what you need but the performance of the animated clipPath is quite poor when combined with the glow effect (but much better without!). Possibly building the glow from something like an image instead of a box-shadow would improve this. (as could reducing the size of the outer most box shadow)
const e = document.getElementsByClassName('scan')[0];
const description = document.getElementsByClassName('description')[0];
document.onmousemove = function(event){
// comment out to compare performance
e.style.left = `${event.clientX}px`;
description.style.clipPath = `polygon(0 0, ${event.clientX}px 0, ${event.clientX}px 100%, 0 100%)`;
};
*{
margin: 0;
padding: 0;
}
html, body{
width: 100%;
min-height: 100vh;
overflow-x: hidden;
display: flex;
}
.banner{
width: 100vw;
height: 100vh;
display: flex;
flex-grow: 1;
flex-direction: row;
align-items: center;
background-color: #031321;
}
.banner .scan{
width: 7px;
height: 80%;
position: absolute;
left: 30px;
z-index: 3;
transition: left 50ms ease-out 0s;
border-radius: 15px;
background-color: #fff;
box-shadow:
0 0 15px 5px #fff, /* inner white */
0 0 35px 15px #008cff, /* inner blue */
0 0 350px 20px #0ff; /* outer cyan */
}
.banner .description{
width: 100%;
color: white;
font-size: 3em;
text-align: center;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
<div class="banner">
<div class="scan"></div>
<div class="description">
Just trying something
</div>
</div>
Try like this:
const e = document.getElementsByClassName('cover')[0];
e.addEventListener('click', animate);
function animate() {
e.classList.add('scanning');
}
*{
margin: 0;
padding: 0;
}
html, body{
width: 100%;
min-height: 100vh;
overflow-x: hidden;
display: flex;
}
.banner{
width: 100vw;
height: 100vh;
display: flex;
flex-grow: 1;
flex-direction: row;
align-items: center;
background-color: #031321;
}
.banner .cover{
position: absolute;
left: 30px;
z-index: 3;
height: 80%;
width:100vw;
background-color: #031321;
transition: left 700ms ease-out 0s;
}
.banner .cover.scanning {
left: calc(100% - 30px);
}
.banner .scan{
width: 7px;
height:100%;
transition: left 50ms ease-out 0s;
border-radius: 15px;
background-color: #fff;
box-shadow:
0 0 15px 5px #fff, /* inner white */
0 0 35px 15px #008cff, /* inner blue */
0 0 350px 20px #0ff; /* outer cyan */
}
.banner .description{
width: 100%;
color: white;
font-size: 3em;
text-align: center;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
<div class="banner">
<div class="cover">
<div class="scan">
</div>
</div>
<div class="description">
Just trying something
</div>
</div>
This solution uses a cover to the right of the scan with the same background colour as the banner. The cover moves with the scan, so when the scan moves to the right, it reveals the text on the left. It works by clicking on it in this demo, but you can initiate it in JavaScript however is best for you.
Seems a little tricky. The first solution that comes to mind is maybe using a linear gradient with a dynamic "stopping point" at the light bar position. The gradient goes from dark -> transparent (light bar position) -> dark. The code will maybe look something like:
.description-overlay {
/*
Replace 50% with the position of the light bar. Get brighter and more
transparent as you approach the position of the light bar.
*/
background: linear-gradient(to right, #000, 50% hsla(0, 0%, 100%, 0.2), #000);
}
Not sure if this will work and it would probably need a box-shadow thrown in somewhere, but maybe it'll give you some ideas.
Related
This question already has answers here:
How can I position my div at the bottom of its container?
(25 answers)
Closed 6 months ago.
I have a card like this:
And the cards have this CSS:
.card {
height:350px !important;
position: relative;
display: flex;
flex-direction: column;
min-width: 0;
word-wrap: break-word;
background-color: #ffffff;
background-clip: border-box;
border: 1px solid rgba(0, 0, 0, 0.125);
border-radius: 0.25rem;
}
label.star {
padding: 5px 2px;
margin-bottom: 0px;
font-size: 18px;
color: #444;
transition: all .2s;
}
As you can see the stars are not placed in the bottom of div and their position depends on the length of the card title.
So I need to place and stick the stars at the bottom of the cards.
So I tried setting this css:
.card{
position:relative;
}
label.star {
position:absolute;
margin-bottom:0px !important;
}
But the result goes like this:
So what's going wrong here?
How can I stick the stars of all divs to the bottom of the cards properly?
There are a few issues with your code. In your first example, the stars are overflowing due to the fact that the text is allowed to also overflow. In the second, you are not positioning your stars with any of the position properties such as top, bottom, left, right, or inset.
.card {
position: relative;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
max-width: 350px;
background-color: #ffffff;
background-clip: border-box;
border: 1px solid rgba(0, 0, 0, 0.125);
border-radius: 0.25rem;
}
figure{
margin: 0;
background-color: blue;
width: 100%;
height: 300px;
}
p{
padding: 10px;
text-align: center;
height: 100px;
overflow: hidden;
text-overflow: ellipsis;
word-wrap: break-word;
}
.star {
padding: 5px 2px;
font-size: 18px;
color: #444;
transition: all .2s;
}
<article class="card">
<figure></figure>
<p>
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</p>
<div class="star">
* * * * *
</div>
</article>
By using flexbox in addition to overflow: hidden you can guarantee a specific height with a flexible width for your element, whilst keeping your ratings/stars glued to the bottom of the element.
Additionally, label is a semantic HTML element intended to be used with inputs. You didn't share your HTML, so I can't tell if it's being used correctly here, but just in case I used div in my example.
I have a header on my website and I want to be able to set my canvas to fill all of the remaining height.
This is the Code:
<div include-html="../global/navbar.html">
<ul class="navbar">
<li class="navbar">Ben</li>
<li class="navbar">Projects</li>
</ul>
</div>
<div class="CanvasContainer">
<canvas id="Canvas" height="440" width="200">
</canvas>
</div>
canvas {
padding: 0;
margin: auto;
display: block;
width: 400px;
}
body {
padding: 0;
margin: 0;
background-color: #17141d;
color: white;
font-family: 'DM Mono', monospace;
}
ul.navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #17141d;
}
li.navbar {
float: left;
}
li.navbar a{
display: block;
padding: 14px 16px;
}
a {
font-size: 20px;
text-align: center;
text-decoration: none;
background-color: #17141d;
color: white;
}
a:hover {
background-color: #262130;
background: linear-gradient(90deg,#ff8a00,#e52e71);
-webkit-text-fill-color: transparent;
background-clip: text;
-webkit-background-clip: text;
}
function LoadCanvas(){
var canvas = document.getElementById("Canvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 150, 75);
}
height:100%; sets the height to the height of the window
Filler so stackoverflow lets me save the edit:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
One way to take up the remaining space with the canvas would be to use flexbox.
In the following I use the property flex: 1 to tell the container to take the remaining space.
function LoadCanvas() {
var canvas = document.getElementById("Canvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0, 0, 150, 75);
}
canvas {
padding: 0;
margin: auto;
display: block;
width: 400px;
height: 100%;
}
body {
padding: 0;
margin: 0;
background-color: #17141d;
color: white;
font-family: "DM Mono", monospace;
display: flex;
height: 100vh;
flex-direction: column;
}
.CanvasContainer {
display: flex;
flex: 1;
}
ul.navbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #17141d;
}
li.navbar {
float: left;
}
li.navbar a {
display: block;
padding: 14px 16px;
}
a {
font-size: 20px;
text-align: center;
text-decoration: none;
background-color: #17141d;
color: white;
}
a:hover {
background-color: #262130;
background: linear-gradient(90deg, #ff8a00, #e52e71);
-webkit-text-fill-color: transparent;
background-clip: text;
-webkit-background-clip: text;
}
<div include-html="../global/navbar.html">
<ul class="navbar">
<li class="navbar">Ben</li>
<li class="navbar">Projects</li>
</ul>
</div>
<div class="CanvasContainer">
<canvas id="Canvas"> </canvas>
</div>
Safari seems to have a bug that when you use webkit-background-... to give text some gradient it sometimes creates a really thin border.
It's really hard to reproduce this error consistently. The problem doesn't occur on each screen size or resolution. Adding/removing a paragraph on a random place on the page sometimes solves the issue (no logic),... Especially on Safari for iOS this problem occurs.
But this is the code I am using:
<span id="text">text.</span>
#text {
font-size: 8em;
font-weight: 700;
letter-spacing: 1px;
color: #000000;
text-decoration: none;
display: block;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-image: linear-gradient(to right, #09D380, #0EC7D4 50%, #a4a4a4 50%);
background-size: 200% 100%;
}
This code is supposed to give the text inside the span a customized background, in this case a gradient. And that works fine. On it's own this code also does not have this issue.
The problem occurs when mixing it on a page with more content:
<!DOCTYPE html>
<html>
<head>
<title>Safari bug</title>
<link rel="icon" type="image/png" href="favicon.png">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght#100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<style>
body {
font-family: Poppins, sans-serif;
width: 100%;
height: 100%;
padding: 0;
background: linear-gradient(90deg, rgba(246,246,246,1) 0%, rgba(255,255,255,1) 50%)
}
#container {
position: absolute;
top: 50%;
left: 0;
transform: translate(0, -50%);
width: 100%;
}
#inner-container {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
width: 90%;
}
#under-construction-half {
position: relative;
text-align: center;
}
#under-construction-half img {
width: 60%;
margin-right: 10px;
}
#logo-and-slogan-half {
text-align: left;
box-sizing: border-box;
margin-left: 50px;
}
#logo {
font-size: 8em;
font-weight: 700;
letter-spacing: 1px;
color: #000000;
text-decoration: none;
display: block;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-image: linear-gradient(to right, #09D380, #0EC7D4 50%, #a4a4a4 50%);
background-size: 200% 100%;
}
#slogan {
font-size: 3.5em;
margin-top: -10%;
color: #3B3B3A;
}
#text {
margin-left: 7.5%;
margin-top: 7%;
font-size: 1.5em;
}
#under-construction-title {
font-weight: 700;
color: #09DD80;
font-size: 1.3em;
}
span {
display: block;
}
#media screen and (max-width: 950px) {
#inner-container {
flex-direction: column;
margin: auto;
}
#logo-and-slogan-half {
margin-left: 0;
font-size: 60%;
}
#text {
width: 90%;
margin: auto;
font-size: 100%;
margin-top: 20%;
}
#under-construction-half {
text-align: left;
}
#under-construction-half img {
width: 50%;
}
}
</style>
</head>
<body>
<div id="container">
<div id="inner-container">
<div id="logo-and-slogan-half">
<div id="logo-and-slogan">
<span id="logo">text.</span>
</div>
</div>
</div>
<div id="text">
<span id="under-construction-title">title...</span>
<p id="under-construction-text">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
</div>
</body>
</html>
Demo page.
Adding a border to the span with the same color as the background of the page also solves the issue. But this is not always possible due to having for example an image as background.
I am already tweaking and fiddling with this HTML/CSS code to resolve the issue, but I can't find a solution for this bug.
You can crop few pixels around using clip-path:inset(1px). You can use a smaller or a bigger value based on your need.
You can also crop only from the top clip-path:inset(1px 0 0). The values work the same way as with padding/margin.
I want to make an effect where when you hover over it, an overlay slides up. I have a card and it has padding. I want the overlay to be 100% of the card's width but the padding on it makes it thinner.
I have created a quick example to show the issue (note: the ".read" class with the blue background is what I'm talking about):
.card h2 {
padding-top: 1em;
}
.card img {
width: 100%;
height: 25em;
}
.card {
width: 50%;
float: left;
background: #e5e5e5;
padding: 2em;
margin: 1em;
box-sizing: border-box;
cursor: pointer;
transition: all 300ms ease;
overflow: hidden;
}
.read {
color: white;
background: blue;
height: 40px;
}
<div class="card">
<img src="https://prodimage.images-bn.com/pimages/9781338659511_p0_v1_s550x406.jpg">
<h2>Integer Sagittis</h2>
<p>Integer Sagittis</p>
<div class=read>
<p>Read more</p>
</div>
</div>
Does anyone know how to make the overlay 100% of the card's width?
You can even out the padding by giving the .read a negative margin.
I also implemented how you should do the hovering part, here's the example, you can try to hover on the card:
.card h2 {
padding-top: 1em;
}
.card img {
width: 100%;
height: 25em;
}
.card {
--padding: 2em;
width: 50%;
float: left;
background: #e5e5e5;
padding: var(--padding);
margin: 1em;
box-sizing: border-box;
cursor: pointer;
transition: all 300ms ease;
overflow: hidden;
}
.read {
color: white;
background: blue;
height: 40px;
margin: calc(var(--padding) * -1);
margin-top: 0;
transform: translateY(100%);
transition: transform .2s;
}
.card:hover .read{
transform: translateY(0);
}
<div class="card">
<img src="https://prodimage.images-bn.com/pimages/9781338659511_p0_v1_s550x406.jpg">
<h2>Integer Sagittis</h2>
<p>Integer Sagittis</p>
<div class=read>
<p>Read more</p>
</div>
</div>
There's also a solution is to make the .read position: absolute. But in that way you need to make some room at the bottom of the .card from .read not obscuring the content, which is less flexible.
.card h2 {
padding-top: 1em;
}
.card img {
width: 100%;
height: 25em;
}
.card {
width: 50%;
float: left;
background: #e5e5e5;
padding: 2em;
margin: 1em;
box-sizing: border-box;
cursor: pointer;
transition: all 300ms ease;
overflow: hidden;
position: relative;
}
.read {
color: white;
background: blue;
height: 40px;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
transform: translateY(100%);
transition: transform .2s;
}
.card:hover .read{
transform: translateY(0);
}
<div class="card">
<img src="https://prodimage.images-bn.com/pimages/9781338659511_p0_v1_s550x406.jpg">
<h2>Integer Sagittis</h2>
<p>Integer Sagittis</p>
<div class=read>
<p>Read more</p>
</div>
</div>
You cannot animate height and width, but you can animate height using transform: translateY.
The key to what I believe you desire is to create a three-Div structure: one outer div (.card), and two inner divs (.olayDiv and .imgDiv).
The outer div (.card) must be styled position:relative, and the inner divs must be position:absolute -- this causes the inner divs to sit on top of each other. You then use z-index to place .olayDiv on top of .imgDiv. (Note that you must make the outer div position:relative or the position:absolute will not work on the inner divs)
.card{
position:relative;
width: 350px;
height: 300px;
overflow: hidden;
border:1px solid #ccc;
}
.bothInnerDivs{
position: absolute;
left:0;
width:100%;
height:100%;
}
.imgDiv{
z-index: 0;
width:100%;
top:0;
}
.olayDiv{
z-index: 1;
top:0;
transform: translateY(88%);
transition: transform .5s ease-out;
color:white;
background:rgba(0,0,0,0.85);
}
.olayDiv:hover{
transform: translateY(0);
}
.blurb{
padding: 10px;
height:50%;
}
.imgDiv h2 {
padding-top: 1em;
}
.imgDiv img {
width: 275px;
height: 25em;
}
.imgDiv {
padding: 2em;
margin: 1em;
box-sizing: border-box;
cursor: pointer;
overflow: hidden;
}
.read {
color: white;
background: blue;
height: 40px;
}
.centerHeightAndWidth{
display: flex;
align-items:center;
justify-content:center;
}
p{padding:0;margin:0;}
<div class="card">
<div class="imgDiv bothInnerDivs">
<img src="https://prodimage.images-bn.com/pimages/9781338659511_p0_v1_s550x406.jpg">
<h2>Integer Sagittis</h2>
<p>Integer Sagittis</p>
</div>
<div class="olayDiv bothInnerDivs">
<div class="read centerHeightAndWidth"><p>Read more</p></div>
<div class="blurb">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="blurb">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. </div>
</div>
</div>
I have a example exercise with a Sidebar Navigation that is fixed left of the screen.
I said that the content-div should have a position of absolute to the body and also a padding-left with the width of the sidebar, so that i can center my content in the visible area (width without the sidebar).
Now when I try to add a media query that says "when the screen is smaller than 1000px the Sidebar should disappear and the the padding of the content area should go to 0 (so that it gets centered in the normal screen width area)" it doesnt work.
I'm a beginner in html and css
Here is my code:
body {
font-family: 'Oswald', sans-serif;
padding: 0;
margin: 0;
background-color: #35af7e;
}
#media screen and (max-width: 1000px) {
.Sidebar {
left: -10rem;
}
.body {
padding-left: 0;
padding: 0;
}
}
#flex {
display: flex;
}
/* MEDIA QUERY FIX: NAVIC ; BODY-paddingleft ; */
.NavIc {
left: 1rem;
top: 1rem;
height: 30px;
width: 30px;
background-color: red;
border-radius: 3px;
z-index: 4;
position: fixed;
cursor: pointer;
}
.NavIc:hover .Sidebar {
background-color: red;
}
.Sidebar {
position: fixed;
width: 10rem;
height: 100%;
background: #E9D758;
color: white;
z-index: 3;
display: flex;
flex-direction: column;
transition: 200ms ease-in-out;
}
.space {
flex-grow: 1;
width: auto;
}
.Nav {
list-style-type: none;
display: block;
width: 100%;
padding: 0;
font-size: 1.5rem;
z-index: 2;
flex-grow: 18;
}
ul li {
box-sizing: border-box;
padding: 0.7rem 0 0.7rem 1rem;
position: relative;
transition: 150ms ease-in-out;
}
ul li:hover {
background-color: white;
color: black;
transform: scale(1.07) translate(0.3rem);
cursor: pointer;
}
.footnotes {
flex-grow: 1;
box-sizing: border-box;
padding: 0 1rem 0 1rem;
}
hr {
border-style: solid;
color: white;
}
.body {
position: absolute;
width: 100%;
padding-left: 10rem;
box-sizing: border-box;
top: 0;
color: white;
transition: 200ms ease-in-out;
}
.mid {
position: relative;
width: 60%;
left: 50%;
transform: translate(-50%);
font-size: 1.5rem;
}
.img {
position: relative;
max-width: 500px;
height: auto;
left: 50%;
transform: translate(-50%);
transition: 200ms ease-in-out;
}
.Logo {
position: relative;
left: 50%;
transform: translate(-50%);
max-width: 100%;
height: auto;
padding: 5rem 0 5rem 0;
}
.mid > hr {
width: 80%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sidebar</title>
<link rel="stylesheet" style="text/css" href="sidebar.css">
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
</head>
<body>
<div class="NavIc">
</div>
<div class="Sidebar">
<div class="space">
</div>
<ul class="Nav">
<li>Home</li>
<li>Gallery</li>
<li>Our Team</li>
<li>Contact</li>
</ul>
<div class="footnotes">
<hr>
<p>blablabla<br>
All rights reserved</p>
<p>blablabla</p>
</div>
</div>
<div class="body">
<div class="mid">
<div class="img">
<img src="Logo.svg" alt="Logo" class="Logo">
</div>
<hr>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea.Commodo consequat.</p><p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.Sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor.</p><p>Incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</br>
<hr>
</div>
</div>
</body>
</html>
Because your .body rule in #media (max-width: 1000px) is being override. Use !important or learn some CSS specificity/precedence.
body {
font-family: 'Oswald', sans-serif;
padding: 0;
margin: 0;
background-color: #35af7e;
}
#media screen and (max-width: 1000px) {
.Sidebar {
left: -10rem;
}
.body {
padding-left: 0 !important;
padding: 0;
}
}
#flex {
display: flex;
}
/* MEDIA QUERY FIX: NAVIC ; BODY-paddingleft ; */
.NavIc {
left: 1rem;
top: 1rem;
height: 30px;
width: 30px;
background-color: red;
border-radius: 3px;
z-index: 4;
position: fixed;
cursor: pointer;
}
.NavIc:hover .Sidebar {
background-color: red;
}
.Sidebar {
position: fixed;
width: 10rem;
height: 100%;
background: #E9D758;
color: white;
z-index: 3;
display: flex;
flex-direction: column;
transition: 200ms ease-in-out;
}
.space {
flex-grow: 1;
width: auto;
}
.Nav {
list-style-type: none;
display: block;
width: 100%;
padding: 0;
font-size: 1.5rem;
z-index: 2;
flex-grow: 18;
}
ul li {
box-sizing: border-box;
padding: 0.7rem 0 0.7rem 1rem;
position: relative;
transition: 150ms ease-in-out;
}
ul li:hover {
background-color: white;
color: black;
transform: scale(1.07) translate(0.3rem);
cursor: pointer;
}
.footnotes {
flex-grow: 1;
box-sizing: border-box;
padding: 0 1rem 0 1rem;
}
hr {
border-style: solid;
color: white;
}
.body {
position: absolute;
width: 100%;
padding-left: 10rem;
box-sizing: border-box;
top: 0;
color: white;
transition: 200ms ease-in-out;
}
.mid {
position: relative;
width: 60%;
left: 50%;
transform: translate(-50%);
font-size: 1.5rem;
}
.img {
position: relative;
max-width: 500px;
height: auto;
left: 50%;
transform: translate(-50%);
transition: 200ms ease-in-out;
}
.Logo {
position: relative;
left: 50%;
transform: translate(-50%);
max-width: 100%;
height: auto;
padding: 5rem 0 5rem 0;
}
.mid > hr {
width: 80%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sidebar</title>
<link rel="stylesheet" style="text/css" href="sidebar.css">
<link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet">
</head>
<body>
<div class="NavIc">
</div>
<div class="Sidebar">
<div class="space">
</div>
<ul class="Nav">
<li>Home</li>
<li>Gallery</li>
<li>Our Team</li>
<li>Contact</li>
</ul>
<div class="footnotes">
<hr>
<p>blablabla<br>
All rights reserved</p>
<p>blablabla</p>
</div>
</div>
<div class="body">
<div class="mid">
<div class="img">
<img src="Logo.svg" alt="Logo" class="Logo">
</div>
<hr>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea.Commodo consequat.</p><p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.Sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor.</p><p>Incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</br>
<hr>
</div>
</div>
</body>
</html>
Inside your media query use display: none;to hide the sidebar and then set padding: 0px;of your content. that's it.
#media only screen and (max-width: 1000px) {
.Sidebar{
display: none;
}
.body{
display: block;
padding: 0px;
}
}