Transparent background from the grand-parent element - html

I am trying to apply to an element transparent background, but directly to the grand parent element. for example:
body {
background: linear-gradient( 45deg, rgba(5, 175, 240, 0.14), rgba(239, 77, 54, 0.14), rgba(243, 200, 57, 0.14)) fixed
}
.parent {
height: 100px;
width: 100px;
background: black;
}
.child {
height: 50px;
width: 50px;
background: // here, i want the background to reflect the body background
}
<div class="parent">
<div class="child"></div>
</div>

No need of span you can achieve this using clip-path CSS property
body {
background: linear-gradient( 45deg, rgba(5, 175, 240, 0.14), rgba(239, 77, 54, 0.14), rgba(243, 200, 57, 0.14)) fixed
}
div {
height: 100px;
width: 100px;
background: black;
clip-path: polygon(0% 50px, 50px 50px, 50px 0%, 85% 0%, 100% 0, 100% 15%, 100% 85%, 100% 100%, 85% 100%, 15% 100%, 0 100%, 0% 85%);
}
<div>
</div>

Use the same gradient for both elements
body {
--g: linear-gradient( 45deg, rgba(5, 175, 240, 0.14), rgba(239, 77, 54, 0.14), rgba(243, 200, 57, 0.14)) fixed;
background: var(--g)
}
.parent {
height: 100px;
width: 100px;
background: black;
}
.child {
height: 50px;
width: 50px;
background: var(--g);
background-color: #fff;
}
<div class="parent">
<div class="child"></div>
</div>

Related

How to center 4 absolute-divs (balls) in the middle of my screen?

I am trying to create a loading-screen effect for my current assignment.
It requires us to create a <div class="overlay"> with position: fixed. This funds as the background. Withing this div, there are 4 <div class="circle"> with position: absolute.
We have to center these using absolute-position and transform: translate. and each ball has a margin of 80px inbetween them
Here is an image of an example I try to re-create
I have managed so far to perfectly-center the balls, but cause of the position: absolute they all overlap. How can I make sure I can get all 4 balls like in the picture?
html {
scroll-behavior: smooth;
}
body {
z-index: 0;
background-color: #fff;
}
.overlay {
background-color: #0d1133;
position: fixed;
top: 0;
left: 0;
z-index: 1;
height: 100vh;
width: 100vw;
}
.circle {
width: 80px;
height: 80px;
background: #fff;
display: inline-block;
border-radius: 40px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#yellow {
background-color: linear-gradient(180deg, rgba(248, 255, 0, 1) 0%, rgba(255, 145, 0, 1) 50%, rgba(255, 145, 0, 1) 100%);
}
#red {
background: linear-gradient(180deg, rgba(255, 0, 215, 1) 0%, rgba(255, 0, 61, 1) 50%, rgba(255, 0, 0, 1) 100%);
}
#blue {
background: linear-gradient(180deg, rgba(0, 255, 243, 1) 0%, rgba(0, 224, 255, 1) 50%, rgba(0, 185, 255, 1) 100%);
}
#purple {
background: linear-gradient(180deg, rgba(255, 0, 241, 1) 0%, rgba(222, 0, 255, 1) 50%, rgba(157, 0, 255, 1) 100%);
}
<main>
<div class="overlay">
<div class="circle" id="yellow"></div>
<div class="circle" id="red"></div>
<div class="circle" id="blue"> </div>
<div class="circle" id="purple"></div>
</div>
</main>
You can wrap them inside a wrapper class and position that div absolute (like you did for each ball).
html {
scroll-behavior: smooth;
}
body {
z-index: 0;
background-color: #fff;
}
.overlay {
background-color: #0d1133;
position: fixed;
top: 0;
left: 0;
z-index: 1;
height: 100vh;
width: 100vw;
}
.wrapper {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%)
}
.circle {
width: 80px;
height: 80px;
background: #fff;
display: inline-block;
border-radius: 40px;
}
#yellow {
background-color: linear-gradient(180deg, rgba(248, 255, 0, 1) 0%, rgba(255, 145, 0, 1) 50%, rgba(255, 145, 0, 1) 100%);
}
#red {
background: linear-gradient(180deg, rgba(255, 0, 215, 1) 0%, rgba(255, 0, 61, 1) 50%, rgba(255, 0, 0, 1) 100%);
}
#blue {
background: linear-gradient(180deg, rgba(0, 255, 243, 1) 0%, rgba(0, 224, 255, 1) 50%, rgba(0, 185, 255, 1) 100%);
}
#purple {
background: linear-gradient(180deg, rgba(255, 0, 241, 1) 0%, rgba(222, 0, 255, 1) 50%, rgba(157, 0, 255, 1) 100%);
}
<main>
<div class="overlay">
<div class="wrapper">
<div class="circle" id="yellow"></div>
<div class="circle" id="red"></div>
<div class="circle" id="blue"> </div>
<div class="circle" id="purple"></div>
</div>
</div>
</main>
I would go with flexboxes, but if you need to animate them using transform: translate you can position them using:
transform: translate(calc(-50% + <OFFSET>px), -50%)
html {
scroll-behavior: smooth;
}
body {
z-index: 0;
background-color: #fff;
}
.overlay {
background-color: #0d1133;
position: fixed;
top: 0;
left: 0;
z-index: 1;
height: 100vh;
width: 100vw;
}
.circle {
width: 80px;
height: 80px;
background: #fff;
display: inline-block;
border-radius: 40px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#yellow {
background-color: linear-gradient(180deg, rgba(248, 255, 0, 1) 0%, rgba(255, 145, 0, 1) 50%, rgba(255, 145, 0, 1) 100%);
transform: translate(calc(-50% - 240px), -50%);
}
#red {
background: linear-gradient(180deg, rgba(255, 0, 215, 1) 0%, rgba(255, 0, 61, 1) 50%, rgba(255, 0, 0, 1) 100%);
transform: translate(calc(-50% - 80px), -50%);
}
#blue {
background: linear-gradient(180deg, rgba(0, 255, 243, 1) 0%, rgba(0, 224, 255, 1) 50%, rgba(0, 185, 255, 1) 100%);
transform: translate(calc(-50% + 80px), -50%);
}
#purple {
background: linear-gradient(180deg, rgba(255, 0, 241, 1) 0%, rgba(222, 0, 255, 1) 50%, rgba(157, 0, 255, 1) 100%);
transform: translate(calc(-50% + 240px), -50%);
}
<main>
<div class="overlay">
<div class="circle" id="yellow"></div>
<div class="circle" id="red"></div>
<div class="circle" id="blue"> </div>
<div class="circle" id="purple"></div>
</div>
</main>
You could use display: flex, aswell as align-items and justify content on the parent like so :
html {
scroll-behavior: smooth;
}
body {
z-index: 0;
background-color: #fff;
}
.overlay {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: center;
background-color: #0d1133;
position: fixed;
top: 0;
left: 0;
z-index: 1;
height: 100vh;
width: 100vw;
}
.circle {
width: 80px;
height: 80px;
background: #fff;
display: inline-block;
border-radius: 40px;
}
#yellow {
background-color: linear-gradient(180deg, rgba(248, 255, 0, 1) 0%, rgba(255, 145, 0, 1) 50%, rgba(255, 145, 0, 1) 100%);
}
#red {
background: linear-gradient(180deg, rgba(255, 0, 215, 1) 0%, rgba(255, 0, 61, 1) 50%, rgba(255, 0, 0, 1) 100%);
}
#blue {
background: linear-gradient(180deg, rgba(0, 255, 243, 1) 0%, rgba(0, 224, 255, 1) 50%, rgba(0, 185, 255, 1) 100%);
}
#purple {
background: linear-gradient(180deg, rgba(255, 0, 241, 1) 0%, rgba(222, 0, 255, 1) 50%, rgba(157, 0, 255, 1) 100%);
}
<main>
<div class="overlay">
<div class="circle" id="yellow"></div>
<div class="circle" id="red"></div>
<div class="circle" id="blue"> </div>
<div class="circle" id="purple"></div>
</div>
</main>
Add an absolutely-positioned div container around the circles, and centre this on the page.
Then put the circles inside it (no longer absolutely-positioned) and give them a margin.
html {
scroll-behavior: smooth;
}
body {
z-index: 0;
background-color: #fff;
}
.overlay {
background-color: #0d1133;
position: fixed;
top: 0;
left: 0;
z-index: 1;
height: 100vh;
width: 100vw;
}
.circles-container {
width: 100%;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.circle {
width: 30px;
height: 30px;
background: #fff;
margin: 30px;
display: inline-block;
border-radius: 40px;
transform: translate(-50%, -50%);
}
#yellow {
background-color: linear-gradient(180deg, rgba(248, 255, 0, 1) 0%, rgba(255, 145, 0, 1) 50%, rgba(255, 145, 0, 1) 100%);
}
#red {
background: linear-gradient(180deg, rgba(255, 0, 215, 1) 0%, rgba(255, 0, 61, 1) 50%, rgba(255, 0, 0, 1) 100%);
}
#blue {
background: linear-gradient(180deg, rgba(0, 255, 243, 1) 0%, rgba(0, 224, 255, 1) 50%, rgba(0, 185, 255, 1) 100%);
}
#purple {
background: linear-gradient(180deg, rgba(255, 0, 241, 1) 0%, rgba(222, 0, 255, 1) 50%, rgba(157, 0, 255, 1) 100%);
}
<main>
<div class="overlay">
<div class="circles-container">
<div class="circle" id="yellow"></div>
<div class="circle" id="red"></div>
<div class="circle" id="blue"> </div>
<div class="circle" id="purple"></div>
</div>
</div>
</main>
This is perfect and clean code using css flex
Html Code:
<div class="circles-container">
<div class="circle" id="red"></div>
<div class="circle" id="orange"></div>
<div class="circle" id="green"> </div>
<div class="circle" id="purple"></div>
</div>
</div>
Css Code:
.main-div{
width:100%;
height:-webkit-fill-available;
display:flex;
background: navy;
justify-content: center;
flex-direction: column;
align-items: center;
}
.circle{
width:10px;
height:10px;
border-radius:50px;
display:inline-block;
}
#red{
background:red
}
#orange{
background:orange;
}
#green{
background:green;
}
#purple{
background:purple;
}

Overflow wrap not being applied to text

Issue
I currently have a side menu that I have built using Angular and it works pretty well on my screen (4k resolution). Problem being on smaller screens the text in the menu doesn't wrap so it overflows the container div. I have tried applying overflow-wrap: break-word; to the text but that is not working.
Any assistance would be greatly appreciated.
You can see the issue below:
Code
HTML of the component:
<div class="sidebar animated fadeIn">
<div class="header">
<div style="display:block;margin-left:auto;margin-right:auto;width:100%;">
<img src="../../../assets/images/logo.svg" style="width:100%" />
</div>
</div>
<div class="spacer"></div>
<div class="menu-item" *ngFor="let item of items" (click)="goTo(item.path)">
<i class="material-icons">{{item.icon}}</i>
<h3 class="text">{{item.name}}</h3>
</div>
</div>
Styling of the component:
.sidebar {
position: absolute;
top: 0;
bottom: 0;
left: 0;
z-index: 2;
width: 10%;
background: rgba(191, 158, 69, 1);
background: -moz-linear-gradient(top, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
background: -webkit-gradient(
left top,
left bottom,
color-stop(0%, rgba(191, 158, 69, 1)),
color-stop(100%, rgba(250, 239, 210, 1))
);
background: -webkit-linear-gradient(bottom, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
background: -o-linear-gradient(bottom, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
background: -ms-linear-gradient(bottom, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
background: linear-gradient(to top, rgba(191, 158, 69, 1) 0%, rgba(250, 239, 210, 1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#bf9e45', endColorstr='#faefd2', GradientType=0 );
box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
}
.header {
width: 100%;
}
.spacer {
margin-top: 3em;
}
.menu-item {
border-top: 1px solid darkgray;
padding-left: 2em;
height: 3em;
display: flex;
align-items: center;
cursor: pointer;
}
.menu-item .text {
margin-left: auto;
margin-right: auto;
overflow-wrap: break-word;
}
Add this property word-break: break-all;
.menu-item .text {
margin-left: auto;
margin-right: auto;
/*overflow-wrap: break-word;*/
word-break: break-all;
}

CSS Background-image layer add by CSS

I have a DOM element:
<div style="background-image: url(layer1.png)">...</div>
I want to add next layer using CSS:
div {
background-image: url('layer2.png'),radial-gradient( rgba(255, 255, 255, 0.85) 0%, rgba(236, 245, 245, 0.19) 75%, rgba(236, 245, 245, 0) 100%);
}
As a result i need to have DIV with all 3 layers as a background image.
Is it possible by pure HTML5 CSS3?
Inline styling totally replaces the properties defined by CSS for that element.
What you can do is create a parent element and child elements as layers, then layer it with the help of z-index and then use opacity to give it some transparency.
HTML
<div class="layers">
<div class="layer1" style="opacity: 0.2; background-image: url(foo.png);"> </div>
<div class="layer2" style="opacity: 0.4;"></div>
<div class="layer3" style="opacity: 0.2;"></div>
</div>
CSS
.layers{
position:relative;
width: 100px;
height: 100px;
}
.layer1, .layer2, .layer3{
position:absolute;
top:0px;
left:0px;
width: 100%;
height: 100%;
}
.layer1{ background-color: red; z-index: 0;}
.layer2{ background-color: orange; z-index: -1;}
.layer3{ background-color: pink; z-index: -2; }
JsFiddle
No, it's not possible. What will happen:
Your div {} rule has lower priority than inline css, so your inline css background-image will overwrite previous rule, not be appended to it.
Solution:
Use child element or :before/:after to apply layer1.png
.wrapper {
height: 200px;
width: 300px;
background-image: radial-gradient( rgba(255, 255, 255, 0.85) 0%, rgba(236, 245, 245, 0.19) 75%, rgba(236, 245, 245, 0) 100%);
position: relative;
}
.wrapper div {
position: absolute;
left: 10%;
top: 10%;
width: 80%;
height: 80%;
}
body {
background-color: black;
}
<div class="wrapper"><div style="background-image: radial-gradient(rgba(0, 255, 0, 0.85) 10%, rgba(0, 245, 0, 0.19) 75%, rgba(0, 245, 0, 0) 90%);"></div></div>

Create a full width header with diagonal background color

What I'm going to explain is a little complicated, so I made an image hoping it could help us.
Here is the large image.
In the top part of the page there is an header. It must have some characteristics:
it have to be full width but...
its content (the logo and the menu) is wrapped in a centered div, 960px of width
these two points are simple: I create an header with a fixed height and a 100% width, then a div with 960px of width and margin 0 auto so that it's always centered.
Now it comes the difficulties:
the background color, as you can see, is transparent, in fact we see the photo under the header. And this transparency is not the same for all the header: the side in which I should locate the logo has a certain value of opacity, and the side of menu has another value. And, moreover, the two sides are separated by a diagonal line.
It seems to be easy, but I don't find a solution to set the background in the way it appears in the image without having problems.
Here is a pure CSS solution.
Update Version:
To implement full-width multiple colored header, I changed my mind and decided to use CSS3 Gradient, Nowadays all modern web browsers support linear-gradient, but can use a transparent image or SVG as fallback for old browsers.
HTML:
<div class="header">
<div class="wrapper">
<div class="left">Left</div>
<div class="right">right side</div>
</div>
</div>
CSS:
.header {
background: -webkit-linear-gradient(-20deg, rgba(230, 0, 200, 0.5), rgba(230, 0, 200, 0.5) 40%, rgba(200, 0, 200, 0.3) 40%, rgba(200, 0, 200, 0.3));
background: -moz-linear-gradient(-20deg, rgba(230, 0, 200, 0.5), rgba(230, 0, 200, 0.5) 40%, rgba(200, 0, 200, 0.3) 40%, rgba(200, 0, 200, 0.3));
background: -ms-linear-gradient(-20deg, rgba(230, 0, 200, 0.5), rgba(230, 0, 200, 0.5) 40%, rgba(200, 0, 200, 0.3) 40%, rgba(200, 0, 200, 0.3));
background: -o-linear-gradient(-20deg, rgba(230, 0, 200, 0.5), rgba(230, 0, 200, 0.5) 40%, rgba(200, 0, 200, 0.3) 40%, rgba(200, 0, 200, 0.3));
background: linear-gradient(110deg, rgba(230, 0, 200, 0.5), rgba(230, 0, 200, 0.5) 40%, rgba(200, 0, 200, 0.3) 40%, rgba(200, 0, 200, 0.3));
min-width: 960px;
width: 100%;
}
.wrapper {
width: 960px;
margin: 0 auto;
outline: 2px dashed green; /* Just for demo */
}
.left, .right {
height: 35px;
line-height: 35px;
}
.left {
float: left;
width: 350px;
}
.right {
text-align: right;
margin-left: 350px;
}
Here is the JSBin Demo.
Previous Answer:
I've used :before and :after pseudo-elements to implement the bevel corners. You can simply transparent image instead, if you want to support old IE versions.
CSS:
.left, .right {
position: relative;
height: 35px;
line-height: 35px;
}
.left {
float: left;
width: 200px;
background-color: rgba(255, 200, 0, .5);
}
.right {
background-color: rgba(255, 150, 0, .5);
margin-left: 225px;
}
.left:after {
content: ' ';
display: block;
border-style: solid;
border-color: rgba(255, 200, 0, .5) transparent transparent transparent;
border-width: 35px 25px 0 0;
width: 0;
height: 0;
position: absolute;
top: 0;
right: -25px;
}
.right:before {
content: ' ';
display: block;
border-style: solid;
border-color: transparent transparent rgba(255, 150, 0, .5) transparent;
border-width: 0 0 35px 25px;
width: 0;
height: 0;
position: absolute;
top: 0;
left: -25px;
}
JSBin Demo
The CSS color property can be used by rgba method.
background:rgba(RED,GREEN,BLUE,OPACITY);
For example if you want to make background red with an opacity of of 50% then you have to use the following code.
background:rgba(255,0,0,0.5);
Things you must know
the maximum value for color (red green or blue) is 255 while lowest value is 0.
The highest value for opacity is 1 while lowest is 0.

How to show blocks for progressbar using CSS

I have a div with 100% width on my page.
Now I need to show blocks into a <div> just like windows progressbar can anyone tell how I can create those blocks in the my div?
Looks like this:
I copied #Anshuman Dwibhashi answer, but I changed the background to a piece of the image you posted. Now you just increase or decrease the percentage width of .sub-block to change the load bar progress.
<div class="main" style="border:solid;background-color:white;width:500px;height:25px;">
<div class="sub-block" style="background:url('http://i.imgur.com/PRBmb4s.png');width:30%;height:25px;" ></div>
</div>
Like this
DEMO
CSS
.progress-striped .bar {
background-color: #149BDF;
background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-size: 40px 40px;
}
.progress .bar {
-moz-box-sizing: border-box;
background-color: #0E90D2;
background-image: linear-gradient(to bottom, #149BDF, #0480BE);
background-repeat: repeat-x;
box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.15) inset;
color: #FFFFFF;
float: left;
font-size: 12px;
height: 100%;
text-align: center;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
transition: width 0.6s ease 0s;
width: 0;
}
.progress {
background-color: #F7F7F7;
background-image: linear-gradient(to bottom, #F5F5F5, #F9F9F9);
background-repeat: repeat-x;
border-radius: 4px 4px 4px 4px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) inset;
height: 20px;
margin-bottom: 20px;
overflow: hidden;
}
.progress-striped .bar {
background-color: #149BDF;
background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
background-size: 40px 40px;
}
.progress-success.progress-striped .bar, .progress-striped .bar-success {
background-color: #62C462;
background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
}
Try this:
DEMO
CSS
.main {
border: solid;
background-color: white;
width: 500px;
height: 25px;
}
.sub-block {
background-color: green;
display:inline-block;
width: 20px;
height: 25px;
}
HTML
<div class="main" >
<div class="sub-block" ></div>
</div>
add more number of sub-blocks according to your need;
Create an image file of that Block and use it as a background for the progress inner element. Give the background repeat-x.
For instance:
background: url("Block.png") left top repeat-x transparent;
For further reading:
http://css-tricks.com/css3-progress-bars/
Progress Bar with HTML and CSS
Creating & Styling Progress Bar With HTML5
In your HTML
<div class="block-container">
<div class="sub-block" ></div>
<div class="sub-block" ></div>
<div class="sub-block" ></div>
.
.
.
</div>
In your css file
.block-container
{
background-color:white;
width: 500px;
height: 25px;
}
.sub-block {
background-color: green;
width: 20px;
height: 25px;
padding-left: 3px;
}
OR
<div class='fix size'>
<div style="width:100%;">
<div>
10 sub-div 10% each
</div>
</div>
</div>