Darken the background on a hover - html

again for my website, I want to make a hover on an div class, when you put your cursor on it, his scale gets bigger, I archieved this, now I want it to add like an '!important' cause as you can try here : http://stefanspeter.fr/about-test.html , the middle div for example get his text cuts on the side. I want to fix this problem first, then I would like to darken everything around this window, and to be fair I don't have a clue about how to make that happens.
I tried to add an !important tag, not knowing if it would work, and the way I did wasn't working actually.
Here is the code I'm using now :
.job {
background: #515151;
padding: 0.5rem;
border-bottom: #eece1a 5px solid;
}
.jobzoom:hover {
transform: scale(1.2);
font-size: 22px;
}
<div class="job jobzoom col-sm">
<h3>Alternance chez <a class="link-2 about-link" href="www.hb-digit.com" target="_blank">HB-Digit</a> et <a class="link-2 about-link" href="https://www.efficom-lille.fr/" target="_blank">Efficom</a></h3>
<hr class="about-hr" />
<h4 class="text-secondary">Août 2019 - Août 2020</h4>
<hr class="about-hr" />
<p>
Je suis actuellement en alternance chez HB-Digit sous l'école supérieur Efficom.<br /> Mes principales missions :
<ul>
<li>Développement de services web (Drupal8, php, bootstrap, twig, JS, jQuery...)</li>
<li>Gestion relation client via méthode Agile (Jira)</li>
<li>Etablissement et respect des cahiers des charges</li>
</ul>
</p>
Actual output : hover get the scale correctly
Expected : darken the background while it's hovering, stopping the cut by the others div surrounding it.
Thank you

I see the text being cutted on the side you already solved.
So, here is the solution for the dark background.
First, add a div inside .about-info element as the last one. Use .dark-element class to it:
<div class="about-info">
<!-- ... -->
<div class="dark-screen"></div>
</div>
Then, let's add CSS in order to create the effect.
You are going to make it fixed, fill the whole screen, invisible if no .job element is being hovering, but will appear when any element is hovered.
So we can use some properties like transition, visibility, point-events and opacity. Also, the selector ~ to select siblings (that are after the element, that's why we put it at the end) will be very useful:
.dark-screen {
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
visibility: hidden;
background: black;
pointer-events: none;
transition: 0.76s;
opacity: 0;
}
.job:hover ~ .dark-screen {
visibility: visible;
opacity: 0.6;
}

Related

How to make a background in a container and put the text in the middle of the photo? HTML/ CSS

I am learning HTML/ CSS and JS. I am making my first website and I have a problem. How can I change the background in the container under the pictures, to my color. On the internet I only find bg-secondary etc and I need for example #82b5cf.
I also have a question, I want to put the text in the middle of the picture, now it is under the photo and I can't do anything with it, for a test I changed the font and there is no reaction. Thank you very much for your help :)
main {
.aboutus-card-title {
font-size: 30px;
}
}
<main>
<section id="UAV" class="...."> //#82b5cf
<div class="container ">
<div class="row gx-4 ">
<div class="col-sm ">
<img class="uav-photo" src="img/introduction_1.jpg" alt="An orange four-engine drone hovers in the clear blue sky.">
<p class="aboutus-card-title">Introduction</p>
</div>
<div class="col-sm">
<img class="uav-photo" src="img/UAV_features_2.jpg" alt="An orange four-engine drone hovers in the clear blue sky.">
<p class="aboutus-card-title">Elements</p>
</div>
</div>
</div>
</section>
</main>
For your first question, it sounds like you're wanting a fallback color behind your image. Here's an example how to do this from: https://css-tricks.com/css-basics-using-fallback-colors/
header {
background-color: black;
background-image: url(plants.jpg);
color: white;
}
Basically you first create your fallback background-color, then overwrite it with your background-image. If the background-image doesn't load, the background-color will stay.
For your second question about the text with the .aboutus-card-title class, you have your CSS selectors messed up. This is a good source for learning about selectors: https://css-tricks.com/how-css-selectors-work/. If you want to select that class within main your selector should look like this:
main .aboutus-card-title{
font-size: 30px;
}
In this case, you can probably leave off main and just have this:
.aboutus-card-title{
font-size: 30px;
}
The only reason you would want to use the main selector here is if you wanted to style the .aboutus-card-title class differently if it's within main compared to somewhere else.
These are two questions. I'd split them into two separate posts, makes it a bit easier to search.
For changing the background you can use:
background-color: #82b5cf;
or
background: #82b5cf;
For the centering of text on an image, you could use a combination of position, top, left and transform:
.centered-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

CSS translateX(100%) on <input> in a parent with overflow causes 'flickering' and inconsistent width

What i'm trying to achieve
example of the closed version /
example of the opened version
At the top of the page in a 'fixed' header, i have a 'search' button next to a 'toggle' for the main menu. The header-search div (magnifying glass) is positioned next to the menu toggler (green). A form is currently positioned 'absolute' within the header to take up the full width of the header minus the padding on each side and its controls (search and toggler) as follows:
styles from header
.header {
top: 0;
left: 0;
width: 100%;
position: fixed;
background-color: var(--color-primary-700);
}
styles from header__aux
.header__aux {
display: flex;
column-gap: 1rem;
flex-flow: nowrap row;
}
.header-search {
display: block;
position: static;
}
.header-search__form {
top: 1.5rem;
height: 4rem;
overflow: hidden;
position: absolute;
left: var(--g-gutter);
width: calc(100% - (7rem + (var(--g-gutter)*2)));
}
.header-search__form-label {
top: -99.9rem;
left: -99.9rem;
color: inherit;
position: absolute;
}
.header-search__form.is-active
.header-search__form-input {
transform: translateX(0%);
}
.header-search__form-input {
width: 100%;
height: 4rem;
padding: 0 1.2em;
transform: translateX(100%);
border: .2rem solid #8097b3;
border-top-left-radius: 2rem;
border-bottom-left-radius: 2rem;
transition: transform 1s ease-in-out
background-color: var(--color-primary-700);
}
A input field inside this form is given 100% width and then using transform: translateX(100%) pushed completely to the right outside the overflow of the form (which retains it's width as set above). When a user presses the 'search' button a class is-active sets this transform: translateX(100%) to 0 and the input field should slide (from the right) to it's original position 100% of the width as seen in this image.
What this looks like in HTML
<header class="header section">
<div class="header__container container">
<a class="header__brand" href="#" aria-label="x">
<!-- svg brand -->
</a>
<div class="header__navs" id="headerNavs">
<div class="header__mask">
<ul id="headerMenu" class="header-menu">
</ul> <div class="header__langs header-langs">
Language
</div>
</div>
</div>
<div class="header__aux">
<div class="header__search header-search">
<button aria-label="Open of sluit het invoerveld voor een zoekopdracht" class="header-search__toggle" id="headerSearchToggle" aria-pressed="false" role="button" tabindex="0">
<i id="headerSearchIcon" class="far fa-search"></i>
</button>
<form class="header-search__form" action="/" id="headerSearchForm" role="search" method="get">
<label class="header-search__form-label" for="headerSearchInput">Zoeken</label>
<div class="header-search__form-slide">
<input placeholder="Zoeken …" required="" class="header-search__form-input" id="headerSearchInput" minlength="2" type="search" value="" name="s">
</div>
</form>
</div>
<a aria-label="" class="header__toggle header-toggle" aria-controls="headerNavs" aria-expanded="false" id="headerToggle" href="#">
Toggle
</a>
</div>
</div>
</header>
The problem
When opening the 'search' the input immediately jumps to the end of the animation which is seen in the example of the opened version (top) and then continues moving left, constantly correcting it's position back to what is seen in the image causing a weird 'flickering' effect usually in this position. Sliding the input 'back' to the right works perfectly.. What's even weirder is that it sometimes does work correctly for a few attempts once i've been on the page for a while. Then suddenly it breaks again.
What i've tried
Different types of browsers, including checking it on my own mobile device (not in the dev tools)
Giving the input the same fixed width as the parent
Removing a translateY on the parent and reverting to 'top' top position it in the vertical center
Adding 1 or multiple parents to the input to force it to inherit that width
As mentioned in a comment, adding transform:translateZ(0.1px); to force rendering using the GPU
What works, but i can't explain
Removing the overflow on the parent form element works and allows the animation to play smoothly, but that shows the input behind the element as seen in this image
I can think of some ways to make this look better, but i just really want to know what i'm missing. I believe i've done these types of simple animations 1000s of times now. A parent with overflow, hiding a child that's translated over.. or perhaps i'm mistaken. Hopefully someone can make sense of this - many thanks if you've taken the time to do so :)

Opacity on background image

As far as I know I can't directly change the opacity of a background image but using ::before and ::after doesn't seem to let my image show up. Am I doing it wrong?
HTML
flower window boxes
All of our products come in virtually any length up to 16 feet and two sizes. Our standard size boxes are designed to accommodate almost any flower. Our XL sizes are taller and deeper to provide more root space for plants making them the ideal sized window boxes for plants.
</div>
<div class="card-back">
<h2 class="click-here"><b>Visit Site</b></h2>
<div class="info">
<h2 class="info">Email:</h2>
<h2 class="info">Phone:</h2>
</div>
</div>
<!-- Content -->
<div class="all-content">
<h1>Contrary to popular belief</h1>
</div>
</li>
Current CSS
.content li:nth-child(1) .card-back{
background-image:url(../images/sponsor-imgs/Cellular%20PVC%20Columns-Kingston-1.jpg);
width: 100%;}
What I've tried
.backimg::after {
background-image:url(../images/backimg/wide.png);
opacity: 0.5;
}
.backimg::before{
background-image:url(../images/backimg/wide.png);
opacity: 0.5;
}
div::after {
opacity: 0.5;
}
On a side not i know i can simply make the images themselves transparent, but i feel like a code to do it much more useful in the long run. thanks in advance.
::before and ::after require a content property. You can set it to an empty string but it must be included.
In most cases you also need to define a display property and assign some dimensions to the element (unless you are using something like position: absolute; top: 0; bottom: 0; left: 0; right: 0; - in which case, you don't).
.backimg {
background: red;
}
.backimg::after {
content: "";
display: block;
width: 200px;
height: 200px;
background-image: url(http://placehold.it/200x200);
opacity: 0.5;
}
<div class="backimg"></div>
You are missing the .backimg class in your html.
Dont use double :: and add content and display properties to after. Also some dimensions wouldnt hourt (width,height)
.class:after{
Cintent:"";
Display:block; // change as you see fit
}

How to highlight a div with children (with partial opacity layer?) Like Yahoo mail, see pic

In Yahoo mail, when you are writing an email and you drag a file onto the page and hover, the message area becomes highlighted. It can be seen here:
The part of this that I don't get is how to have the blue area appear with partial opacity over the things under it that are normally visible.
With:
#blueBox {
background-color: #FFD090;
opacity: 0.0;
}
If the msgContent is a child of blueBox:
<div id='msgBox'>
<div id='blueBox'>
<div id='msgContent'>
... all the message contents, buttons, etc.
</div>
</div>
</div>
and when msgBox is hovered I increase blueBox opacity from 0 to say 0.6, the blueBox will show but the msgContent div is hidden until the hover event. It should be visible always.
If the msgContent div is not a child of blueBox, then the blueBox doesn't cover it.
I've tried rgba (http://jsfiddle.net/mkasson/nJcxQ/19/) like here on SO, but it doesn't cover over the child elements.
Couldn't do my usual watching/inspecting via browser's webdev tools because focus was never on the browser while dragging the file onto it.
Thanks!
Here is how I would go about this,
(What the problem is, you are using the parents background. You can't make the parents background go over it's content, that is not what a background does. It merely sites behind everything it is containing and acts as a background.)
html,
<div class="messageContent">
<span class="overlay"></span>
<p>Darn fanatically far and tarantula jeepers meek a secret much so hence underneath monogamously interwove apart gosh spilled far where and badger.</p>
This is a link
</div>
css,
.messageContent {
color: #000;
position: relative;
height: 100%;
width: 100%;
}
.overlay {
position: absolute;
top: 0;
left: 0;
background: lightBlue;
opacity: 0;
height: 100%;
width: 100%;
display: block;
z-index: 100;
}
.messageContent:hover .overlay {
opacity: 0.6;
}
What I am doing is placing an absolute span tag inside of the parent to act as the color overlay. When the parent is hovered the overlay child will become active by increasing it's opacity.
JSFIDDLE
Here's how I would do it.
<div id='msgBox'>
<div id='blueBox'>
</div>
<div id='msgContent'>
... all the message contents, buttons, etc.
</div>
</div>
CSS
#blueBox {
background-color: #FFD090;
opacity: 0.0;
position: absolute;
top: 0;
left: 0;
}
jQuery
$("#msgBox").hover(function(){
$("#blueBox").css({top:$(this).css("top")}).height($(this).outerHeight()).width($(this).outerWidth()).animate({opacity:0.6});
},function(){
$("#blueBox").animate({opacity:0}).height(0).width(0);
});
http://jsfiddle.net/54cx7/2/
The problem is that since content is a child of bluebox, then it inherits the 0 opacity.

How to make css opacity property not to be inherited from parent div´s?

I want a black bar behind a png image, and i want the black bar behind the image to have opacity. When I apply opacity to the black bar, his child element (the png image) inherits this opacity. I dont want this to happen.
The site is www.tomasfleiderman.com.ar , where it says "work for money, design for love" I want a black bar behind with opacity.
The code is the following:
<style type="text/css">
p {
font-size:40px;
color: white;
}
#caja
{
}
#fondofrase
{
}
</style>
<!--
<p>Work for money design for love</p>
-->
<div id="fondofrase">
<div id="caja">
<div>
<img src="http://www.tomasfleiderman.com.ar/1.png" alt="Texto" height="60%" width="60%"/>
</div>
</div>
</div>
Thanks
You can do this with a semi transparent background color: http://jsfiddle.net/alessandro_pezzato/LWh75/
background: rgba(0,0,0,0.8);
You can't do that, at least not easily. Child elements have the same maximum opacity as the parent, so a child image can only have an opacity of, say, '0.6' if the parent has an opacity of '0.6'. You could, though, use some absolute positioning techniques to layer the div and the img on top of each other as sibling elements rather than parent-child elements.
<style>
#positioner {
position: relative;
}
#theText,
#theImage {
position: absolute;
top: 0;
left: 0;
}
</style>
<div id="positioner">
<p id="theText">Work for money design for love</p>
<img id="theImage" />
</div>
​
You could try setting this style on the surrounding <div>-tag:
background: rgba(0, 0, 0, .5);
However, the browser support of rgba is not perfect, and definitely something you should consider before going with this solution. It tends to break in IE versions below 9 (see link: http://css-tricks.com/rgba-browser-support/).