html - CSS circle with inner circle and image -
i'm new css please bare me. i'm trying achieve following:
- a background circle smaller colored circle inside of it, must centered
- a small centered image inside of both circles
- all of these items needs placed in single div
i'm trying minimum amount of code. want avoid duplication as possible. believe of can achieved using before , after selectors, i'm not sure how done
here's have far:
css:
.grid-container { display: grid; grid: 100px / 100px; } .circle { border-radius: 50%; width: 100%; height: 100%; background-color: #e4e4e7; } .circle:before { content: ""; border-radius: 50%; width: 80%; height: 80%; top: 10%; left: 10%; background-color: blue; display: block; position: relative; } .image-one:before { content: url("https://stackoverflow.com/favicon.ico"); } .circle-01 { grid-column: 1 / 2; grid-row: 1 / 2; }
html:
<div class="grid-container"> <div class="circle-01 circle image-one"></div> </div>
i need structure whereby can change color of inner circle and/or image
example
<div class="grid-container"> <div class="circle-01 circle image-one yellow"></div> <div class="circle-01 circle image-two blue"></div> <div class="circle-01 circle image-three green"></div> </div>
thanks in advance assistance!
you can pseudo element this, putting pseudo element on top of main element , using borders , background-image. can use background color behind image if doesn't fill whole pseudo element (note no-repeat
, size , position settings background):
.x1 { width: 300px; height: 300px; position: relative; border-radius: 50%; border: 10px solid #22f; margin: 30px; background: yellow; } .x1:after { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 220px; height: 220px; border-radius: 50%; border: 6px solid #f22; background: #3d3 url(http://placehold.it/200x200/fa0/?text=this_is_an_image) center center no-repeat; background-size: 100px 100px; }
<div class="x1"></div>
note: orange square image, green color around background color, red circle border of pseudo element, yellow area background color of main element , blue circle border of main element. each of these white or transparent.
addition after additional question in comment:
you can change background-colors adding seperate classes. in following snippet added 2 classes div
, 1 affects background in main element , 1 affects background-color of pseudo element. in latter case have make sure use background-color
property, not background
in css rule - otherwise background-image disappear:
.x1 { width: 300px; height: 300px; position: relative; border-radius: 50%; border: 10px solid #22f; margin: 30px; background: yellow; } .x1:after { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 220px; height: 220px; border-radius: 50%; border: 6px solid #f22; background: #3d3 url(http://placehold.it/200x200/fa0/?text=this_is_an_image) center center no-repeat; background-size: 100px 100px; } .aqua-outer-bg { background: aqua; } .pink-inner-bg:after { background-color: pink; }
<div class="x1 aqua-outer-bg pink-inner-bg"></div>
note: original css rules remained unchanged, background colors overwritten additional classes.
one more addition after additional question in comment op on september 18th:
yes, can split in 2 classes did below (.x1a
, .x1b
). added both classes html tag , split css x1:after
2 rules, 1 .x1a:after
, 1 .x2a:after
.x1a { width: 300px; height: 300px; position: relative; border-radius: 50%; border: 10px solid #22f; margin: 30px; background: yellow; } .x1a:after { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 220px; height: 220px; background: #3d3 url(http://placehold.it/200x200/fa0/?text=this_is_an_image) center center no-repeat; background-size: 100px 100px; } .x1b:after { border-radius: 50%; border: 6px solid #f22; } .aqua-outer-bg { background: aqua; } .pink-inner-bg:after { background-color: pink; }
<div class="x1a x1b aqua-outer-bg pink-inner-bg"></div>
Comments
Post a Comment