Have a client request for irregular corners in CSS. Is that even a thing? So far I had experimented with CSS triangles ( http://css-tricks.com/snippets/css/css-triangle/ ) but no bueno.
https://dl.dropbox.com/u/4031469/irreg.png
Thinking I'll probably have to do it with images sadly... unless y'alls know of any way to pull it off.
The main parameters: Needs to be at least flexible in height, preferably flexible in width too, but not required. Current solution: Top capper that extends potentially above the box enough to make the corner effect work on the secondary box... with the lower descender pieces right absolutely aligned pushing below.
My closest attempt so far (uses image for top): https://dl.dropbox.com/u/4031469/fs.html
Stealing from http://nicolasgallagher.com/pure-css-speech-bubbles/
http://jsfiddle.net/aBYHX/
EDIT :- Second attempt. Simpler, less css and on the same side as your example pic.
http://jsfiddle.net/aBYHX/1/
<div class="content">
<p class="triangle-isosceles">This only needs one HTML element.</p>
<p class="irregular-corner"> ---- </p>
</div>
Css:
.content
{
padding: 15px;
}
.triangle-isosceles, .irregular-corner
{
position:relative;
padding:15px;
margin:1em 0 3em;
color:#000;
background:#f3961c;
}
.triangle-isosceles:after {
content:"";
position:absolute;
bottom: 0;
right: 0;
border-width: 25px 50px 0 0;
border-style: solid;
border-color: transparent white;
/* reduce the damage in FF3.0 */
display:block;
}
.irregular-corner:before
{
content:"";
position:absolute;
top: -25px;
right: 0px;
border-width: 25px 50px 0 0;
border-style:solid;
border-color:transparent #f3961c;
/* reduce the damage in FF3.0 */
display:block;
}
Under CSS3, as far as I've researched, the particulars of this look make it not yet possible.
This look has a subtle gradient and inner glow, which we've accomplished using an inset box shadow... that seems to not work with the prior css triangle effects.
CSS Masks look like they might be able to assist in many circumstances, but in circumstances requiring box-shadow: inset, images are the only way to go.
Today I got this working using the -webkit-clip-path property, which has varying browser support.
.entry{
background-color: blue;
width: 500px;
height: 200px;
-webkit-clip-path: polygon(0% 0%, 90% 0%, 100% 40%, 100% 100%, 0 100%);
-webkit-transform: translateY(-30px);
top: 10px;
left: 0;
}
body{
background-color: green;
}
http://codepen.io/randallb/pen/tmlAH
Nora Brown wrote a lovely article on the CSS3 border-image property. It's worth a quick read...
If you're worried about cross-browser support (and you should be), then offer a graceful fallback. Perhaps just having a border with no "crazy corners" would do as a fallback situation, perhaps not.
This method isn't cross-browser, but some find it nice to be "progressive".
Related
The site I'm working on has headings that look like this:
http://i.imgur.com/ssvj8J1.png
They need to...
a) be centered on the page
b) be flexible width, to fit the contained text with a few em of padding either side.
c) work on IE9+, and of course all the other modern browsers
d) work on any background (so the images used can't contain white bits to help with overlaying)
I started off chopping it into 3 bits, and using ::before and ::after. This had problems with the backgrounds overlapping.
I then tried a sliding-doors approach, with just 2 images, but obviously had similar problems.
Now I'm on multiple BG images, which I've not used before. Same problem as above, they overlap. The solution seems to be to "clip" the middle one to content-box, but then that limits the padding I can use to strictly 53px, the "width" of each end bit of the banner, making them look too cramped?
Also, what's the best way of centering these? They're h1 tags. Do I need to use positioning/translation/inline-block? Or can I somehow keep them as 100% width block elements (which would be easier/better) and just centralise the backgrounds?
This is what I had before I tried to make them fluid:
h1{
background:url(banner.png) 50% 0 no-repeat;
line-height:52px;
color:#fff;
padding:0 0 6px}
And this is where I'm at now:
h1{
background-image:url(banner-left.png), url(banner-mid.png), url(banner-right.png);
background-position:0%, 50%, 100%;
background-repeat:no-repeat, repeat-x, no-repeat;
background-clip:border-box, content-box, border-box;
line-height:52px;
color:#fff;
display:inline-block;
padding:0 53px 6px}
I'm not happy with this for the reasons mentioned above. I feel I'm missing some obvious/easy tricks?!
Thanks - CSS seems to have moved on a lot since I last did anything significant!
You can use a pseudo elements and avoid the images completely.
Codepen Demo
HTML
<div><h1><span>Short Text</span></h1></div>
<div><h1><span>Much Longer Text</span></h1></div>
CSS
body {
text-align: center;
}
div {
margin: 25px;
}
h1 {
position: relative;
line-height: 1em;
max-width:50%;
display: inline-block;
}
h1 span {
color:gold;
padding: .5em;
background: black;
box-shadow:
0 0 0px 1px gold,
0 0 0px 3px black;
}
h1::before, h1::after {
position: absolute;
content:"";
top:35%;
z-index:-1;
border: solid black;
border-width:25px;
}
h1::before { /* left */
border-left-color:transparent;
left:0;
transform:translateX(-75%)
}
h1::after { /* right */
border-right-color:transparent;
right:0;
transform:translateX(75%)
}
I wanted to make a cool div, so I made this image to get its borders:
The problem is that half of the borders are transparent area, so when I try to fill the empty center of the div with background-color it also paints the outer, transparent area. I'd like the background color not to get past the border.
Here's what I'm talking about:
#charset "utf-8";
/* CSS Document */
#testDiv{
border-image-source:url(https://s9.postimg.org/40j461sf3/Div_Sprite.png);
border-image-slice: 50% 25% 25%;
border-image-repeat:repeat;
border-image-width:auto;
border-image-repeat:round;
background-color: red;
min-height:600px;
width:600px;
}
#body {
height:100%;
width: 100%;
background: #CCC;
position: absolute;
margin: 50px 0 0 0;
}
<div id="testDiv">
</div>
Or see http://jsfiddle.net/6M59T/119/.
How can I solve this? I've thought on putting a slightly smaller div inside this one, but I don't know how to adjust it so it always covers a bit less than its parent. Also, I'd like to keep it as simple as possible. Any ideas?
Maybe i am mistaken, but you can try to play with border-image-outset and margin attribute.
float:left;
margin:50px 20px;
border-image-source:url(http://s9.postimg.org/40j461sf3/Div_Sprite.png);
border-image-slice: 50% 25% 25%;
border-image-repeat:repeat;
border-image-width:auto;
border-image-repeat:round;
background-color: red;
border-image-outset:30px;
http://jsfiddle.net/6M59T/120/
I'm in somewhat of a situation as I need to make minor CSS adjustments but do not have permission to touch the graphics.
In this case, i have a background image (that has a width of 461px in Photoshop) and I need to extend it 4-5 pixels.
The current for CSS for this image is:
#screenvolumeslidermenu{
background:url(../html_cmi/lopa/volume_bg_overlay.png) no-repeat;
background-size:100%;
width:461px;
height:51px;
position:fixed;
z-index:15;
top:678px;
left:70px;
display:none;
}
It didn't initially have the no-repeat property, but if I take that out and just increase the current width, the image will start to repeat. If I leave it in as is and increase the width, no visible change is made but using inspect element the width is technically increasing. See here:
I want the right side of the black rectangle to extend a few more pixels on the right side.
I tried using background-size but couldn't get any decent results.
What is the best solution here to extend the image width without touching it in Photoshop?
In your situation. The ideal method would be to create the whole thing using CSS. Create the main rectangle and use :before and :after to create the arrow with border styles. Check this site out
.arrow_box {
position: relative;
background: #88b7d5;
border: 4px solid #c2e1f5;
}
.arrow_box:after, .arrow_box:before {
right: 100%;
top: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.arrow_box:after {
border-color: rgba(136, 183, 213, 0);
border-right-color: #88b7d5;
border-width: 30px;
margin-top: -30px;
}
.arrow_box:before {
border-color: rgba(194, 225, 245, 0);
border-right-color: #c2e1f5;
border-width: 36px;
margin-top: -36px;
}
1) background-size can accept two values, for example
background-size: 200% 100%;
should let you stretch only one dimension (can use pixels too).
2) if you don't want to touch proportions, consider creating another, narrower element that has the same background image, but aligned to the right edge, and place it over the first element, aligned to the right. Then by moving the right piece like a slide ruler, you'll be able to vary overall width without distorting your graphics.
This is a page that uses a carousel (I believe flexslider). The images in this carrousel are NOT background images. I need to add a gradient to the image, going from the bottom up, and from dark to zero opacity, so that I can make the text more legible. Is this possible?
http://hungersolutionsny.magadev.net
Personally I am not a big fan of adding markup just for styling. I would go for a pseudo element :before or :after
The code would look something like this:
HTML
<div class='slideshow-wrapper'>
<img src='http://www.placekitten.com/800/300'/>
<h2 class='title'>Some title</h2>
</div>
CSS
.slideshow-wrapper {
position:relative;
float: left;
}
.title {
position: absolute;
left: 0;
right: 0;
text-align: center;
z-index: 2;
}
.slideshow-wrapper:before {
content: '';
position:absolute;
top:0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,1) 100%);
z-index: 1;
}
And an example: http://jsfiddle.net/VrGeM/
Overlay the image with an absolutely positioned <div> that's the same size as the slider. Give that <div> the gradient. Ensure that it's above the images but below the text on top of the images.
It's also pretty easy to create a transparent PNG to use rather than a CSS gradient, which will have the advantage of working in older versions of IE.
The way I ususally do this is via an absolutely-positioned DIV which sits on top of the images and contains the text. Then I give that an opacity like so:
background-color: rgba(0, 0, 0, 0.56);
If you want a gradient with opacity, this is a good tool which makes that easy: http://www.colorzilla.com/gradient-editor/
There are a number of ways to tackle this. Mainly targeting the background CSS property. If you're looking to target the text that is overlapping the image you could use something simple like this:
body.front #region-content #flexslider-1 ul.slides .views-field-field-banner-statement {
background-color:rgba(0, 0, 0, 0.5);
}
It doesn't apply a gradient but it does supply a black background with 50% opacity.
I usually don't use a gradient in this way... when faced with this problem in the past I have always used an inset box-shadow on a div wrapped around the image. Something like this...
<div class="img-wrap">
<img src="" />
</div>
And then in CSS apply the box-shadow to a pseudo selector...
.img-wrap {
display: block;
position: relative;
}
.img-wrap:before {
display: block;
content: '';
position: absolute;
width: 100%;
height: 100%;
-webkit-box-shadow: inset 0 -100px 80px 0px rgba(0,0,0,0.4);
}
img {
display: block;
width: 100%;
height: auto;
}
Check out this CodePen if you want to see it live... http://cdpn.io/qGwLe
I have a jquery slider on my page which is centered when the page is wide enough to fit it yet aligns with the left edge of the window and shifts when the window is smaller. Below is my CSS - Am I missing something?
#billboardWrapper {height:600px;width:100%;margin:-170px 0 0 0px; position:relative; overflow:hidden; /*border-width: 0 20px 20px 20px; border-style:solid; border-color: {{settings.billboard_color}}; /* can't use border shorthand. IE9 has a rendering bug, see more notes in the ie8.css file */ }
#billboard {height:600px;width:1000px;position:relative;/*background:#1c1c1c;*/ background-position: 50% 0pt;}
#billboardPrev,
#billboardNext { display:block; text-indent:-9999px; position:absolute; left:40px; top:270px; width:30px; height:30px; cursor:pointer; background: url(arrows.png) no-repeat 0 0; z-index:99;}
#billboardNext {left:auto; right:40px; background-position:0 -92px; }
.slide {height:600px;width:1000px;display:none; }
.slide img {height:600px; width:100%; background-position: 50% 0pt;
.slideLeftLayout .slideTitle,.slideLeftLayout .slideText,.slideLeftLayout .slideLink {left:50px;}
.slideRightLayout .slideTitle,.slideRightLayout .slideText,.slideRightLayout .slideLink {right:50px;text-align:right;}
Perhaps it is centered by chance on the larger screen.
Centering usually works when you have:
width: (any-FIXED-WIDTH-value); - Good spot Bram Vanroy ;)
margin: auto;
which I cannot see...
You should really add your HTML too, and if possible start a jsfiddle and include the link. This way other users can play with it and solve it for you, and we can understand your code better too.
Hope that helps