CSS blur a portion of background image - css

I have the following HTML/CSS code
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#image {
background-image:url(https://upload.wikimedia.org/wikipedia/commons/5/50/Montage_of_Toronto_7.jpg);
display:block;
width:100%;
height:500px;
position:relative;
background-size:cover;
}
#blur {
display:block;
position:absolute;
width: 300px;
height:300px;
top:50%;
left:50%;
transform:translate(-50%,-50%);
border-radius:150px;
-webkit-filter:blur(10px); filter: blur(10px); -moz-filter:blur(30px); -ms-filter: blur(10px);
}
</style>
</head>
<body>
<div id="image">
<div id="blur"></div>
</div>
</body>
</html>
I want the middle of the image to be blurred into a dot. If I change the background color of #blur to blue, I can see that it exists. But the circle blur isn't happening.
Any suggestions on how to get a blurred circle in the picture via CSS ?

Workaround / solution:
You'll have to apply a blur to the initial image to blur it, since you can't apply it to a specified spot, we'll just have to use an overlay- blur this and resize it. We can use your dot pretty easily for this, just add the following CSS to your current file:
#blur {
background-image: url(https://upload.wikimedia.org/wikipedia/commons/5/50/Montage_of_Toronto_7.jpg);
background-position: center center;
}
And the outcome would look like this:
<html>
<head>
<style type="text/css">
#image {
background-image:url(https://upload.wikimedia.org/wikipedia/commons/5/50/Montage_of_Toronto_7.jpg);
display:block;
width:500px;
height:500px;
position:relative;
}
#blur {
display:block;
position:absolute;
width: 300px;
height:300px;
top:50%;
left:50%;
background-image:url(https://upload.wikimedia.org/wikipedia/commons/5/50/Montage_of_Toronto_7.jpg);
background-position: center center;
transform:translate(-50%,-50%);
border-radius:150px;
-webkit-filter:blur(10px); filter: blur(10px); -moz-filter:blur(30px); -ms-filter: blur(10px);
}
</style>
</head>
<body>
<div id="image">
<div id="blur"></div>
</div>
</body>
</html>

you can use this code
body {
background: url('https://images.unsplash.com/photo-1486723312829-f32b4a25211b?dpr=2&auto=format&fit=crop&w=1500&h=1000&q=80&cs=tinysrgb&crop=&bg=') no-repeat center center fixed;
background-size: cover;
}
.blur {
background: url(https://images.unsplash.com/photo-1486723312829-f32b4a25211b?dpr=2&auto=format&fit=crop&w=1500&h=1000&q=80&cs=tinysrgb&crop=&bg=) no-repeat center center fixed;
background-size: cover;
overflow: hidden;
filter: blur(13px);
position: absolute;
height: 300px;
top: -50px;
left: -50px;
right: -50px;
bottom: -50px;
width: 300px;
margin: 0 auto;
border-radius: 100px;
}
.widget {
border: 5px solid rgba(255, 255, 255, .5);
height: 300px;
width: 300px;
border-radius: 100%;
overflow: hidden;
}
.center {
position: absolute;
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.text {
height: 300px;
width: 300px;
}
.text h1 {
text-align: center;
text-shadow: 1px 1px rgba(0, 0, 0, .1);
color: #ffffff;
margin-top: 100px;
font-family: 'Lora', serif;
font-weight: 700;
font-size: 38px;
}
.text p {
text-align: center;
color: #ffffff;
text-shadow: 1px 1px rgba(0, 0, 0, .1);
margin-top: 0px;
font-family: 'Lato', serif;
font-weight: 400;
font-size: 22px;
}
<div class="widget center">
<div class="blur"></div>
<div class="text center">
<h1 class="">Lorem ipsum</h1>
<p>sit amet ipsum dolor</p>
</div>
</div>

Related

CSS: Alternative min()

According to the size of the div, I want to set the background-position-x and the background-size.
Using only CSS without JS or JQuery, I use min() which works:
.test {
transition: all 0.5s;
background-image: url(./my-asset.svg);
background-repeat: no-repeat;
background-position-x: min(-50px, -100%);
background-position-y: center;
background-size: min(50px, 100%) 100%;
}
This works properly but only on recent browsers, but I have a Firefox target to v.68 and it is not compatible.
What could be the alternative without using JS or JQuery and only CSS ?
I reproduce what I would like to have in output using min(). Hover the red part to make it work:
body,
html {
height: 100%;
width: 100%;
margin: 5px;
}
#main {
display: flex;
flex-direction: row;
background-color: cyan;
}
.use-px {
width: 300px;
height: 300px;
border: solid 3px black;
}
.use-percentage {
margin-left: 200px;
width: 100px;
height: 300px;
border: solid 3px black;
}
.left-over-image {
width: 25%;
height: 100%;
transition: all 1s;
background-color: red;
background-image: url(https://www.w3schools.com/images/w3schools_green.jpg);
background-repeat: no-repeat;
background-position-x: min(-50px, -100%);
background-position-y: center;
background-size: min(50px, 100%) 100%;
}
.left-over-image:hover {
background-position: left;
}
<html>
<body>
<div id="main">
<div class="use-px">
<!-- It will use 50px, because 25% of 300px is 75px. -->
<div class="left-over-image"></div>
</div>
<div class="use-percentage">
<!-- It will use 100%, because 25% of 100px is 25px. -->
<div class="left-over-image"></div>
</div>
</div>
</body>
</html>
You can consider a trick using pseudo element.
Resize both examples to see that they behave the same:
.box {
height:100px;
width:100px;
border:2px solid;
resize:both;
overflow:hidden;
background:linear-gradient(red,blue) 0/50px 50px no-repeat;
background-position-x: min(4em, 100%);
}
.alt {
height:100px;
width:100px;
border:2px solid;
resize:both;
overflow:hidden;
position:relative;
z-index:0;
}
.alt::before {
content:"";
position:absolute;
background:inherit;
background:linear-gradient(red,blue) 0/50px 50px no-repeat;
background-position-x:100%;
max-width:calc(4em + 50px); /* 4em + width of background */
width:100%;
top:0;
bottom:0;
left:0;
z-index:-1;
}
<div class="box">
</div>
<div class="alt">
</div>
UPDATE
Based on your new code:
body,
html {
height: 100%;
width: 100%;
margin: 0;
overflow: hidden;
}
#main {
display: flex;
flex-direction: row;
background-color: cyan;
}
.use-px {
width: 300px;
height: 300px;
border: solid 1px black;
}
.use-percentage {
width: 100px;
height: 300px;
border: solid 1px black;
}
.left-over-image {
width: 25%;
height: 100%;
background-color: red;
position:relative;
overflow:hidden;
}
.left-over-image::before {
content:"";
position:absolute;
top:0;
bottom:0;
left:0;
width:100%;
max-width:50px;
background-image: url(https://www.w3schools.com/images/w3schools_green.jpg);
background-size: 100% 100%;
transform:translateX(-100%);
transition: all 1s;
}
.left-over-image:hover::before {
transform:translateX(0);
}
<div id="main">
<div class="use-px">
<!-- It will use 50px, because 25% of 300px is 75px. -->
<div class="left-over-image"></div>
</div>
<div class="use-percentage">
<!-- It will use 100%, because 25% of 100px is 25px. -->
<div class="left-over-image"></div>
</div>
</div>

mobile optimization CSS

So I am just starting out in FE and found a really cool parralex animation via CSS that I have applied to my site.
I am happy with the desktop, but on mobile I lose the text boxes for some of the slides.
I tried to add the #media to specify changes for mobile screen sizes, and it works ok on Pixel 3, but on Iphone it is still cutting off. I suspect it is something to do with the overflow - but I cannot seem to fix it. I have tried a couple if things, I am not starting to think I just need to do a mobile style sheet. As I am new to the game I thought I would post on here to see if there is a quick fix!
Thanks,
D
<html>
<head>
<title></title>
<style>
html {
height: 100%;
overflow: hidden;
}
body {
margin:0;
padding:0;
perspective: 1px;
transform-style: preserve-3d;
height: 100%;
overflow-y: scroll;
overflow-x: hidden;
font-family: 'Lora', serif;
}
h1 {
font-size: 250%
}
p {
font-size: 140%;
line-height: 150%;
color: #333;
}
.slide {
position: relative;
padding: 25vh 10%;
min-height: 100vh;
width: 100vw;
box-sizing: border-box;
box-shadow: 0 -1px 10px rgba(0, 0, 0, .7);
transform-style: inherit;
color: #fff;
text-shadow: 0 5px 5px #808080;
}
img {
position: absolute;
top: 50%;
left: 35%;
width: 320px;
height: 240px;
transform: translateZ(.25px) scale(.75) translateX(-94%) translateY(-100%) rotate(2deg);
padding: 10px;
border-radius: 5px;
background: rgba(240,230,220, .7);
box-shadow: 0 0 8px rgba(0, 0, 0, .7);
}
img:last-of-type {
transform: translateZ(.4px) scale(.6) translateX(-104%) translateY(-40%) rotate(-5deg);
}
.slide:before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
box-shadow: 0 0 8px 1px rgba(0, 0, 0, .7);
}
.title {
width: 50%;
padding: 3%;
border-radius: 5px;
background: rgba(240,230,220, .7);
box-shadow: 0 0 8px rgba(0, 0, 0, .7);
}
.slide:nth-child(2n) .title {
margin-left: 0;
margin-right: auto;
}
.slide:nth-child(2n+1) .title {
margin-left: auto;
margin-right: 0;
}
.slide, .slide:before {
background: 50% 50% / cover;
}
.header {
text-align: center;
font-size: 175%;
color: #fff;
text-shadow: 0 5px 5px #008000;
}
#title {
background-image: url("code1.jpg");
z-index:2;
}
#title h1 {
transform: translateZ(.25px) scale(.75);
transform-origin: 50% 100%;
color: #fff;
text-shadow: 0 5px 5px #008000;
}
#slide1:before {
background-image: url("code2.jpg");
transform: translateZ(-1px) scale(2);
}
#slide2 {
background-image: url("code3.jpg");
z-index:2;
}
#slide3:before {
background-image: url("dark.jpg");
transform: translateZ(-1px) scale(2);
}
#slide4 {
background: #222;
}
#media screen and (max-width: 1020px) {
#title, #slide1, #slide2, #slide3, #slide4 {
float: none;
width: auto;
overflow-y: scroll;
overflow-x: scroll;
}
}
</style>
</head>
<body>
<div id="title" class="slide header">
<h1>
</h1>
</div>
<div id="slide1" class="slide">
<div class="title">
<h1>About me</h1>
<p></p>
</div>
</div>
<div id="slide2" class="slide">
<div class="title">
<h1>Skill set</h1>
<p></p>
</div>
<img src="code1.jpg">
<img src="hype.jpg">
</div>
<div id="slide3" class="slide">
<div class="title">
<h1>Why choose me?</h1>
<p></p>
</div>
</div>
<div id="slide4" class="slide header">
<h1></h1>
<p></p>
</div>
</body>
</html>
You can set z-index for the title, and remember to set position to z-index work well
#media screen and (max-width: 1020px) {
.slide .title {
position: relative;
z-index: 5;
}
}

css shapes with text inside it

I need to create this kinda shape in the image below which contains text in it.
This is how I tried :
HTML
<div class="header-bottom">
<div class="blue-rectangle">
<p>sadasdasdasd</p>
</div>
<div class="blue-rectangle">
<p>dsasdasdasda</p>
</div>
</div>
CSS
.header-bottom{
position: absolute;
right:13%;
bottom:5%;
}
.blue-rectangle {
background-color: rgba(3,78,136,0.7);
padding: 10px 20px 10px 200px;
margin-bottom: 20px;
}
.blue-rectangle p{
color:white;
text-transform: uppercase;
font-size:18px;
}
i tried adding transform:skew but it skews both right, left and the text itself.
.shape{
text-align:center;
background-color:rgba(3,78,136,0.7);
width:200px;
height:60px;
line-height:60px;
color:white;
margin:20px auto;
position:relative;
}
.shape:before{
content:"";
width:0px;
height:0px;
border-top:60px solid rgba(3,78,136,0.7);
border-left:60px solid transparent;
position:absolute;
right:100%;
top:0px;
}
<div class="shape">
something something
</div>
<div class="shape">
something else
</div>
I like to use a :before pseudo class for this:
.blue-rectangle {
color:white;
text-transform: uppercase;
font-size:18px;
padding: 10px 20px 10px 200px;
background-color: rgba(3,78,136,0.7);
width: 200px;
position: relative;
margin-left: 50px;
}
.blue-rectangle:before {
content: "";
position: absolute;
border: 21px solid transparent;
border-top-color: rgba(3,78,136,0.7);
border-right-color: rgba(3,78,136,0.7);
right: 100%;
top: 0;
width: 0;
height: 0
}
<p class="blue-rectangle">sadasdasdasd</p>
Please try following code
.header-bottom {
position: absolute;
right: 13%;
bottom: 5%;
}
.blue-rectangle {
height: 60px;
background-color: rgba(3, 78, 136, 0.7);
padding: 10px 20px 10px 200px;
margin-bottom: 20px;
position: relative;
}
.blue-rectangle p {
color: white;
text-transform: uppercase;
font-size: 18px;
position: relative;
}
.blue-rectangle:before {
content: '';
width: 0;
height: 0;
border-top: 80px solid rgba(3, 78, 136, 0.7);
border-left: 80px solid transparent;
position: absolute;
top: 0;
right: 100%;
}
<div class="header-bottom">
<div class="blue-rectangle">
<p>sadasdasdasd</p>
</div>
<div class="blue-rectangle">
<p>dsasdasdasda</p>
</div>
</div>
for infos :
background gradient and background size can be used too :)
.shape{
text-align:center;
background:
linear-gradient(65deg , transparent 50%,rgba(3,78,136,0.7) 50%) left no-repeat,
linear-gradient(0deg , rgba(3,78,136,0.7),rgba(3,78,136,0.7)) 30px 0 no-repeat;
background-size:30px 100%, 100% 100%;
width:200px;
height:60px;
line-height:60px;
padding:0 20px;
color:white;
margin:20px auto;
position:relative;
}
body {
background:url(http://lorempixel.com/640/480);
background-size:cover;
}
<div class="shape">
sometext
</div>
<div class="shape">
something else
</div><div class="shape">
some more text
</div>
<div class="shape">
and so on n on
</div>
In your case, you can't use skew. Instead, you should add a rotated triangle on the left.
Try add:
.blue-rectangle:before {
content: "";
border-left: 78px solid transparent;
border-top: 78px solid rgba(3,78,136, 0.7);
position: absolute;
top: 0;
left: -78px;
opacity: 0.7;
}
You may do the rest of the tuning yourself.

Jumbotron center text vertically and horizontally

Having problem with jumbotron centering text horizontal and vertical..
how do i achieved this? i have tried vertical-align ang text align but
still not working.. help pls.
HTML CODE HERE
<html>
<head></head>
<body>
<section class="jumbotron-section-1">
<div class="jumbotron no-margin jumbotron-section-1-bg">
<div class="container-fluid introduction">
<h1 class="name">Full Name</h1>
<p>Some text here..</p>
Some text here..
</div>
</div>
</section>
</body
</html>
CSS CODE HERE
<style>
.jumbotron-section-1 {
padding-top: 70px !important;
}
.jumbotron-section-1-bg {
background: url('../img/banner-img/bg10.jpg') no-repeat center center;
height: 768px;
background-size:100% 100%;
background-attachment: ;
}
.introduction {
text-align: center;
vertical-align: middle;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.name {
font-family: "custom-headerfont",sans-serif;
}
.introduction p {
font-weight: bold;
}
</style>
This is what i did and it work
.jumbotron-section-1 {
padding-top: 70px !important;
}
.jumbotron-section-1-bg {
background: url('../img/banner-img/bg10.jpg') no-repeat center center;
height: 768px;
background-size:100% 100%;
background-attachment: ;
}
.introduction {
position: absolute;
left: 50%;
top: 50%;
bottom: auto;
right: auto;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
-o-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
text-align: center;
width: 100%;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.name {
font-family: "custom-headerfont",sans-serif;
}
.introduction p {
font-weight: bold;
}
<style>
.jumbotron-section-1 {
}
.jumbotron-section-1-bg {
background: url('../img/banner-img/bg10.jpg') no-repeat center center;
width: 100%;
height: 100%;
}
.introduction {
width:300px;
height:100px;
position:absolute;
left:50%;
top:50%;
margin:-100px 0 0 -150px;
text-align: center;
}
.name {
font-family:"custom-headerfont", sans-serif;
}
.introduction p {
font-weight: bold;
}
</style>

How to make one circle inside of another using CSS

I am trying to make one circle inside of another circle using css, but I am having an issue making it completely centered. I am close, but still not there. Any ideas?
<div id="content">
<h1>Test Circle</h1>
<div id="outer-circle">
<div id="inner-circle">
<span id="inside-content"></span>
</div>
</div>
</div>
Here is my CSS:
#outer-circle {
background: #385a94;
border-radius: 50%;
height:500px;
width:500px;
}
#inner-circle {
position: relative;
background: #a9aaab;
border-radius: 50%;
height:300px;
width:300px;
margin: 0px 0px 0px 100px;
}
Also, here is a fiddle:
http://jsfiddle.net/972SF/
Ta da!
Explained in the CSS comments:
#outer-circle {
background: #385a94;
border-radius: 50%;
height: 500px;
width: 500px;
position: relative;
/*
Child elements with absolute positioning will be
positioned relative to this div
*/
}
#inner-circle {
position: absolute;
background: #a9aaab;
border-radius: 50%;
height: 300px;
width: 300px;
/*
Put top edge and left edge in the center
*/
top: 50%;
left: 50%;
margin: -150px 0px 0px -150px;
/*
Offset the position correctly with
minus half of the width and minus half of the height
*/
}
<div id="outer-circle">
<div id="inner-circle">
</div>
</div>
You don't need extra elements in CSS3
You can do it all with one element and a box-shadow.
JSFiddle Demo.
CSS
#outer-circle {
background: #385a94;
border-radius: 50%;
height:300px;
width:300px;
position: relative;
box-shadow: 0 0 0 100px black;
margin:100px;
}
If you want to use only one div to add circle inside circle, then use box-shadow.
div {
border-radius: 50%;
box-shadow: 0px 0px 0px 10px red, 0px 0px 0px 20px green, 0px 0px 0px 30px yellow, 0px 0px 0px 40px pink;
width: 100px;
height:100px;
margin: 3em;
}
<div></div>
Solved this by using CSS transform property:
You can refer to this JS fiddle link for below output:
http://jsfiddle.net/suprabhasupi/74b1ptne/
div {
border-radius: 50%;
/* border: 1px solid red; */
}
.circle1 {
position: relative;
width: 300px;
height: 300px;
background-color: red;
}
.circle2 {
transform: translate(25%, 25%);
width: 200px;
height: 200px;
background-color: green;
}
.circle3 {
transform: translate(48%, 46%);
width: 100px;
height: 100px;
background-color: blue;
}
<div class="circle1">
<div class="circle2">
<div class="circle3">
</div>
</div>
</div>
Use position: relative on the outer circle, position:absolute on the inner circle, and set all offset to the same value. Let the automatic calculation of height and width handle the rest (JSFiddle):
#outer-circle {
position:relative;
background: #385a94;
border-radius: 50%;
height:500px;
width:500px;
}
#inner-circle {
position:absolute;
background: #a9aaab;
border-radius: 50%;
right: 100px;
left: 100px;
top: 100px;
bottom: 100px;
/* no margin, no width, they get automatically calculated*/
}
Seems that top is the only thing you need to alter -> http://jsfiddle.net/972SF/12/
#inner-circle {
position: relative;
background: #a9aaab;
border-radius: 50%;
height:300px;
width:300px;
top: 100px; /* <--- */
margin: 0px 0px 0px 100px;
}
Just use box-shadow to get the effect you want:
Demo in a fiddle: http://jsfiddle.net/972SF/16/
The html is reduced to:
<div id="content">
<h1>Test Circle</h1>
<div id="circle">
</div>
</div>
Css:
#circle {
margin: 10em auto;
background: #385a94;
border-radius: 50%;
height:200px;
width:200px;
-webkit-box-shadow: 1px 1px 0px 100px black;
-moz-box-shadow: 1px 1px 0px 100px black;
box-shadow: 1px 1px 0px 100px black;
}
its simple, easy, and makes sure that your circles are always perfectly positioned next to each other.
You can change the size of the circle by changing the 4th property ( 100px ) on box-shadow to what ever you want.
take a look at this fiddle
which calculates centering automatically
#outer-circle {
background: #385a94;
border-radius: 50%;
height:500px;
width:500px;
display:table-cell;
vertical-align:middle;
}
#inner-circle {
display:inline-block;
background: #a9aaab;
border-radius: 50%;
height:300px;
width:300px;
}
Here is an example of a circle with outer border.
HTML:
<div id="inner-circle"></div>
Styles:
#inner-circle {
background: #385a94;
border : 2px solid white;
border-radius: 50%;
height:30px;
width:30px;
position: relative;
box-shadow: 0 0 0 1px #cfd1d1;
}
See results:
JSFiddle
Try,
#inner-circle {
position: absolute;
background: #a9aaab;
border-radius: 50%;
height:300px;
width:300px;
margin: 15% 0px 0px 100px;
}
Here is ur Updated JSFIDDLE
See How I have positioned the Divs, Just border-radius should do the Job
.outer{width:500px;height:500px;background:#f00;border-radius:50%;position:relative;top:0;left:100;}
.inner{width:250px;height:250px;background:#000;border-radius:50%;position:absolute;top:125;left:125;}
<div class="outer">
<div class="inner">
</div>
</div>
DEMO
try to give the innercircle a top:50% and than margin-top: a nagative value from the half of the height of the innercircle.
http://jsfiddle.net/972SF/19/
SOLVED! Exactly the way you want:
DEMO: http://jsfiddle.net/aniruddha153/RLWua/
HTML:
<div id="content">
<div id="outer-circle">
<div id="inner-circle">
</div>
</div>
</div>
CSS:
#content {
position: relative;
width: 100%;
padding-bottom: 100%;
}
#outer-circle {
position: absolute;
width: 50%;
height: 50%;
background-color: #000000;
border-radius: 50%;
}
#inner-circle{
margin-top: 25%;
margin-left: 25%;
position: absolute;
width: 50%;
height: 50%;
background-color: #e5e5e5;
border-radius: 50%;
}
You can use the top and left property of CSS to center it.
body {
width: 100%
margin:0px;
text-align: center;
}
#content {
width: 500px;
margin-left: auto;
margin-right: auto;
}
#outer-circle {
background: #385a94;
border-radius: 50%;
height:200px;
width:200px;
}
#inner-circle {
position: relative;
background: #a9aaab;
border-radius: 50%;
height:100px;
width:100px;
top:50px;
left:50px;
}
<div id="content">
<h1>Test Circle</h1>
<div id="outer-circle">
<div id="inner-circle">
<span id="inside-content"></span>
</div>
</div>
</div>

Resources