What I am looking to achieve is to display an image with a transparent background layer, this image would sit over a background which would have a white border and gray box centred in the image area.
Basically to give the image a partial gray background, then to leave the rest white, to give the appearance of the image to "float" over the gray background as well as allow me to make simple css changes to change the background verses having to redo the images to change the look.
this is the css I have tried:
.borderlist img {
text-align:center;
vertical-align:middle;
background:
linear-gradient
(255,255,255, 0.9),
url('../images/gray.png') no-repeat;
max-width: 100%;
height:auto;
}
And the html:
<span class="borderlist"><img src="images/bounty.png" alt="BOUNTY" title=" BOUNTY " width="225" height="155"></span><br>BOUNTY
I removed the underline from the <a> because it creates a weird underline on the <br>. If you want the text to be underlined, you could throw it in a <span> with a class that tells it to have it. but this is what I got. Let me know if you're needing it to do something different.
.overflowing-img {
display: inline-block;
text-align: center;
text-decoration: none;
}
.undrline {
text-decoration: underline;
}
.borderlist {
text-align: center;
}
.borderlist img {
text-align:center;
vertical-align:middle;
background-image: linear-gradient(rgba(160,160,160, 0.5), rgba(160,160,160, 0.5));
background-repeat: no-repeat;
background-size: 80% auto;
background-position: center center;
}
<a href="http://www.domain.com/bounty.html" class="overflowing-img">
<span class="borderlist">
<img src="http://pngimg.com/upload/gift_PNG5950.png" alt="BOUNTY" title=" BOUNTY " width="225" height="155">
</span>
<br>
<span class="undrline">BOUNTY<span>
</a>
I used a different image, but is this what you are attempting to achieve?
.borderlist img {
width: 200;
height: 100;
}
.borderlist {
width: 225px;
height: 125px;
text-align: center;
vertical-align: middle;
background: linear-gradient(to bottom, #c8c8c8, #ffffff);
margin: auto;
}
.whiteBorder {
width: 255px;
height: 155px;
background-color: #ffffff;
text-align: center;
}
<div class="whiteBorder">
<div class="borderlist">
<a href="http://www.domain.com/bounty.html">
<img src="http://en.wikipedia.org/static/images/project-logos/enwiki.png" alt="BOUNTY" title="BOUNTY">
<br>BOUNTY</a>
</div>
</div>
Try doing using :before in your css to overlay the image on top of a div.
div{
width: 200px; height: 200px;
background-color: lightgray;
box-sizing: border-box;
border: 20px solid white;
position: relative;
}
div:before{
content: "";
display: block;
margin: -20px;
width: 200px;
height: 200px;
background-image: url('https://i.stack.imgur.com/eLzG5.png');
background-size: contain;
background-repeat: no-repeat;
}
<div></div>
Lets go very simple first:
You can't move the image to left by changing css though
.borderlist {
background: grey;
border: 60px solid white;
box-sizing: border-box;
width: 260px;
}
<div class="borderlist">
<img src="https://s9.postimg.org/d0odjmlcv/dwa.png" height="100px" width="150px" />
</div>
You can do this too, create a container div, inside, create the grey div, then float the image above the grey div, like this (I think this is the best):
.borderlist {
padding: 5%;
background: white;
width: 160px;
height: 120px;
position: relative;
}
.grey {
position: absolute;
background: grey;
width: 130px;
height: 90px;
margin: 10px;
}
.float {
position: absolute;
}
<div class="borderlist">
<div class="grey">
</div>
<img class="float" src="https://s9.postimg.org/d0odjmlcv/dwa.png" height="100px" width="150px" />
</div>
Feel free to change and play around to understand it properly
If you're OK with using a mask (white colored background covering the edges), you could use multiple backgrounds coupled with a background color. (credit to user Dave Cripps for the demo image that I shamelessly stole from his demo for mine.)
a {
text-align:center;
display:inline-block;
}
.borderlist {
display:inline-block;
text-align:center;
vertical-align:middle;
background:
linear-gradient(to right, white 15%, transparent 15%, transparent 85%, white 85%), linear-gradient(to bottom, white 15%, transparent 15%, transparent 85%, white 85%);
background-color: #eee;
transition: background-color 0.4s;
}
a:hover .borderlist {
background-color: #5C5;
}
.borderlist img {
height:auto;
}
<span class="borderlist"><img src="http://en.wikipedia.org/static/images/project-logos/enwiki.png " alt="BOUNTY" title=" BOUNTY " width="225" height="155"></span><br>BOUNTY
Related
How do I add an hovering effect on an element that serves as an SVG Icon that can also change the color of the icon itself.
This is what I have right now, two option, using a mask image or display the icon as background.
The problem using background in CSS, the display is correct when hovering but I can't change the icon color.
.icon {
display: inline-block;
background: url('https://cdn-icons-png.flaticon.com/512/151/151773.png') no-repeat center; /* imagine the file here as an SVG file */
background-size: 100px 100px !important;
height: 100px;
width: 100px;
}
.icon_interactive:hover {
cursor: pointer;
background-color: white;
border-radius: 50%;
padding: 25px;
}
<div style="padding: 100px; background-color: gray; text-align: center;">
<span class="icon icon_interactive"></span>
</div>
The problem using mask-image in CSS, the display is incorrect when hovering but I can change the icon color.
.icon {
-webkit-mask: url('https://cdn-icons-png.flaticon.com/512/151/151773.png');
-webkit-mask-size: cover !important;
mask-image: url('https://cdn-icons-png.flaticon.com/512/151/151773.png');
mask-size: cover !important;
display: inline-block;
background-color: black;
height: 100px;
width: 100px;
}
.icon_interactive:hover {
cursor: pointer;
background-color: white;
border-radius: 50%;
padding: 25px;
}
<div style="padding: 100px; background-color: gray; text-align: center;">
<span class="icon icon_interactive"></span>
</div>
What I want to create is an interactive icon when hovering that you can change the color of the icon itself.
EDIT:
To summarize my problem, I have a masked element which acts as an Icon an I need to have it controllable color, size and also a background circle when hovering the element.
Consider pseudo element to combine both tricks:
.icon {
display: inline-block;
height: 100px;
width: 100px;
border-radius: 50%;
padding: 25px;
}
.icon:before {
content: "";
display: block;
height:100%;
background: #000;
-webkit-mask: url('https://cdn-icons-png.flaticon.com/512/151/151773.png') center/100px 100px no-repeat;
}
.icon_interactive:hover {
cursor: pointer;
background-color: white;
}
.icon_interactive:hover::before {
background:red;
}
body {
background:gray;
}
<span class="icon icon_interactive"></span>
I am attempting to get a div, bar-grow to be width: 80%; of the header above it. Right now, it is taking 80% width of the parent container. I am unsure how I change this so that it is working how I want it.
Any suggestions?
.header-wrap {
border: 1px solid black;
}
.header {
font-size: 2rem;
margin-bottom: 12px;
display: inline;
}
.bar-grow {
background: linear-gradient(to right, #BE1E2D, #BE1E2D) no-repeat;
background-size: 100% 7px;
transition: 1s;-webkit-transition: 1s;
margin-bottom: 50px;
height: 7px;
width: 80%;
}
<div class="header-wrap">
<p class="header">Structural Framing Solutions</p>
<div class="bar-grow"></div>
</div>
You need something to wrap both of those elements that isn't a full width element. I added a div and set it to display: inline-block. You could apply that style to the header-wrap div if you don't want an extra div (note it will shrink that div to be just wide enough to contain it's contents).
.header-wrap {
border: 1px solid black;
}
.header {
font-size: 2rem;
margin-bottom: 12px;
display: inline;
}
.header-width-constrainer {
display: inline-block;
}
.bar-grow {
background: linear-gradient(to right, #BE1E2D, #BE1E2D) no-repeat;
background-size: 100% 7px;
transition: 1s;-webkit-transition: 1s;
margin-bottom: 50px;
height: 7px;
width: 80%;
}
<div class="header-wrap">
<div class="header-width-constrainer">
<p class="header">Structural Framing Solutions</p>
<div class="bar-grow"></div>
</div>
</div>
Why not simply move the gradient to the header element and control easily its size:
.header-wrap {
border: 1px solid black;
}
.header {
font-size: 2rem;
margin-bottom: 52px;
padding-bottom:7px;
display: inline-block;
background: linear-gradient(to right, #BE1E2D, #BE1E2D) no-repeat;
background-size: 80% 7px;
background-position:0 100%;
}
<div class="header-wrap">
<p class="header">Structural Framing Solutions</p>
</div>
I don't think there is an easy way to make a div like "bar-grow" 80% width of it's sibling (the text, "Structural Framing Solutions")... Technically, that text is sitting inside of a div that takes up the full width 100% of the screen, so your code is working as intended. An alternate approach, would be something like this:
.bar-grow {
background: linear-gradient(to right, #BE1E2D, #BE1E2D) no-repeat;
background-size: 100% 7px;
transition: 1s;-webkit-transition: 1s;
margin-bottom: 50px;
height: 7px;
width: 300px;
}
Notice how I changed 80% width to 300px width?
300px, roughly, is 80% of the title's length. I used my eye ball to choose the 300px. Make that small adjustment and see if it can work for you.
With my edit, it could render like this:
Hopefully I am understanding the problem, correctly!
So I'm trying to make a nav buttons without using a image. But I can't get the CSS to work out properly. I managed to get everything but the vertical alignment of the text, yet to get that far I feel the code as become more sloppy than necessary. Here is what I have:
.nav_button {
height: 18px;
background: linear-gradient(#3D3C3B 0%, #0A0B0A 50%);
margin-top: 5px;
}
.arrow_container {
display: inline-block;
width: 35px;
}
.nav_arrow {
width: 20px;
height: 18px;
background: linear-gradient(#D2DA76 0%, #5EB649 50%);
}
.nav_link {
display: inline-block;
width: 125px;
text-align: center;
}
.nav_arrow::after {
display: block;
content: '';
height: 18px;
width: 20px;
background: linear-gradient(to bottom right, #D2DA76 0%, #5EB649 50%);
transform: translate(10px, 0px) scale(.8, .715) rotate(45deg);
}
<a href='#'>
<div class='nav_button'><span class='arrow_container'><div class='nav_arrow'></div></span><span class='nav_link'>Test</span></div>
</a>
Is there a better way to write this? if not I at least need to know how to vertical align the text. line-height did not work.
Edit: Here is a demo pic. the arrow is backwards but it's close.
A better solution may be to actually build your button's structure relative to the size of the text's line-height, rather than trying to hardcode the size and then update the line-height secondly.
The simplification of the html is based upon the idea that we use a single gradient overlay on the button rather than fading both the button background and the "arrow" section with different colours independently. However, this doesnt exactly match the design.
.nav_button_alt{
display:inline-block;
border:1px solid #888;
color:#FFF;
text-decoration:none;
font-family:Helvetica, Arial, sans-serif;
position:relative;
background:#5EB649;
font-size:1.2em;
line-height:1.4em;
padding:0 0.2em 0 40px;
min-width:125px; /* remove this if you wish the buttons to be relative to the size of the text*/
}
.nav_button_alt > span{
display:inline-block;
position:relative;
width:100%;
z-index:3;
text-align:center;
}
/* provides the fade */
.nav_button_alt:before{
content:"";
position:absolute;
top:0;
left:0;
right:0;
z-index:2;
height:100%;
background-image: linear-gradient(rgba(255,255,255,0.6) 0%, rgba(255,255,255,0) 50%);
}
/* provides the "black" overlay of the green background */
.nav_button_alt:after{
content:"";
position:absolute;
left:1.2em; /* distance from the right that the arrow starts */
top:0;
height:0;
right:0;
border-left:1em solid transparent; /* size of the green arrow's point */
border-top:0.7em solid #000; /* half the height of the button */
border-bottom:0.7em solid #000; /* half the height of the button */
z-index: 1;
}
<a href="#" class="nav_button_alt">
<span>Test</span>
</a>
Try vertically aligning the text inside the button.
.nav_button {
height: 18px;
background: linear-gradient(#3D3C3B 0%, #0A0B0A 50%);
margin-top: 5px;
}
.arrow_container {
display: inline-block;
width: 35px;
}
.nav_arrow {
width: 20px;
height: 18px;
background: linear-gradient(#D2DA76 0%, #5EB649 50%);
}
.nav_link {
display: inline-block;
width: 125px;
text-align: center;
vertical-align:top;
}
.nav_arrow::after {
display: block;
content: '';
height: 18px;
width: 20px;
background: linear-gradient(to bottom right, #D2DA76 0%, #5EB649 50%);
transform: translate(10px, 0px) scale(.8, .715) rotate(45deg);
}
<a href='#'>
<div class='nav_button'><span class='arrow_container'><div class='nav_arrow'></div></span><span class='nav_link'>Test</span></div>
</a>
Use "line-height" for vertical alignment of text. Here's an example
div {
height: 90px;
line-height: 90px;
text-align: center;
border: 2px dashed #f69c55;
}
<div>
Hello World!
</div>
I am trying to get a certain effect on a header for a mockup. It has white glow almost not noticeable. You will see it in this picture i provide behind the title and sub title. How can i get that glow effect with css? I do have a header with the entire thing but is that a good idea to use an image for an entire header? Also i want those two lines near the subtitle. Is it possible to code those lines? And last, the button "order now", will that be possible to make with css or should i just use an image of that and link it?
mockup
jsfiddle - http://jsfiddle.net/ezdr3xdg/1/ [what i currently have]
<header>
<h1>Taffies Cupcakes</h1>
<h2>Fresh and tasty</h2>
</header>
body{
background-color:#e7d2c9;
}
header h1{
font-family:georgia;
font-size:46px;
color:#784f3d;
text-align:center;
margin-top:50px;
}
header h2{
font-family:segoe script;
font-size:32px;
color:#846a5f;
text-align:center;
}
All of this is possible to do in CSS 3, I wouldn't recommend it though. Using an image for the button and the header is the best idea if you want it to look the same in all browsers. If you want to do it in CSS anyway try this:
HTML:
<header>
<div class="shadow"></div>
<h1>Taffies Cupcakes</h1>
<h2><div class="line"></div>Fresh and tasty<div class="line"></div></h2>
</header>
CSS:
header > .shadow {
width: 0px;
height: 0px;
margin: 0px 50%;
box-shadow: 0px 0px 200px 100px white;
}
header h2 > .line {
height: 1px;
width: 100px;
margin: 5px 20px;
background-color: #846a5f;
display: inline-block;
vertical-align: middle;
}
As the other answers have mentioned, radial-gradient is probably the way to go here. Just apply it to the header element instead of using my version with box-shadow (which might be a little hacky to some).
Update for the button:
HTML:
<button class="special"><div class="icon"></div><div class="headline">ORDER NOW</div><div class="description">We deliver in 24 hours</div></button>
CSS:
button.special {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #784f3d), color-stop(1, #846a5f) );
background:-moz-linear-gradient( center top, #784f3d 5%, #846a5f 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#784f3d', endColorstr='#846a5f');
background-color:#784f3d;
color: #e7d2c9;
text-align: left;
border: 0;
outline: 0;
border-radius: 5px;
height: 42px;
}
button.special > .icon {
width: 27px;
height: 27px;
/*background-image: url('triangle-button.png')*/
position: absolute;
margin: 5px;
}
button.special > .headline {
margin-left: 42px;
font-size: 18px;
}
button.special > .description {
margin-left: 42px;
font-size: 12px;
}
http://jsfiddle.net/ezdr3xdg/17/
Use CSS radial-gradient()
DEMO 1:
body {
height: 100vh;
background-color: #e7d2c9;
background-image: -webkit-radial-gradient(center top, ellipse farthest-corner, #fff 0%, #e7d2c9 50%);
}
DEMO 2:
body{
height:100vh;
background-color:#e7d2c9;
background-image: -webkit-radial-gradient(center top, ellipse farthest-corner, #fff 0%, #e7d2c9 100%);
}
DEMO 3:
body {
height: 100vh;
background-color: #e7d2c9;
position:relative;
}
body:after {
content: '';
position: absolute;
left: 50%;
top: -150px;
margin-left: -100px;
width: 200px;
height: 200px;
border-radius: 50%;
z-index:-1;
background: rgba(255, 255, 255, 0.42);
box-shadow: 0 0 40px 64px rgba(255, 255, 255, 0.42);
}
I have update your jsfiddle with a starting template of sorts. Its CSS# gradients and border-radius. http://jsfiddle.net/ezdr3xdg/7/
the button:
<div id="order_now">
<div id="triangle-right"></div>
<div id="text">
ORDER NOW
<div id="sub_order">we deliver in 24hours</div>
</div>
</div>
CSS:
The Button:
#order_now{
background: linear-gradient(#846a5f, brown);
width: 200px;
border-radius: 5px;
padding: 5px;
color: white;
font-size: 12pt;
font-weight: bold;
}
#sub_order{
font-size: 10pt;
font-style: italic;
}
#triangle-right {
width: 0;
height: 0;
border-top: 25px solid transparent;
border-left: 50px solid white;
border-bottom: 25px solid transparent;
display: inline-block;
}
#text{
display: inline-block;
}
The Background:
body{
background:linear-gradient(to right, red, blue, red);
}
this should be enough to get you started.
Is it possible to have transparent text on top of a white background with an image behind it, so that the text appears to be the colour of the image behind it.
Here's a JSFiddle of what I started to give you a better understanding of what I mean:
http://jsfiddle.net/g3SfD/
Right now the text is black, but is there a way to make it transparent so that the colour of the text is that of the background image?
HTML:
<div class="image">
<div class="box">
<div class="text">Sample Text</div>
</div>
</div>
CSS:
.text {
color: black;
font-family: Arial;
font-size: 72px;
font-weight: bold;
}
.box {
display: inline-block;
background: white;
padding: 5px 10px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -219px;
margin-top: -47.5px;
}
.image {
background: url('http://www.menucool.com/slider/prod/image-slider-4.jpg') no-repeat;
width: 960px;
height: 420px;
position: relative;
}
Demo
Ok thanks to this example provided by ralph.m, it seems possible using -webkit-background-clip which would only be supported by browsers that can use webkit.
.text {
font-family: Arial;
font-size: 72px;
font-weight: bold;
text-align: center;
background: url('http://www.menucool.com/slider/prod/image-slider-4.jpg') no-repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 200% 200%;
background-position: -200px -50px;
}
Your background size and position may need tweaking to suit.
I guess you're looking for the rgba() function.
It takes 4 parameters, 3 colors channels and one alpha that controls the opacity of the color.