I have an issue with CSS.
I have a gradient, with more than one instruction to make it compatible with any browser.
background: no-repeat 20px center url("./img/pc.png"), -webkit-gradient(linear, left top, left bottom, from(#000000), to(#111111));
background: no-repeat 20px center url("./img/pc.png"), -webkit-linear-gradient(top, #000000, #111111);
background: no-repeat 20px center url("./img/pc.png"), -moz-linear-gradient(top, #000000, #111111);
background: no-repeat 20px center url("./img/pc.png"), -ms-linear-gradient(top, #000000, #111111);
background: no-repeat 20px center url("./img/pc.png"), -o-linear-gradient(top, #000000, #111111);
background: no-repeat 20px center url("./img/pc.png"), linear-gradient(to bottom, #000000, #111111);
As you can see, there is also an image for the background. Now, imagine if this image was inline. It would be an enormous waste of space to copy and paste it many times.
Is there a way to do sometning like this:
background: no-repeat 20px center url("./img/pc.png");
background: linear-gradient(to bottom, #000000, #111111);
But without overwriting (and destroying) the first property (image) with the second call (gradient)?
Thanks
If you don't want to repeat yourself use CSS variable:
:root {
--image:url("https://lorempixel.com/400/200/") center/100px no-repeat
}
.box {
height:200px;
background: var(--image), -webkit-gradient(linear, left top, left bottom, from(#000000), to(#111111));
background: var(--image), -webkit-linear-gradient(top, #000000, #111111);
background: var(--image), -moz-linear-gradient(top, #000000, #111111);
background: var(--image), -ms-linear-gradient(top, #000000, #111111);
background: var(--image), -o-linear-gradient(top, #000000, #111111);
background: var(--image), linear-gradient(to bottom, #000000, #111111);
}
<div class="box">
</div>
<div class="box" style="--image:url(https://lorempixel.com/400/400/) center/100px no-repeat ">
</div>
Use an :after psuedo-element to add the gradient on top the image background.
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
div {
width: 100%;
height: 100%;
background: no-repeat center center url(http://via.placeholder.com/350x150);
position: relative;
}
div:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to bottom, transparent, #111111);
}
<div></div>
Both linear-gradient and url affect the background-image, so no, you cannot use those two in conjunction; the second one would overwrite the first.
When you combine these two rules in the following shorthand order:
background: no-repeat 20px center url("./img/pc.png");
background: linear-gradient(to bottom, #000000, #111111);
Only the background-image of the second rule gets applied; the other rules from the first shorthand rule get ignored:
background-image: linear-gradient(rgb(0, 0, 0), rgb(17, 17, 17));
background-position-x: initial;
background-position-y: initial;
background-repeat-x: initial;
background-repeat-y: initial;
However, you can cause these additional rules to apply by specifying the gradient as the background-image manually:
background-image: url(./img/pc.png); /* Only rule to get overriden */
background-image: linear-gradient(rgb(0, 0, 0), rgb(17, 17, 17));
background-position-x: 20px;
background-position-y: center;
background-repeat-x: no-repeat;
background-repeat-y: no-repeat;
This way your background-position-x, background-position-y, background-repeat-x and background-repeat-y rules can be applied in conjunction with your gradient... though it is impossible to have both of your background-url rules apply to the same element at the same time.
To have both the image and the gradient show up, I would recommend making use of two elements positioned on top of each other with position: absolute, and applying one background-image to each. The gradient would go on top, and be transparent so that the background image can be seen.
This can be seen in the following:
div {
width: 100px;
height: 100px;
position: absolute;
}
.background {
background-image: url("http://placehold.it/100");
}
.gradient {
background-image: linear-gradient(to bottom, transparent, #111111);
}
<div class="background"></div>
<div class="gradient"></div>
Related
There are four lines over the background. They are visible in overall sections but not over images.
How to make this?
It is as easy as this
body{
background: linear-gradient(90deg, #eee 1%, transparent 1%) 1px 0, #fff;
background-size: 200px 1px;
}
DEMO: https://codepen.io/anon/pen/VMzwNw
These and many other backgrounds can be generated using this site -> http://lea.verou.me/css3patterns/#stairs
You can use CSS linear gradients and multiple backgrounds to achieve this. Here's an example:
div {
height: 100px;
background-color: transparent;
background-size: 25% 100%;
background-repeat: repeat-x;
background-image: linear-gradient(to right, black 1px, transparent 1px);
background-position: 12.5%;
}
<div>
</div>
The gradient draws a vertical line, whereas background-size, background-position and background-repeat combined make the vertical line repeat.
Here's an example with a background image and the vertical lines:
div {
height: 100px;
background-color: transparent;
background-size: 25% 100%, cover;
background-repeat: repeat-x, no-repeat;
background-image: linear-gradient(to right, black 1px, transparent 1px), url(http://lorempixel.com/400/200/);
background-position: 12.5%, center;
}
<div>
</div>
I want to create the background image of the attached div element with CSS (or SVG).
div.target {
background-image: linear-gradient(
to right bottom,
transparent 50%,
#00BCD4 50%
);
Background image of the div element I want to create with CSS (or SVG)
We can do this using multiple background image gradients like in the below snippet. The darker shade is assigned as the background color to the element. Then two background image layers created using gradients are placed in such a way that they produce the desired effect. Adding a partially transparent layer of white color above the darker shade will produce a lighter shade.
The background-size of the second layer should be smaller and its background-position should be at the left-bottom side of the element.
div {
height: 200px;
background-color: rgb(20,203,194);
background-image: linear-gradient(to top left, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 50%), linear-gradient(to top right, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) 50%);
background-size: 100% 100%, 50px 50px;
background-position: left top, left bottom;
background-repeat: no-repeat;
}
<div></div>
Angled CSS gradients are known to produce slightly jagged (or uneven or rough) edges and that can be avoided by offsetting the color stop point a bit like in the below demo.
div {
height: 200px;
background-color: rgb(20,203,194);
background-image: linear-gradient(to top left, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) calc(50% + 1px)), linear-gradient(to top right, rgba(255,255,255,0.25) 50%, rgba(255,255,255,0) calc(50% + 1px));
background-size: 100% 100%, 50px 50px;
background-position: left top, left bottom;
background-repeat: no-repeat;
}
<div></div>
You can do this with :before and :after pseudo elements.
div {
position: relative;
width: 500px;
height: 100px;
background: #0BC7BE;
}
div:after {
position: absolute;
border-style: solid;
border-width: 0 0 100px 500px;
border-color: transparent transparent rgba(255, 255, 255, 0.3) transparent;
right: 0;
top: 0;
content: "";
}
div:before {
position: absolute;
border-style: solid;
border-width: 50px 0 0 70px;
border-color: transparent transparent transparent rgba(255, 255, 255, 0.3);
left: 0;
bottom: 0;
content: "";
}
<div></div>
Im creating a website for college and Im not sure how to stop text from overlapping when I make the web browser smaller. This is what I mean:
(not overlapping)
(overlapping)
Here is my jsfiddle: (http://jsfiddle.net/RC4Ar/)
.words {
font-family:apple;
font-size:20px;
max-width:800px;
height:190px;
margin-top:10px;
margin-left:42%;
}
Thanks in advance!
Assuming you are adding the words class to the paragraph tags (without your html, we can only guess), you simply need to remove the height declaration.
.words {
font-family: apple;
font-size: 20px;
max-width: 800px;
margin-top: 10px;
margin-left: 42%; }
For your fiddle example, I would change the title_bar to have a min height instead of a fixed height. This will allow it to be responsive instead of overlapping over the following text.
#title_bar {
margin-top:78px;
left:-17px;
width:101.5%;
min-height:30px;
background:blue;
position:relative;
top:-70px;
z-index:3;
border: 3px rgba(255, 105, 180, 1) solid;
background-image: -webkit-gradient(linear, right bottom, right top, color-stop(0, #5977FF), color-stop(1, #59C5FF));
background-image: -o-linear-gradient(top, #5977FF 0%, #59C5FF 100%);
background-image: -moz-linear-gradient(top, #5977FF 0%, #59C5FF 100%);
background-image: -webkit-linear-gradient(top, #5977FF 0%, #59C5FF 100%);
background-image: -ms-linear-gradient(top, #5977FF 0%, #59C5FF 100%);
background-image: linear-gradient(to top, #5977FF 0%, #59C5FF 100%);
}
Fiddle
The end result should look like this:
Button Comp
My button, with the image deleted, correctly displays my radial gradient perfectly (fills up the container completely). Once I add the image to the HTML, my gradient gets lost.
The image only takes up about 135px (from the top) leaving about 70px at the bottom of the container. I want the gradient to show inside this 70px area. For some reason, this area displays as a white background.
Basically let's say I have a container that has a height of 500px and is filled completely with a radial gradient. I place an image and position it center, top. the image has a height of 250px. The container should display the image in the upper half and the gradient in the lower half. Is this far fetched or what?
NOTE: With these classes below, the .sm and .lg are only in place to change the button size based on the number of buttons on my page.
Here's my button HTML:
`<div class="imgButton <?php echo $buttonSizeClass; ?>" style="background:transparent url(<?php echo $answer["image"]; ?>) no-repeat; background-size: 100% auto;"><label><input type="checkbox" value="<?php echo implode(",",$answer["keys"]); ?>" /><?php echo $answer["label"]; ?></label></div>`
Here's my CSS:
`.expert-advice .imgButton input[type=checkbox] {display:none;}
.expert-advice .imgButton {
background-size: cover;
background-origin: content-box;
background-position: top left;
-webkit-background-size: cover;
-moz-background-size: cover;
background-color: transparent !important;
border:1px solid #e3e3e3;
text-align: center;
color:#ff6600;
display:inline-block;
position: relative;
overflow: hidden;
margin-right: 15px;
}
.expert-advice .imgButton.sm {
width: 106px;
height: 98px;
-moz-border-radius:9px;
-webkit-border-radius:9px;
border-radius:9px;
font-size:.8em !important;
}
.expert-advice .imgButton.lg {
width: 205px;
height: 188px;
-moz-border-radius:18px;
-webkit-border-radius:18px;
border-radius:18px;
font-size:1.0em !important;
}
.expert-advice .imgButton label {
width: 100%;
height:auto;
position: absolute;
display:block;
top:80%;
}
.expert-advice .imgButton:hover {
background-color: #fcf1cc;
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPHJhZGlhbEdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgY3g9IjUwJSIgY3k9IjUwJSIgcj0iNzUlIj4KICAgIDxzdG9wIG9mZnNldD0iMzAlIiBzdG9wLWNvbG9yPSIjZmZmZmZmIiBzdG9wLW9wYWNpdHk9IjEiLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2Y5YzYzNiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9yYWRpYWxHcmFkaWVudD4KICA8cmVjdCB4PSItNTAiIHk9Ii01MCIgd2lkdGg9IjEwMSIgaGVpZ2h0PSIxMDEiIGZpbGw9InVybCgjZ3JhZC11Y2dnLWdlbmVyYXRlZCkiIC8+Cjwvc3ZnPg==);
background: -moz-radial-gradient(center, ellipse cover, #ffffff 30%, #f9c636 100%); /* FF3.6+ */
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(30%,#ffffff), color-stop(100%,#f9c636)); /* Chrome,Safari4+ */
background: -webkit-radial-gradient(center, ellipse cover, #ffffff 30%,#f9c636 100%); /* Chrome10+,Safari5.1+ */
background: -o-radial-gradient(center, ellipse cover, #ffffff 30%,#f9c636 100%); /* Opera 12+ */
background: -ms-radial-gradient(center, ellipse cover, #ffffff 30%,#f9c636 100%); /* IE10+ */
background: radial-gradient(ellipse at center, #ffffff 30%,#f9c636 100%); /* W3C */
-moz-box-shadow: 0px 1px 18px -8px #000000;
-webkit-box-shadow: 0px 1px 18px -8px #000000;
box-shadow: 0px 1px 18px -8px #000000;
border:1px solid #f8bf1f;
}`
Your :hover background property is overwriting your button background property. This is the expected behavior of CSS, since the :hover selector is more specific. What you need instead, is to combine the background properties into a single statement. This is called multiple backgrounds and it is well supported by browsers.
Try this CSS instead:
.imgButton:hover {
background-image: url(http://www.danalydesign.com/finding-time.jpg), radial-gradient(ellipse at center, #ffffff 30%,#f9c636 100%);
}
Example Fiddle
The background images are stacked with the 1st image sitting on top and the last image sitting on bottom. more on background image stacking order
I've seen a million people do it, but I haven't been able to get it to work.
background: -webkit-linear-gradient(left top, black, #333333 85%, gray), url('/img/helix.png');
I've tried with the order reversed and with background-image, still nothing.
I saw one person use:
body:before {
content: " ";
width: 100%;
height: 100%;
position: absolute;
z-index: -1;
top: 0;
left: 0;
background: -webkit-linear-gradient(left top, black, #333333 85%, gray);
}
But there has to be a better way...
Updated code:
In an ID for the image div:
height: 100%;
width: 100%;
background: transparent url('/img/helix-white.png') no-repeat;
In the CSS for the body element:
background: -webkit-linear-gradient(left top, black, #333333 85%, gray);
background: -moz-linear-gradient(left top, black, #333333 85%, gray);
background: -ms-linear-gradient(left top, black, #333333 85%, gray);
background: -o-linear-gradient(left top, black, #333333 85%, gray);
background: linear-gradient(left top, black, #333333 85%, gray);
Update 2:
I used a div with the image in it with CSS for positioning:
<div id="backgroundImage">
<img src="img/helix-white.png" alt=" " />
</div>
#backgroundImage
{
position: fixed;
bottom: 10%;
left: 7%;
opacity:0.4;
filter:alpha(opacity=40);
-webkit-transform: rotateZ(20deg);
-moz-transform: rotateZ(20deg);
-ms-transform: rotateZ(20deg);
-o-transform: rotateZ(20deg);
transform: rotateZ(20deg);
}
And in the body CSS for the gradient:
height: 100%;
background: -webkit-linear-gradient(left top, black, #333333 85%, gray);
background: -moz-linear-gradient(left top, black, #333333 85%, gray);
background: -ms-linear-gradient(left top, black, #333333 85%, gray);
background: -o-linear-gradient(left top, black, #333333 85%, gray);
background: linear-gradient(left top, black, #333333 85%, gray);
Why not have a div with the background gradient then another div inside with a background image. If the background image is a .png with transparency or doesn't fill the div, you'll be able to see the gradient behind it.
e.g.
<div id="gradient">
<div id="image">
Your content here.
</div>
</div>
CSS
#gradient {
background: -webkit-linear-gradient(left top, black, #333333 85%, gray); }
#image {
background: transparent url('your image here') center center no-repeat; }
On another note, you should use a full range of gradient options to support all browsers (not just webkit). I'd recommend using a CSS3 gradient generator for the code:
http://www.colorzilla.com/gradient-editor/
as mentioned, be sure you're checking your stuff in either Safari or an older version of Chrome. They both use(d) webkit as the rendering engine.