How can apply custom css to the background image - css

I've got this example from w3school.
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("paper.gif");
display: flex;
align-items: center;
background-size: 705px;
background-repeat: no-repeat;
background-position: 95% 50%;
}
</style>
</head>
<body>
<h1>The background-image Property</h1>
<p>Hello World!</p>
</body>
</html>
What I want to do is to add some border around the image which position has been changed by background-position property.
https://www.w3schools.com/cssref/tryit.asp?filename=trycss_background-image

Try this:
<!DOCTYPE html>
<html>
<head>
<style>
section{
position: relative;
}
div {
background-image: url("paper.gif");
display: flex;
align-items: center;
background-size: 705px;
background-repeat: no-repeat;
background-position: 95% 50%;
position: absolute;
height: 600px;
width: 700px;
border-bottom: solid;
border-left: solid;
top: 0;
right: 0;
}
</style>
</head>
<body>
<section>
<div><div/>
<section/>
</body>
</html>
It will look like this in the "Try It Editor" on W3Schools website:

First of all as you know you can add border; the property border is a shorthand it will apply a border to all sides, so go for border-bottom and border-left.
With this said you can use the :after selector to put any kind of styles or effects such a responsive animation, motion transitions, borders > glow borders or better yet borders with neon glow blurry effect.
If you are interested on going deep with these kind of animations i would suggest you to try a library specialized on animation, such as anime.js or framer-motion.

Related

Background image not displaying. Css problems

I am trying to figure out why I can't see the image.
I am trying to add an image in the <li class="logo">PufferFish Divers</li> line, but I just see a black space.
When I inspect it, it is there, but I cannot get to see it.
header .logo a {
background-image: url("https://www.dropbox.com/s/ie6qd07mbmonjs1/sea10%20copia.jpeg?dl=0") ;
background-size: 300px;
display: inline-block;
height: 80px;
width: 300px;
text-indent: -999999999px;
}
Here's a codepen link.
here is the code. you can try this out. and you can refer enter link description here here for more details.
<html>
<head>
<style>
body {
background-image: url("https://uccf62af6085e46bfa876477ddd6.previews.dropboxusercontent.com/p/thumb/ABP0IK4DkxiZRD-oqNgvuM_MQx2MKut92ZE3MOLBMM2_aHYJ1Oz_fFc8c8B-zQ0R6PWpG8SlVUKL-hDW8HukOeP_nXbuZvH1XDQpMMEpDEFZgc7He81YmTuC1hE1V953GsqDwB9mZoR22b1VrWVxf0gmDyU8wv1x05cMbY8JDDqayTLMS0-S0_3mf7ELwNXB-FEacQjlV3KmTw82mpj1rx_N-rN9V4gT7-284Zo-A3_cBQ0ursYlyJ563tPMvzed852kpQJ5vp9Dwpf1mkEh1_xZAizECUuPvDZGc39xweogbwP_2blHPFW6wsu1xoffpb7Z3PPNz4tb2-EEcgJaT3SdfFVjHzXSoB0e4hF3Dy9dpbNcdTzmhDVp5rt6YKtbMCqBP2WNepm_EVDWH_VH4kW5/p.jpeg?fv_content=true&size_mode=5");
background-color: #cccccc;
background-repeat: no-repeat;
background-size: 300px 100px;
}
</style>
</head>
<body>
<h1>The background-image Property</h1>
<p>Hello World!</p>
</body>
</html>
There is mistake in the image's url. It was just a letter, but made it impossible to reach.

How to achieve this blur effect with css

I'm trying to get this cloud-like/gaussian blue effect, but I can't quite get it. I've tried using drop shadows with the same background color but it's not exactly right. Anyone know how to do it?
The given image doesn’t look so much like a CSS drop shadow as mentioned in the question, more like an image put in an element on top of which is a div with something like a linear gradient, or even multiples of these, semi transparent.
This sort of thing
background-image: linear-gradient(to bottom right, rgba(0,0,0,0.5),rgba(255,255,255,0.5));
But more sophisticated. Playing around with tones and opacities and positioning is probably the only way to get exactly what is wanted, the good thing about linear gradients being they let you do that.
I'm using a pseudo-element of the .splash container, makes it smaller than it's parent. On that pseudo-element, I have a partially transparent background and a box-shadow.
I do need to place all children of said container on top of the pseudo-class.
As you can see, the background begin to fade before the edge of the parent element that contains all text.
section {
height: 200px;
display: flex;
justify-content: center;
align-items: center;
background-color: #121212
}
.splash {
--splash-background-color: rgba(255, 255, 255, 0.3);
--splash-background-size-decrement: 60px;
position: relative;
z-index: 2;
}
.splash > * {
position: relative;
z-index: 1;
}
.splash::before {
content: '';
position: absolute;
left: var(--splash-background-size-decrement);
right: var(--splash-background-size-decrement);
top: var(--splash-background-size-decrement);
bottom: var(--splash-background-size-decrement);
background-color: var(--splash-background-color);
box-shadow: 0px 0px 50px 60px var(--splash-background-color);
}
<section>
<div class="splash">
<h1>Some text here</h1>
<p>Some text here. Some text here</p>
<p>Some text here. Some text here</p>
</div>
<section>
You can achieve this using the SVG image. You can add SVG image in CSS file or you can add SVG code in HTML file. I am not able to attach SVG file here.
This is the final output.
<style>
body{
/*background-image: url("#"); Add background Image*/
background-repeat: no-repeat;
background-size: 100%;
display: flex;
height: 100vh;
justify-content: center;
align-items: center;
margin: 0 auto;
max-width: 800px;
max-height: 800px;
}
.container{
width: 800px;
height: 800px;
/*background-image: url(".svg");*/
/*or .svg code in html file*/
background-repeat: no-repeat;
}
</style>
<body>
<div class="container"></div>
</body>

I'm trying to fix an image to the grey background so when I scroll above the red div covers them up

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.parallax {
/* The image used */
background-image: url("grey.jpg");
z-index: 1;
position: relative;
/* Set a specific height */
min-height: 700px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
/*These are property I assigned to the dog image (was just experimenting with the z-index) */
.parallax img{
z-index: 2;
border: 2px solid black;
position: relative;
top: 10px;
background-attachment: fixed;
}
</style>
</head>
<body>
<p>Scroll Up and Down this page to see the parallax scrolling effect.</p>
<div class="parallax"><img src="dog.jpg" width="250px" height="250px"></div>
<div style="height:600px;background-color:red;font-size:36px;position:
relative; top: -220px; z-index: 3;">
</body>
</html>
The original code is different.
There is a red div I want it to float over the dog image that should be fixed to the grey background. The dog image and red div are floating together and I don't want that! I want just the red div to float over them. I tried experimenting with the z-index and stuff but all in vain.
I tried all the ways to accomplish that parallax kind of effect.
These are the links to the images used:
This is the image used
This is the grey background used.
You are trying to give the dog image a 'fixed' position using css:
.parallax img{
/*...*/
background-attachment: fixed;
}
Instead try to use position: fixed like this:
.parallax img{
/*...*/
position: fixed;
}

How to stick a div with background image to the top of the body that has padding-top?

I need a div with background image and this div must been stick to the top.
However, body has padding-top = 80px.
The problem is that body’s padding cuts 80px of the div’s background image and I see a white strap at the bottom of the page.
How to get rid of this white strap and see the whole div’s background image?
Here is an illustration of the problem:
<!DOCTYPE html>
<html>
<head>
<style>
body {
padding-top: 80px;
margin: 0;
}
.divider-div {
min-height: 250px;
background-image: url(https://c1.staticflickr.com/5/4095/4913282297_671ae41f57_b.jpg);
background-size: 100% 100%;
background-repeat: no-repeat;
background-attachment: fixed;
}
</style>
</head>
<body>
<div class="divider-div"></div>
</body>
</html>
Wow. I've found a solution by chance...
I need to add these lines to .divider-div style
top: 0;
position: fixed;

CSS background-position not working in Mobile Safari (iPhone/iPad)

I have an issue with background-position in mobile safari. It works fine on other desktop browsers, but not on iPhone or iPad.
body {
background-color: #000000;
background-image: url('images/background_top.png');
background-repeat: no-repeat;
background-position: center top;
overflow: auto;
padding: 0px;
margin: 0px;
font-family: "Arial";
}
#header {
width: 1030px;
height: 215px;
margin-left: auto;
margin-right: auto;
margin-top: 85px;
background-image: url('images/header.png');
}
#main-content {
width: 1000px;
height: auto;
margin-left: auto;
margin-right: auto;
padding-left: 15px;
padding-right: 15px;
padding-top: 15px;
padding-bottom: 15px;
background-image: url('images/content_bg.png');
background-repeat: repeat-y;
}
#footer {
width: 100%;
height: 343px;
background-image: url('images/background_bottom.png');
background-position: center;
background-repeat: no-repeat;
}
Both "background_top.png" and "background_bottom.png" are shifted too far to the left. I've googled around, and as far as I can tell, background-position IS supported in mobile safari. I've also tried every combination of keywords ("top", "center", etc.), px, and %. Any thoughts?
Thanks!
Update: here's the markup in the .html file, which displays the design & layout fine in other browsers: (I also updated the above css)
<html lang="en">
<head>
<title>Title</title>
<link rel="Stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="header"></div>
<div id="main-content"></div>
<div id="footer"></div>
</body>
</html>
Both background images are very wide (~2000px) so as to take up space on any sized browser.
P.S. I know that there's probably a few more efficient CSS shortcuts I could be using, but for now I like having the code organized like I have it for visibility.
The iPhone/Webkit browser cannot center align background images when placed in the body tag. The only way around this is to remove the background image from your body tag and use an additional DIV as a wrapper.
#wrapper {
background-color: #000000;
background-image: url('images/background_top.png');
background-repeat: no-repeat;
background-position: center top;
overflow: auto;
}
<html lang="en">
<head>
<title>Title</title>
<link rel="Stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="wrapper">
<div id="header"></div>
<div id="main-content"></div>
<div id="footer"></div>
</div>
</body>
</html>
It'll work with
background-position-x: 50%;
background-position-y: 0%;
and still add
background-position: center top;
for other browsers.
Apparently, when you "scroll" on an iPhone / iPad, you're not scrolling the page in the same way as you do in a desktop browser. What you're doing is more like moving the whole page within a viewport. (I'm sure someone will correct me if I'm using the wrong terminology here.)
This means that background-position: fixed is still "supported" but has no real effect, since the whole page is moving within the viewport rather than the page content scrolling within the page.
Create a wrapper ID to place in the body, then include the following CSS:
#background_wrap {
z-index: -1;
position: fixed;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-size: cover;
background-image: url('../images/compressed/background-mobile.png');
background-repeat: no-repeat;
background-attachment: scroll;
}
Just ensure that none of your content goes within the div otherwise the whole page will be fixed with no scrolling.
I have this problem and I'm addressing it by getting rid of my fixed footer using a separate style as mentioned here: How to target CSS for iPad but exclude Safari 4 desktop using a media query?

Resources