I am trying to achieve this effect. I want the two bars on each side to extend to the edge of the page. This is the closest I've come. I obviously need to flip the "folds" somehow, and I need to get each light blue bar to extend to the edge of the page.
http://jsfiddle.net/vPJ8g/
<div id="ribbon">
<span id="content">Call us today! 555-555-5555</span>
</div>
*{margin:0px;padding:0px;}
html {
width:100%;
height:100%;
background:#CCC;
text-align: center;
}
#ribbon {
padding: .5em 2em;
margin: 0;
margin-top: 5%;
position:relative;
color: #ffffff;
font: 20px 'Arial', sans-serif;
text-align: center;
background: #5f85b4;
display: inline-block;
}
#ribbon:before, #ribbon:after {
content: "";
width:1em;
top:-.5em;
position:absolute;
display:block;
border: .9em solid #1eb2df;
z-index:-2;
}
#ribbon:before {
left:-1.5em;
}
#ribbon:after {
right:-1.5em;
}
#content:before, #content:after {
content:"";
bottom:2.1em;
position:absolute;
display:block;
border-style:solid;
border-color: #2c4059 transparent transparent transparent;
z-index:-1;
}
#content:before {
left: 0;
border-width: .5em 1em 0 0;
}
#content:after {
right: 0;
border-width: .5em 0 0 1em;
}
You can use display: table; and display: table-cell; and some markup changes to achieve the results you are going for.
I removed your #content as it's a redundant identifier. You can use ancestor selections from the #ribbon to achieve the same results, without hogging a unique ID.
HTML:
<div id="ribbon">
<div>
<span>Call us today! 555-555-5555</span>
</div>
</div>
CSS:
#ribbon {
display: table;
margin: 0;
margin-top: 5%;
position:relative;
color: #ffffff;
font: 20px 'Arial', sans-serif;
text-align: center;
width: 100%
}
#ribbon:before, #ribbon:after {
content: "";
width:25%;
top:-.5em;
position:absolute;
display: table-cell;
border: .9em solid #1eb2df;
z-index:-2;
}
#ribbon:before {
left:-1.5em;
}
#ribbon:after {
right:-1.5em;
}
#ribbon > div {
margin: 0;
display: table-cell;
position: relative;
width: 53%;
}
#ribbon span {
display: block;
color: #ffffff;
font: 20px 'Arial', sans-serif;
text-align: center;
background: #5f85b4;
padding: .5em 2em;
position: relative;
}
#ribbon span:before, #ribbon span:after {
content:"";
bottom:2.1em;
position:absolute;
display: block;
border-style:solid;
border-color: #2c4059 transparent transparent transparent;
z-index:-1;
top: -10px;
}
#ribbon span:before {
left: 0;
border-width: .5em 1em 0 0;
}
#ribbon span:after {
right: 0;
border-width: .5em 0 0 1em;
}
Example: http://jsfiddle.net/vPJ8g/4/
To get the ribbon to stretch across the whole page, make #ribbon:before and #ribbon:after really big and use a combination of positioning and margins to get them where they need to be:
#ribbon:before {
width: 1000000em;
left: 0;
margin-left: -1000000.8em;
}
#ribbon:after {
width: 1000000em;
right: 0;
margin-right: -1000000.8em;
}
http://jsfiddle.net/BYossarian/vPJ8g/7/
And to flip the triangular folds bits just play with the border-color property:
#content:before {
left: 0;
border-width: .5em 1em 0 0;
border-color: transparent #2c4059 transparent transparent;
}
#content:after {
right: 0;
border-width: .5em 0 0 1em;
border-color: transparent transparent transparent #2c4059;
}
http://jsfiddle.net/BYossarian/vPJ8g/8/
Related
so i have the following design for some "button tabs".
One side is curved, so border radius would not really be possible.
But is this type of curve even possible ?
or am i doomed to use some sort of image?
mostly looking for tips on how this might be accomplished, or somewhere i can look for a solution, since my previous tries to find a solution has yet to yield a result.
Html
<div class="tab-row">
<button>All Products<div class="tab-row__counter">20</div></button>
<button>Hardware<div class="tab-row__counter">20</div></button>
<button>Virtual<div class="tab-row__counter">20</div></button>
<button>Bundles<div class="tab-row__counter">20</div></button>
</div>
Css
.tab-row{
button{
background-color:$element-bg;
border:0;
color:$white;
width:300px;
height:90px;
margin-right:20px;
margin-top:40px;
border-radius: 5px 100px 0 0;
&:first-child{
margin-left:40px;
}
.tab-row__counter{
}
}
}
This is what i ended up with as a result,
https://codepen.io/andrelange91/pen/YzPqJXO
not exactly curved but close enough
You can try the curves by using the border-radius, transform, and transform-origin properties like,
/**
* Slanted tabs with CSS 3D transforms
* See http://lea.verou.me/2013/10/slanted-tabs-with-css-3d-transforms/
*/
body { padding: 50px;background:#20273d }
nav {
position: relative;
z-index: 1;
white-space: nowrap;
}
nav a {
position: relative;
display: inline-block;
padding: 1.5em 2em 1em 1em;
color:#9a9a9a;
text-decoration: none;
margin: 0 -7px;
}
nav a::before {
content: ''; /* To generate the box */
position: absolute;
top: 0; right: 0; bottom: .5em; left: 0;
z-index: -1;
border-radius: 10px 10px 0 0;
background: #434f78;
box-shadow: 0 2px hsla(0,0%,100%,.5) inset;
transform: perspective(5px) rotateX(2deg);
transform-origin: bottom left;
}
nav a.selected {
z-index: 2;
color:#FFF;
}
<nav class="left">
All Products
Hardware
Virtual
</nav>
You can use radial gradient also,
body { padding: 50px;background:#20273d }
nav {
position: relative;
z-index: 1;
white-space: nowrap;
}
nav a {
position: relative;
display: inline-block;
padding: 1em 5em 1.2em 1em;
color:#9a9a9a;
text-decoration: none;
margin: 0 -20px;
border: 0px none;
}
nav a::before {
content: ''; /* To generate the box */
position: absolute;
top: 0;
right: 0;
bottom: .5em;
left: 0;
z-index: -1;
background: radial-gradient(circle at top right,transparent 5.8vw, #434f78 6.8vw);
transform: perspective(10px) rotateX(1deg);
transform-origin: bottom left;
border: 0px none;
}
nav a.selected {
z-index: 2;
color:#FFF;
}
<nav class="left">
All Products
Hardware
Virtual
</nav>
Whilst this does not replicate the exact shape you're after, this does provide an example of the method I described in the comments in how to approach it. You will just need to edit the values in ::before and ::after to get it to your desired shape.
.curve {
background: blue;
width: 50px;
height: 75px;
position: relative;
}
.curve:before {
content: '';
background-image: radial-gradient(circle at 100% 100%, rgba(204, 0, 0, 0) 100px, blue 100px);
position: absolute;
top: 0;
left: 100%;
width: 100px;
height: 75px;
}
.curve:after {
content: '';
position: absolute;
width: 50px;
height: 75px;
background: blue;
border-radius: 0 0 100% 0 / 0 0 100% 0;
top: 100%;
left: 0;
}
.container {
display: flex;
align-items: flex-start;
justify-content: center;
}
.tab {
height: 150px;
width: 300px;
background: red
}
<div class="container">
<div class="tab"></div>
<div class="curve"></div>
</div>
Also take a look at Creating s-shaped curve using css
I'm unsure how to tackle what i'm doing.
I'm basically trying to achieve the above. I have a section tag and a list of li tags with a hr tag for the line. They overlap poorly though and don't sit/look as smoothly as i'd like.
Html:
<section class="navigation">
<li class="page_nav--one">One</li>
<hr class="page_nav--line_break" />
<li class="page_nav--two">Two</li>
<li class="page_nav--three">Three</li>
</section>
and my css looks like :
.navigation {
background: #fff;
text-align: center;
margin: 50px 0;
display: block;
.page_nav--line_break {
position: absolute;
display: block;
height: 1px;
top: -14px;
border: 0;
border-top: 1px solid #ccc;
/* margin: 1em 0; */
padding: 0;
width: 400px;
right: 202px;
z-index: 999999;
}
li {
display: inline-block;
list-style: none;
position: relative;
margin: 10px 85px;
}
li:before {
content: '';
height: 16px;
width: 16px;
background-size: 16px 16px;
position: absolute;
top: -23px;
left: 16px;
margin: auto;
cursor: pointer;
pointer-events: none;
}
li:nth-child(1):before {
background: url("trianle_image.png");
}
li:nth-child(2):before {
left: 23px;
background: url("trianle_image.png");
}
li:nth-child(3):before {
left: 35px;
background: url("trianle_image.png");
}
}
Is there a better method/way of achieving what i'm after or am I going about it the correct way?
I would probably use :after pseudo elements.
<div class="diamond"></div>
<div class="diamond"></div>
<div class="diamond"></div>
then the CSS with pseudo elements looks like this:
.diamond {
width:10px;
height:10px;
position:relative:
float:left;
margin-right:100px;
}
.diamond:last-of-type {
margin-right:0;
}
.diamond:after {
content:""
display:block;
width:100px;
height:1px;
background-color:gray;
position:absolute;
top:5px;
left:5px;
}
.diamond:last-of-type:after {
display:none;
}
So the theory is that the after element is your line (like you have) and it is as wide as the margin between the two elements, placed exactly where you need it. Then the last one is hidden.
FIDDLE
I have the following. However, I've been trying to get the blue title area to expand with the outter div and the arrow to be aligned in the middle. I have an outer div set at 25% just so the text wraps.
.breakingNewsRec {
width: 100%;
background: #FFF;
position: relative;
border: solid 2px #6A7791;
}
.breakingNewsRec>.bn-rec {
width: auto;
display: inline-block;
background: #6A7791;
position: relative;
margin-right: 20px;
}
.breakingNewsRec>.bn-rec>h2 {
display: inline-block;
margin: 0;
padding: 0 20px;
line-height: 40px;
font-size: 0.8em;
color: #FFF;
box-sizing: border-box;
}
.breakingNewsRec>.bn-rec>span {
position: absolute;
right: -10px;
top: 10px;
height: 0;
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent #6A7791;
}
.breakingNewsTown {
width: 100%;
height: 40px;
background: #FFF;
position: relative;
border: solid 2px #74936A;
}
.breakingNewsTown>.bn-rec {
width: auto;
height: 40px;
display: inline-block;
background: #74936A;
position: relative;
margin-right: 20px;
}
.breakingNewsTown>.bn-rec>h2 {
display: inline-block;
margin: 0;
padding: 0 20px;
line-height: 40px;
font-size: 0.8em;
color: #FFF;
height: 40px;
box-sizing: border-box;
}
.breakingNewsTown>.bn-rec>span {
width: 0;
position: absolute;
right: -10px;
top: 10px;
height: 0;
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent #74936A;
}
<div style="width: 25%">
<div class="breakingNewsRec">
<div class="bn-rec">
<h2>Recreation News</h2><span></span>
</div>fdsasdf asdif ksd jfkasjdfasj dfla sjdflj
<img src="imgs/slides/slide2.jpg" width="25%">asdfljas dflkjsdf alskdjf asdfl</div>
<div class="breakingNewsTown">
<div class="bn-rec">
<h2>Town News</h2><span></span>
</div>fareveae vasev</div>
</div>
Using display:table-cell this is very easy to accomplish:
#news {
width: 50%;
}
#news .item {
border-width: 1px;
border-style: solid;
}
#news .item h2 {
color: white;
font-size: 100%;
white-space: nowrap;
position: relative;
border-color: inherit;
}
#news .item h2:after {
content: '';
display: inline-block;
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent;
border-left-color: inherit;
vertical-align: middle;
position: absolute;
left: 100%;
}
#news .item h2,
#news .item div {
display: table-cell;
vertical-align: middle;
padding: 0 1.5em;
}
.style1 { border-color: #697791 }
.style1 h2 { background: #697791 }
.style2 { border-color: #74936a }
.style2 h2 { background: #74936a }
<div id="news">
<div class="item style1">
<h2>Recreation News</h2>
<div>
<p>fdsasdf asdif ksd jfkasjdfasj dfla sjdflj asdfljas dflkjsdf alskdjf asdfl</p>
</div>
</div>
<div class="item style2">
<h2>Town News</h2>
<div>
<p>fareveae vasev</p>
</div>
</div>
</div>
I am not sure exactly what you are trying to achieve, but it sounds like something like this:
which would just be applying width:100%; to .bn-rec
EDIT
Regarding your comment - I think I understand then. How about surrounding the text in a <div> and making both <div> tags display:inline-block; and restricting their width by %. Then increasing the margin of the arrow, also by a % like I did here:
https://jsfiddle.net/030y329m/
Is that closer to what you were thinking?
The code is provided in the fiddle link below.
JSFiddle Link
Code:
$(function() {
// Build "dynamic" rulers by adding items
$(".ruler[data-items]").each(function() {
var ruler = $(this).empty(),
len = Number(ruler.attr("data-items")) || 0,
item = $(document.createElement("li")),
i;
for (i = 0; i < len; i++) {
ruler.append(item.clone().text(i + 1));
}
});
// Change the spacing programatically
function changeRulerSpacing(spacing) {
$(".ruler").
css("padding-right", spacing).
find("li").
css("padding-left", spacing);
}
$("#spacing").change(function() {
changeRulerSpacing($(this).val());
});
});
.ruler, .ruler li {
margin: 0;
padding: 0;
list-style: none;
display: inline-block;
}
/* IE6-7 Fix */
.ruler, .ruler li {
*display: inline;
}
.ruler {
background: lightYellow;
box-shadow: 0 -1px 1em hsl(60, 60%, 84%) inset;
border-radius: 2px;
border: 1px solid #ccc;
color: #ccc;
margin: 0;
height: 3em;
padding-right: 1cm;
white-space: nowrap;
}
.ruler li {
padding-left: 1cm;
width: 2em;
margin: .64em -1em -.64em;
text-align: center;
position: relative;
text-shadow: 1px 1px hsl(60, 60%, 84%);
}
.ruler li:before {
content: '';
position: absolute;
border-left: 1px solid #ccc;
height: .64em;
top: -.64em;
right: 1em;
}
/* Make me pretty! */
body {
font: 12px Ubuntu, Arial, sans-serif;
margin: 20px;
}
div {
margin-top: 2em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul class="ruler"><li>1</li><li>2</li><li>3</li><li>4</li></ul>
<div>
<ul class="ruler" data-items="10"></ul>
</div>
<div>
<label for="spacing">Spacing</label>
<select id="spacing">
<option>1cm</option>
<option>2cm</option>
<option>1in</option>
<option>1em</option>
<option>20px</option>
</select>
</div>
How can I show the text on top, next to the li tick in the provided link?
Currently, I am adding vertical-align:top to the css .ruler li but nothing changes in the UI.
Please check the image below. The requirement is shown in blue.
What css property in what css class do I need to add to make sure the text is shown at top and next to the tick?
Simply move the list items slightly to the right and up. Then move the :before pseudo elements the same amount to the left and down.
http://jsfiddle.net/kwcug/1006/
And I'm not sure why my update causes JSFiddle to think this one now has 1006 revisions.
Add some left position to your ruler li and adjust your right position in li:before
$(function() {
// Build "dynamic" rulers by adding items
$(".ruler[data-items]").each(function() {
var ruler = $(this).empty(),
len = Number(ruler.attr("data-items")) || 0,
item = $(document.createElement("li")),
i;
for (i = 0; i < len; i++) {
ruler.append(item.clone().text(i + 1));
}
});
// Change the spacing programatically
function changeRulerSpacing(spacing) {
$(".ruler").
css("padding-right", spacing).
find("li").
css("padding-left", spacing);
}
$("#spacing").change(function() {
changeRulerSpacing($(this).val());
});
});
.ruler,
.ruler li {
margin: 0;
padding: 0;
list-style: none;
display: inline-block;
}
/* IE6-7 Fix */
.ruler,
.ruler li {
*display: inline;
}
.ruler {
background: lightYellow;
box-shadow: 0 -1px 1em hsl(60, 60%, 84%) inset;
border-radius: 2px;
border: 1px solid #ccc;
color: #ccc;
margin: 0;
height: 3em;
padding-right: 1cm;
white-space: nowrap;
}
.ruler li {
padding-left: 1cm;
width: 2em;
margin: .64em -1em -.64em;
text-align: center;
position: relative;
text-shadow: 1px 1px hsl(60, 60%, 84%);
top: -.64em;
left: .64em
}
.ruler li:before {
content: '';
position: absolute;
border-left: 1px solid #ccc;
height: .64em;
right: 1.4em;
}
/* Make me pretty! */
body {
font: 12px Ubuntu, Arial, sans-serif;
margin: 20px;
}
div {
margin-top: 2em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" src="http://fonts.googleapis.com/css?family=Ubuntu" />
<ul class="ruler">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
<div>
<ul class="ruler" data-items="10"></ul>
</div>
<div>
<label for="spacing">Spacing</label>
<select id="spacing">
<option>1cm</option>
<option>2cm</option>
<option>1in</option>
<option>1em</option>
<option>20px</option>
</select>
</div>
Does this help?
http://jsfiddle.net/kwcug/1008/
I changed this
.ruler li {
margin: .64em -1em -.64em;
}
.ruler li:before {
content: '';
position: absolute;
border-left: 1px solid #ccc;
height: .64em;
top: -.64em;
right: 1em;
}
to
.ruler li:before {
content: '';
border-left: 1px solid #ccc;
margin-right: .2em;
}
.ruler li {
margin: 0 -1em -.64em;
}
I have a css class for centering a heading, and adding vertically centered lines on either side. Problem is, it uses css3 background properties, and not every browser supports those. So I'd like to simplify this for cross browser compatibility, but am not sure how to do that.
Is there a simpler way to achieve this, without the css3 background (and without adding any extra elements or static heights/widths)?
demo here
.section-heading {
display: table;
white-space: nowrap;
}
.section-heading:before {
background: linear-gradient(to bottom, black, black) no-repeat left center / 95% 1px;
content: "";
display: table-cell;
width: 50%;
}
.section-heading:after {
background: linear-gradient(to bottom, black, black) no-repeat right center / 95% 1px;
content: "";
display: table-cell;
width: 50%;
}
<h2 class="section-heading">Example</h2>
You can use fieldset and legend, it's not very beautiful code but you don't need CSS3
http://jsfiddle.net/dASCv/9/
fieldset {
text-align: center;
border: none;
border-top: 1px solid black;
}
legend {
padding: 20px;
}
<fieldset>
<legend>
<h2>Example</h2>
</legend>
</fieldset>
OR this other method whit :after and :before
http://jsfiddle.net/dASCv/10/
div {
text-align: center;
}
h2:before,
h2:after {
border-top: 1px solid black;
display: block;
height: 1px;
content: " ";
width: 40%;
position: absolute;
left: 0;
top: 1.4em;
}
h2:after {
right: 0;
left: auto;
}
<div>
<h2>text TEXT</h2>
</div>
There is my best try.
I have a little isue that I have corrected in Chrome; but I really don't know even why it works.
The CCS is
.test {
display: table-row;
white-space: nowrap;
line-height: 0px;
}
.test:before,
.test:after {
border-color: transparent;
border-top: solid black 1px;
border-left: solid transparent 1px;
border-bottom: solid rgba(0,0,0,0.01) 11px;
border-right: solid transparent 1px;
content: "";
display: table-cell;
width: 50%;
}
.test:before {
border-right: solid 30px transparent;
}
.test:after {
border-left: solid 30px transparent;
}
I am using the border to display the black line, and to have it positioned in place I have reduced the height of the table to 0.
fiddle
In the fiddle, I have kept your original demo, so that you can compare side by side.
And now, the weird part. change rgba(0,0,0,0.01) in the border bottom to rgba(0,0,0,0.001), and it will break (at least in Chrome).
I really would like to understand that ...
new answer
All the above was asuming that the requirement was to have a transparent style (that is , that it was posible to set a background that could be seen thru the h1. If this is not the case, there is another posible solution, using box-shadow instead of gradient barckground:
.test {
display: table-row;
white-space: nowrap;
}
.test:before,
.test:after {
border: solid white 10px;
content: "";
display: table-cell;
width: 50%;
height: 10px;
line-height: 10px;
box-shadow: inset 0px 5px white, inset 0px 6px black;
}
.test:before {
border-right-width: 10px;
border-left-width: 1px;
}
.test:after {
border-left-width: 10px;
border-right-width: 1px;
}
new demo
1-element solution
FIDDLE
div {
display: inline-block;
background: #fff;
padding: 0 10px;
}
div:before {
content: '';
display: block;
position: absolute;
left: 0;
width: 100%;
height: 20px;
border-bottom: 1px solid #c2c2c2;
margin-top: -9px;
z-index: -1;
}
<div>A header</div>
(NB: for this solution to work, you need to set text-align:center on its parent element)
2-element solution (works over a background image)
FIDDLE
.splitHR {
text-align: center;
overflow: hidden;
}
.splitHRText {
display: inline-block;
position: relative;
padding: 0 10px;
}
.splitHRText:before,
.splitHRText:after {
content: '';
display: block;
width: 1000px;
position: absolute;
top: 0.73em;
border-top: 1px solid #c2c2c2;
}
.splitHRText:before {
right: 100%;
}
.splitHRText:after {
left: 100%;
}
<div class="splitHR">
<span class="splitHRText">A header</span>
</div>
Please add Prefix for the CSS
For Webkit browswers
-webkit-gradient
Firefox
-moz-linear-gradient
IE
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#cccccc', endColorstr='#000000');
More Details Here http://webdesignerwall.com/tutorials/cross-browser-css-gradient
Using this way also you can achieve the answer, please check this
<p style="display:block; width:100%; text-align:center;
border-bottom:1px #ccc solid; line-height:3px">
<span style="background-color:red; ">Examples</span></p>
http://jsfiddle.net/dASCv/11/
css
h2 {
border-bottom: 1px solid black;
text-align: center;
margin: 0;
padding: 0;
}
h2 span {
display: inline-block;
position: relative;
padding: 0 20px;
bottom: -15px;
background-color: white;
}
markup
<h2><span>text Textsssssssssssssssss</span></h2>
You could set the bottom for span in percentage if you set the height for h2.
you can use this code:
JsFiddle DEMO
HTML:
<h2><span>Title is here</span></h2>
CSS:
h2{
display:block;
text-align:center;
line-height:30px;
}
h2 span{
background:#fff;
padding:0 10px;
}
h2:after{
content:"";
display:block;
border-top:1px solid black;
margin-top:-15px;
}
Update:
you can use this code too: (single element)
JsFiddle
HTML:
<h2>Title is here</h2>
CSS:
h2{
display: table;
margin: 0 auto;
text-align: center;
line-height: 30px;
padding: 0 10px;
background: #FFF;
}
h2:after{
content:"";
display:block;
border-top:1px solid;
margin-top:-15px;
position:absolute;
width:100%;
left:0;
z-index:-1;
}