Showing part of the box [duplicate] - html

This question already has answers here:
How to color part of a box
(6 answers)
Closed 1 year ago.
I'm trying to show only part of the entire box.
<div class="box">30%</div>
.box{
background : linear-gradient(to right, rgba(250,0,0,0),rgba(250, 0, 0, 1));
}
The box looks like this, and I want to make only 30% of the background of the box colored and the rest transparent. I'm not trying to minimize the box to 30% width. I want the box's width to stay 100% but show only 30% of the gradient background.

If you wanna do it with the css background property, here you go:
background: background: linear-gradient(270deg, #F00 0%, rgba(255, 0, 0, 0.473958) 70.00%, rgba(255, 0, 0, 0) 70.01%, rgba(255, 0, 0, 0) 100%);
This is how it'll look line in a white background:
Notice the "70%" standing right there, it's where you can control where in the dimension you want a color to start (in this case rgba(255, 0, 0, 0) at 70% from the right border)
You can read more about it at MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient()#gradient_with_multi-position_color_stops

If I understand you correctly, you are wanting to have the left 70% transparent and have the gradient show only for the last 30%. If this is what you want you need to add 70% to your first colour stop as follows:
#box1{
background : linear-gradient(to right, rgba(250,0,0,0) 70%,rgba(250, 0, 0, 1));
}
#box2{
background : linear-gradient(to left, red, orange 70%, rgba(250,0,0,0) 30%);
}
#box3{
background : linear-gradient(to right, red 0%, orange 30%, white 30% );
}
.box {
margin-top: 15px;
}
<div class="box" id="box1">30%</div>
<div class="box" id="box2">30%</div>
<div class="box" id="box3">30%</div>
It looks like the OP was looking for something similar to a rainbow progress bar. There are many examples available including this one here: Progress bar different colors

Youn Can acheive it by:
css gradient background generator
with ::before and ::after
with clippath
span{
color:blue;
}
.box{
height:100px;
background: rgb(255,255,255);
background: linear-gradient(90deg, rgba(255,255,255,1) 30%, rgba(255,0,0,1) 30%);
}
.box2{
margin-top:30px;
position:relative;
height:100px;
}
.box2::before{
content:"";
position:absolute;
background-color:#000;
left:0;
top:0;
height:100%;
width:30%;
z-index:-1;
}
.box3{
background-color:#000;
height:100px;
margin-top:15px;
clip-path: inset(0 70% 0 0);
}
.box4{
margin-top:15px;
position:relative;
height:100px;
background: red; /* For browsers that do not support gradients */
background: -webkit-linear-gradient(left, orange , yellow, green, cyan, blue, violet); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, orange, yellow, green, cyan, blue, violet); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, orange, yellow, green, cyan, blue, violet); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, orange , yellow, green, cyan, blue, violet); /* Standard syntax (must be last) */
}
.box4::before{
content:"";
position:absolute;
top:0;
right:0;
width:70%;
height:100%;
background-color:#fff;
}
<div class="box">
<span>content<span>
</div>
<div class="box2">
<span>content<span>
</div>
<div class="box3">
<span>width clip path</span>
</div>
<div class="box4">
<span>As per your comment</span>
</div>

Related

How do I make my navbar only a gradiented shadow

I am trying to create a navbar with a gradiented background as shown in the image below
How can I create the gradient in the red box in this image
This is a sample CSS class for using gradients.
#gradient {
height: 50px;
opacity: 0.2;
background-color: transparent;
background-image: linear-gradient( black, white);
}
You can tweak the opacity for shadows accordingly.
Your code:
div {
background-image: linear-gradient(black, white);
height:60px;
position:fixed;
top:0px;
width:100%;
border:2px solid black;
text-align:center;
}
There you go:
div {
background-image: linear-gradient(grey, white);
height:60px;
position:fixed;
top:0px;
width:100%;
border:2px solid black;
text-align:center;
}
<div><h1>My Youtube Channel</h1></div>
A completely working example!
You'll want to use linear-gradient.
background-image: linear-gradient(to bottom, rgba(0,0,0,1) 0, rgba(0,0,0,0) 100%);
This is rgba black full opacity (1) to rgba black 0 opacity. If you want it to be lighter you can set the first rgba to something like rgba(0,0,0,0.5), black half opacity (0.5).

CSS Three Tone Diagonal Background

I am trying to create a 3 color background with colors going diagonally.
I found a great example with colors i like here: Responsive Diagonal Two-Tone Backgrounds with CSS (Corner to Corner)
.btn {
background:#212531;
background: linear-gradient(to right bottom, #2f3441 50%, #212531 50%);
display:inline-block;
padding:0.75em 2.0em;
font-size:1.5em;
text-align:center;
margin:0.25em 0;
color:#ffffff;
font-weight:normal;
text-transform:uppercase;
font-family:sans-serif;
}
.btn:hover, .btn:focus {
background:#2d3d64;
background: linear-gradient(to right bottom, #415382 50%, #2d3d64 50%);
}
body { text-align:center; background:#e6e9f6; padding-top:1.0em; }
a { text-decoration:none; }
<a class="btn" href="#">Check Out My Background</a>
I want to modify this example to have a third color, going from the bottom left corner, diagonally up to the middle of the screen and then stopping there.
How can i achieve this?
You can try like below. Simply consider an extra gradient with a diagonal direction.
.box {
width:200px;
height:100px;
background:
linear-gradient(to bottom left ,transparent 50%,yellow 50.5%),
linear-gradient(to bottom right,red 50%,blue 50.5%);
}
<div class="box">
</div>
According to this example:
https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient
You can use something like that:
background: linear-gradient(217deg, rgba(255,0,0,.8), rgba(255,0,0,0) 70.71%),
linear-gradient(127deg, rgba(0,255,0,.8), rgba(0,255,0,0) 70.71%),
linear-gradient(336deg, rgba(0,0,255,.8), rgba(0,0,255,0) 70.71%);

How to put a div between two different backgrounds

I want to put a div between two different backgrounds.
It looks something like below image:
As you can see, the div placed in between two background, white and blue.
How can I achieve this?
You can use position:absolute and a negative margin-top on the div you want in the middle
Check this
You can use below code by applying to that div. In this code you can use two different colors to background that you want.
background: linear-gradient(bottom, #FFFFFF 50%, #008ED3 50%);
background: -o-linear-gradient(bottom, #FFFFFF 50%, #008ED3 50%);
background: -moz-linear-gradient(bottom, #FFFFFF 50%, #008ED3 50%);
background: -webkit-linear-gradient(bottom, #FFFFFF 50%, #008ED3 50%);
background: -ms-linear-gradient(bottom, #FFFFFF 50%, #008ED3 50%);
In above code do not remove any single line, because each line is for browser compatibility, each line code is for different browsers.
You can position your white div so that it stacks on top of the divs with blue and white background.
https://jsfiddle.net/z6ohochn/
#blue {
background: blue;
width:100%;
height:60px;
}
#white {
width:80%;a
height:50px;
background:white;
z-index:2;
position:relative;
top:-80px;
left:10%;
border-radius:5px;
}
#gray {
background: gray;
width:100%;
height:60px;
}

Bootstrap 3 sign glyphicon with white circle background

Problem
Is there any way to make a Bootstrap 3.2 sign glyph to have a white background? It is being displayed on a coloured background. I've got an example on bootply but it has a white trim that is annoying.
CSS
.glyph-white-background {
background-color:#FFFFFF;
border-radius: 50%;
}
I had a play with the bootply and there may well be better ways of doing this but for now I sorted it by placing an inner span inside the glyphicon element and positioning it so that its border does not overlap the parents.
<div class="header">
<span class="glyphicon glyphicon-exclamation-sign glyph-background">
<span class="inner"></span>
</span>
</div>
The CSS positions the inner to provide the red background for the icon only.
.header {
background-color:#3AA3CB;
font-size: x-large;
}
.glyph-background {
position:relative;
border-radius:50%;
color:#fff;
z-index:2;
}
.inner {
position:absolute;
top:2px;
left:2px;
right:2px;
bottom:2px;
border-radius:50%;
background-color:red;
z-index:-1;
}
Bootply
I followed #Duroth 's advice and it works just fine.
HTML
<span class="not-available-icon"><i class="fa fa-exclamation"></i> </span>
CSS
.not-available-icon {
background-color: #9D5A5B;
display: inline-block;
height: 25px;
width: 25px;
color: white;
border-radius: 50%;
font-size: 16px;
padding-left: 10px;
}
JS Fiddle Here
You can use any color in :
.glyph-white-background {
background-color: red;//Say red
border-radius: 50%;
}
You should specify white color for class .glyph-red
.glyph-red {
color: white;
}
See the screenshot:
http://www.bootply.com/IRTWifeP2u
I consider this absolute overkill for what you're trying to accomplish, but at least it seems to work.
Using a gradient editor, I generated an image with a radial gradient that drops from 100% to 0% opacity at around 67% / 68%, making the image fully transparent just before it hits the edge of the icon.
The following CSS should work for just about every circle icon:
.glyph-white-background {
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPHJhZGlhbEdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgY3g9IjUwJSIgY3k9IjUwJSIgcj0iNzUlIj4KICAgIDxzdG9wIG9mZnNldD0iMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogICAgPHN0b3Agb2Zmc2V0PSI2NyUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogICAgPHN0b3Agb2Zmc2V0PSI2OCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMCIvPgogICAgPHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjZmZmZmZmIiBzdG9wLW9wYWNpdHk9IjAiLz4KICA8L3JhZGlhbEdyYWRpZW50PgogIDxyZWN0IHg9Ii01MCIgeT0iLTUwIiB3aWR0aD0iMTAxIiBoZWlnaHQ9IjEwMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%, rgba(255,255,255,1) 67%, rgba(255,255,255,0) 68%, rgba(255,255,255,0) 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(255,255,255,1)), color-stop(67%,rgba(255,255,255,1)), color-stop(68%,rgba(255,255,255,0)), color-stop(100%,rgba(255,255,255,0)));
background: -webkit-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(255,255,255,1) 67%,rgba(255,255,255,0) 68%,rgba(255,255,255,0) 100%);
background: -o-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(255,255,255,1) 67%,rgba(255,255,255,0) 68%,rgba(255,255,255,0) 100%);
background: -ms-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(255,255,255,1) 67%,rgba(255,255,255,0) 68%,rgba(255,255,255,0) 100%);
background: radial-gradient(ellipse at center, rgba(255,255,255,1) 0%,rgba(255,255,255,1) 67%,rgba(255,255,255,0) 68%,rgba(255,255,255,0) 100%);
}
Ofcourse, do mind your cross-browser compatibility.

How to set the width of background-color of a div?

I have two divs with same background color. How can I set the width of background?
Expected result:
Here is HTML:
<div>
<span>100% width of background</span>
</div>
<div>
<span>75% width of background</span>
</div>
What I tried to do using CSS:
div {
background-color: #fc0;
margin: 2px;
}
div:last-child {
background-size: 75%;
}
jsFiddle, of course.
Is it posible to do this exept of setting width of a div?
You can use background gradients with hard stops. Here I'm using custom properties on each element to dynamically set the length value. The CSS rule uses a partial attribute selector to look for the custom property in the style attribute.
div {
background-color: #fc0;
margin: 2px;
}
div[style*="--bg-length"] {
background: linear-gradient(
to right,
#fc0 var(--bg-length), /* the end of the colored segment */
transparent var(--bg-length) /* the start of the transparent segment */
);
}
<div><span>100% width of background</span></div>
<div style="--bg-length: 300px"><span>60% width of background</span></div>
<div style="--bg-length: 85%"><span>85% width of background</span></div>
<div style="--bg-length: 70vw"><span>85% width of background</span></div>
You can't do it with a simple background-color, but you can do it with a CSS gradient.
background-color is always treated as a single plain colour for the entire element, but gradients are treated as images, and can be sized. You can also do other things with gradients, such as layering multiple gradients, which can't be done with a simple background-color.
I would use a 1px image as background something like background: url(1px.png) repeat-y; then you can set background-size:75%; as it's image now. Making life easier and less/simple code as well.
you can use gradient:
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzFlNTc5OSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjY5JSIgc3RvcC1jb2xvcj0iIzFlNTc5OSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjcwJSIgc3RvcC1jb2xvcj0iIzFlNTc5OSIgc3RvcC1vcGFjaXR5PSIwIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiMxZTU3OTkiIHN0b3Atb3BhY2l0eT0iMCIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(left, rgba(30,87,153,1) 0%, rgba(30,87,153,1) 69%, rgba(30,87,153,0) 70%, rgba(30,87,153,0) 100%);
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(30,87,153,1)), color-stop(69%,rgba(30,87,153,1)), color-stop(70%,rgba(30,87,153,0)), color-stop(100%,rgba(30,87,153,0)));
background: -webkit-linear-gradient(left, rgba(30,87,153,1) 0%,rgba(30,87,153,1) 69%,rgba(30,87,153,0) 70%,rgba(30,87,153,0) 100%);
background: -o-linear-gradient(left, rgba(30,87,153,1) 0%,rgba(30,87,153,1) 69%,rgba(30,87,153,0) 70%,rgba(30,87,153,0) 100%);
background: -ms-linear-gradient(left, rgba(30,87,153,1) 0%,rgba(30,87,153,1) 69%,rgba(30,87,153,0) 70%,rgba(30,87,153,0) 100%);
background: linear-gradient(to right, rgba(30,87,153,1) 0%,rgba(30,87,153,1) 69%,rgba(30,87,153,0) 70%,rgba(30,87,153,0) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#001e5799',GradientType=1 );
CSS gradient generator
jsfiddle
You should change your CSS to :
div {
background-color: #fc0;
margin: 2px;
}
div:last-child {
background-image: -webkit-linear-gradient(left, #fc0, #fc0 75%, transparent 75%, transparent 100%)
}