I have the following overlapping divs:
#circle {
width: 150px;
height: 150px;
background-color: rgba(0, 0, 0, .3);
position: absolute;
border-radius: 100%;
margin-top: 30px;
}
#rect {
margin-left: 20px;
width: 100px;
height: 100px;
border-radius: 5px;
background-color: lightblue;
display: inline-block;
}
<div id='wrapper'>
<div id='circle'></div>
<div id='rect'></div>
</div>
I want to make the circle div only appear inside of the rectangle div, but I cannot put one inside the other and use overflow. How can this be achieved?
If it's only about visual, use the circle as background of the div:
#rect {
margin-left: 20px;
width: 100px;
height: 100px;
border-radius: 5px;
background:radial-gradient(circle 75px at 55px 105px, rgba(0, 0, 0, .3) 99%,transparent);
background-color: lightblue;
display: inline-block;
}
<div id='wrapper'>
<div id='rect'></div>
</div>
This isn't very practical, but the only way to do this without changing the markup is to crop it with the parent wrapper using position: relative and overflow: hidden on the parent. Adjust the location of the circle with top: 30px and left: -20px.
The parent would also need to set the rounded corners with
border-radius: 5px.
Of course if this is just a background, then it should be set with a background radial gradient on the rectangle.
Example
#wrapper {
position: relative;
display: inline-block;
margin: 30px;
border-radius: 5px;
overflow: hidden;
}
#circle {
width: 150px;
height: 150px;
background-color: rgba(0, 0, 0, .3);
position: absolute;
top: 30px;
left: -20px;
border-radius: 100%;
}
#rect {
width: 100px;
height: 100px;
background-color: lightblue;
}
<div id="wrapper">
<div id="circle"></div>
<div id="rect"></div>
</div>
Related
I have 3 layers div, image, div containing circles. I need to add black opacity background to image and add circles top of it. Circles suppose to show non black opacity applied image. Please see the image below
.
I tried to do this using box shadows but shadows kept stacking. I also looked for clip-path but needed black opacity background and clip-path did not allow me to that. Could you point me to correct css property?
.main {
width: 500px;
height: 55px;
position: absolute;
}
.circle-1{
width: 50px;
height: 50px;
border-radius: 50%;
border-style: solid;
border-width: 2px;
border-color: white;
background-color: rgba(0, 0, 0, 0);
box-shadow: 0 0 0 5000px rgba(0,0,0,.7);
}
.circle-2{
position: relative;
left: 150px;
width: 50px;
height: 50px;
border-radius: 50%;
border-style: solid;
border-width: 2px;
border-color: white;
background-color: rgba(0, 0, 0, 0);
box-shadow: 0 0 0 5000px rgba(0,0,0,.7);
}
.circle-3{
position: relative;
left: 150px;
width: 50px;
height: 50px;
border-radius: 50%;
border-style: solid;
border-width: 2px;
border-color: white;
background-color: rgba(0, 0, 0, 0);
box-shadow: 0 0 0 5000px rgba(0,0,0,.7);
}
<div class="main">
<div class="circle-1"/>
<div class="circle-2"/>
<div class="circle-3"/>
</div>
Add mix-blend-mode: overlay to the circles, and use filter: brightness(0.7) on the <img> to make the overlay.
.img-container {
position: relative;
width: 250px;
height: 250px;
margin: 0 auto;
}
.img-container img {
width: 100%;
height: 100%;
object-fit: cover;
filter: brightness(0.7);
}
.img-container .circle {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 90px;
height: 90px;
border-radius: 50%;
background: #fff;
mix-blend-mode: overlay;
}
<div class="img-container">
<img src="https://i.imgur.com/0hRbRO2.jpeg" alt="Egg Awarma" loading="lazy" />
<!-- image source: https://imgur.com/gallery/0hRbRO2 -->
<div class="circle"></div>
</div>
JS Fiddle demo.
i want to fit image with parent div (image-container) with corect ratio
.image-container{
height: 195px;
border-radius: 10px;
position: relative;
width: 482px;
width: 482px;
}
img{
border-top-left-radius: 10px;
border-top-right-radius: 10px;
object-fit: contain;
overflow:hidden
}
.gray-layer{
width: 482px;
height: 195px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
background-color: rgba(0, 0, 0, 0.4);
position: absolute;
top: 0;
}
<div class="image-container">
<img src="https://javadeveloperzone.com/wp-content/uploads/2019/02/JAVA-PARSE-LARGE-JSON-FILE-GSON-EXAMPLE-1024x488.png">
<div class="gray-layer">
</div>
</div>
my above code doesn't fit the image. please help me
First, you can use overflow: hidden on the parent div in order to have the rounded corner work for the contained img without having to specify them again.
Then, if you want the img to always fill out the entirety of the parent div, then you should set width and height to 100% and use object-fit: cover:
.image-container {
width: 482px;
height: 195px;
position: relative;
border-radius: 10px;
border: 1px dashed #ccc;
overflow: hidden;
}
img {
width: 100%;
height: 100%;
object-fit: cover;
}
<div class="image-container">
<img src="https://javadeveloperzone.com/wp-content/uploads/2019/02/JAVA-PARSE-LARGE-JSON-FILE-GSON-EXAMPLE-1024x488.png">
</div>
If you, however, want the image to just take on the parent's width (possibly growing out or leaving space at the bottom), then setting width to 100% should do the trick:
.image-container {
width: 482px;
height: 195px;
position: relative;
border-radius: 10px;
border: 1px dashed #ccc;
overflow: hidden;
}
img {
width: 100%;
}
<div class="image-container">
<img src="https://javadeveloperzone.com/wp-content/uploads/2019/02/JAVA-PARSE-LARGE-JSON-FILE-GSON-EXAMPLE-1024x488.png">
</div>
Note that I've omitted the .gray-layer for brevity and added a border to image-container to better see what's going on.
Yes. Add missing ending div and give height/width to 100% to get it working.
.image-container {
height: 195px;
border-radius: 10px;
position: relative;
width: 482px;
}
img {
height: 100%;
width: 100%;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.gray-layer {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
background-color: rgba(0, 0, 0, 0.4);
position: absolute;
height: 100%;
width: 100%;
top: 0;
}
<div class="image-container">
<img src="https://javadeveloperzone.com/wp-content/uploads/2019/02/JAVA-PARSE-LARGE-JSON-FILE-GSON-EXAMPLE-1024x488.png">
<div class="gray-layer"></div>
</div>
Currently I'm building a website, and I want a small contact form to overlap a backgroud image and a part of the div above and beneath...
I've read about positioning it as absolute and setting your positions for top and right, in my dreamweaver it looks like what I want, but when I open it in my browser (in dreamweaver it's a smaller screen) the container is placed way too far down on the page. has this something to do with screen sizes and responsive design? ps: I'm totally new so my code can be messy.
the html:
<div id="contact">
<div id="container"></div>
</div>
the css:
#container {
background-color: #FFFFFF;
width: 700px;
height: 500px;
margin: auto;
border-radius: 15px;
box-shadow: 0px 0px 70px 5px #000000;
position: absolute;
left: 30%;
top: 720%;
}
#container {
background-color: #FFFFFF;
width: 700px;
height: 500px;
display: block;
margin-left: auto;
margin-right: auto;
z-index:99999;
border-radius: 15px;
box-shadow: 0px 0px 70px 5px #000000;
position: absolute;
transform: translate(-50%);
}
<div class="contact">
<div class="container">
</div>
<div>
<style type="text/css">
.contact{
height: 100%;
width: 100%;
background: #EEE;
}
.container {
height: 200px;
width: 350px;
position: relative;
border: 1px solid #e3e312;
box-shadow: 3px 6px 26px #3A1314;
display: block;
margin-left: auto;
margin-right: auto;
top: 15%;
z-index: 999999;
}
</style>
Alright so I am trying to a basic overlay over an image but it seems that I am doing something wrong, instead of being width and height 100% of the IMG, it is width and height 100% of the entire page
HTML
<div id="main_BodyNews">
<img src="img/main.png" alt="mainNews" />
<div class="overflow-box"></div>
</div>
And the CSS
#main_BodyNews {
width: 50%;
height: 300px;
background-color: #F2C68C;
margin-top: 50px;
margin-left: 20px;
float: left;
border-radius: 5px;
border: 1px solid #F2C68C;
}
#main_BodyNews img {
width: 100%;
height: 100%;
border-radius: 5px;
background-color: 1px solid #F2C68C;
position: relative;
}
.overflow-box {
position:absolute;
top: 0px;
left: 0px;
bottom: 0px;
right: 0px;
background-color:rgba(255,255,0,0.5);
width: 100%;
height: 100%;
}
JS fiddle: https://jsfiddle.net/0utbjwo0/
you should add position: relative; to your absolute parent div
#main_BodyNews{
position: relative;
}
#main_BodyNews {
width: 50%;
height: 300px;
background-color: #F2C68C;
margin-top: 50px;
margin-left: 20px;
float: left;
border-radius: 5px;
border: 1px solid #F2C68C;
position: relative;
}
#main_BodyNews img {
width: 100%;
height: 100%;
border-radius: 5px;
background-color: 1px solid #F2C68C;
position: relative;
}
.overflow-box {
position:absolute;
top: 0px;
left: 0px;
bottom: 0px;
right: 0px;
background-color:rgba(255,255,0,0.5);
}
<div id="main_BodyNews">
<img src="img/main.png" alt="mainNews" />
<div class="overflow-box"></div>
</div>
You can use absolute. It's just that you are setting
width: 100%;
height: 100%;
Remove that and set your margin-top and margin left. You can set your width and height for the actually dimensions of your image. If you do this, you wont have to exactly keep your overlay div within your image div.
Here is an example of one I have made for my site.
#overlay {
margin-top: 60px;
margin-left: 88px;
height: 30px;
width: 85px;
position: absolute;
}
You can temporarily set a background-color for it so that you can get a good idea of where it is placed on your page. Then adjust your margins accordingly.
It's because the position: absolute has top, right, bottom, left value of 0. You don't need to specify the height and width. To make it resize on it's parent size. You need position: relative on parent element.
#main_BodyNews {
width: 50%;
height: 300px;
background-color: #F2C68C;
margin-top: 50px;
margin-left: 20px;
float: left;
border-radius: 5px;
border: 1px solid #F2C68C;
position: relative;
}
#main_BodyNews img {
width: 100%;
height: 100%;
border-radius: 5px;
background-color: 1px solid #F2C68C;
position: relative;
}
.overflow-box {
position: absolute;
top: 0px;
left: 0px;
bottom: 0px;
right: 0px;
background-color: rgba(255, 255, 0, 0.5);
}
<div id="main_BodyNews">
<img src="img/main.png" alt="mainNews" />
<div class="overflow-box"></div>
</div>
I cant find out how to achieve this effect, I'm familiar with parallax effect, but how can I make this "clip-path" effect or whatever is it called, where circles are transparent so image background can be seen through it?
You can use box-shadow and border-radius
body {
background: linear-gradient(blue, lightblue);
}
html, body {
height: 100%;
}
.base {
width: 200px;
height: 200px;
overflow: hidden;
margin: 30px;
}
.inner {
width: 100px;
height: 100px;
margin: 10px;
padding: 40px;
border-radius: 50%;
box-shadow: 0px 0px 0px 1000px white;
color: white;
font-size: 40px;
}
<div class="base">
<div class="inner">TEST</div>
</div>