I am wondering if below black shape can be made through css, or we need to use SVG for it, please provide css if possible.
In above image, the shape of black div is quite tricky to be done through css, please suggest.
Yes, It can be done by svg, but going not so far, we can do that by css3 also.
div {
margin: 60px auto;
width: 200px;
height: 50px;
position: relative;
background-color: #555;
transform: rotate(-5deg);
-webkit-transform: rotate(-5deg);
}
span {
display: block;
width: 200px;
height: 60px;
padding: 15px 0;
position: relative;
z-index: 1;
text-align: center;
transform: rotate(5deg);
-webkit-transform: rotate(5deg);
}
div::before {
content: "";
width: 100%;
height: 20px;
position: absolute;
background-color: #555;
transform: rotate(-3deg);
-webkit-transform: rotate(-3deg);
top: -6px;
}
<div>
<span>Phone Number</span>
</div>
Here's a rough sketch .
You can do it with help of :before and :after pseudo elements. then try to mess with border as suggested here
.bigbox:before{
content:'';
color:red;
top:90px;
left:8px;
width: 0;
height: 0;
border-left: 210px solid transparent;
border-right: 0px solid transparent;
border-bottom: 10px solid black;
position:absolute;
}
Related
I wrote a code to create a triangular badge. It is almost working, only lower end is kinda cut off.
Here is my code:
span {
border: 1px solid #999;
border-radius: 5px;
display: inline-block;
padding: 3px 8px;
text-decoration: none;
}
.newBadge {
border-right: 50px solid transparent !important;
border-top: 50px solid #777 !important;
height: 41px !important;
left: 0px;
position: absolute;
top: 0px;
}
.badgeText {
color: #fff;
height: 90px;
left: 0;
position: absolute;
top: 0;
width: 100px;
height: 90px;
}
.badgeText strong {
display: block;
height: 100%;
left: 37px;
position: relative;
-webkit-transform: rotate(-45deg) translate(0, -25%);
-moz-transform: rotate(-45deg) translate(0, -25%);
-ms-transform: rotate(-45deg) translate(0, -25%);
-o-transform: rotate(-45deg) translate(0, -25%);
transform: rotate(-45deg) translate(0px, -25%);
width: 100%;
font-size: 12px;
bottom: 10px;
}
<span class="newBadge"></span>
<span class="badgeText">
<strong>Text</strong>
</span>
How do I fix the lower end of the triangle?
I had to tweak .newBadge a little:
span {
border: 1px solid #999;
border-radius: 5px;
display: inline-block;
padding: 3px 8px;
text-decoration: none;
}
.newBadge {
border-right: 80px solid transparent !important;
border-top: 70px solid #777 !important;
height: 41px !important;
left: -20px;
position: absolute;
top: 0px;
border-bottom:none;
}
.badgeText {
color: #fff;
height: 90px;
left: 0;
position: absolute;
top: 0;
width: 100px;
height: 90px;
}
.badgeText strong {
display: block;
height: 100%;
left: 37px;
position: relative;
-webkit-transform: rotate(-45deg) translate(0, -25%);
-moz-transform: rotate(-45deg) translate(0, -25%);
-ms-transform: rotate(-45deg) translate(0, -25%);
-o-transform: rotate(-45deg) translate(0, -25%);
transform: rotate(-45deg) translate(0px, -25%);
width: 100%;
font-size: 12px;
bottom:10px;
}
<span class="newBadge"></span>
<span class="badgeText">
<strong>Text</strong>
</span>
So, moving to the left side, little more, and increasing borders, did the trick, it seems? Also, border-bottom is set to none, because it is inherited from span...
Also, not sure, but if you can work with fixed dimensions of badge, i would suggest much easier (cleaner) HTML/CSS: https://jsfiddle.net/9o00a553/
div {
border: 1px solid #999;
border-radius: 5px;
display: inline-block;
padding: 3px 8px;
text-decoration: none;
width:100px;
height:100px;
position:relative;
overflow:hidden;
margin:50px;
}
div:before {
content:"";
color:white;
transform: rotate(-45deg);
position:absolute;
background:red;
width:100%;
height:100%;
left:-50%;
top:-50%;
}
span {
transform: rotate(-45deg);
color:white;
position:absolute;
z-index:3;
left:12px;
top:20px;
}
<div>
<span class="text">text</span>
</div>
Short answer: Remove the height and padding on the badge, and use the left and bottom borders as well. The changed style for .newBadge will be like this:
.newBadge {
padding: 0;
border-top: 33px solid #777 !important;
border-bottom: 33px solid transparent !important;
border-left: 33px solid #777 !important;
border-right: 33px solid transparent !important;
height: 0 !important;
left: 0px;
position: absolute;
top: 0px;
}
On (very) close inspection, you might notice that the right and bottom corners look a little cut-off; this is due to the border-radius. Setting border-top-right-radius and border-bottom-left-radius to 0 will make those nice and sharp.
Longer answer: The cut-off on the bottom corner is being caused mainly by the padding, and also a little bit from the browser rendering something due to the border-radius and the transparent border color (I couldn't tell you why that is). I don't think there's a clean and reliable way to completely get rid of those artifacts.
Instead, rearrange the parts of the border to more directly create the triangle you want. Since the two legs are the top and left, color the top and left parts of the border, then use the opposite sides uncolored to square it up. Setting all the border-widths the same will keep it even. The width of each border will be half of the side length — since the original border width was 50, and the left and right padding were each 8, the new border width is (50 + 8 + 8) / 2 == 33.
The snippet shows a comparison of the original and changed results. Change the colors of each border fragment to see what each one contributes.
span {
border: 1px solid #999;
border-radius: 5px;
display: inline-block;
padding: 3px 8px;
text-decoration: none;
}
.newBadge {
border-right: 50px solid transparent !important;
border-top: 50px solid #777 !important;
height: 41px !important;
left: 0px;
position: absolute;
top: 0px;
}
#new .newBadge {
/* padding and height should be 0, or they will interfere with the triangle */
padding: 0;
height: 0 !important;
/* Since the triangle is top and left, color those parts of the border, and use the opposite sides uncolored with the same dimensions to make the triangle perfect */
border-top: 33px solid #777 !important;
border-bottom: 33px solid transparent !important;
border-left: 33px solid #777 !important;
border-right: 33px solid transparent !important;
}
.badgeText {
color: #fff;
height: 90px;
left: 0;
position: absolute;
top: 0;
width: 100px;
height: 90px;
}
.badgeText strong {
display: block;
height: 100%;
left: 37px;
position: relative;
-webkit-transform: rotate(-45deg) translate(0, -25%);
-moz-transform: rotate(-45deg) translate(0, -25%);
-ms-transform: rotate(-45deg) translate(0, -25%);
-o-transform: rotate(-45deg) translate(0, -25%);
transform: rotate(-45deg) translate(0px, -25%);
width: 100%;
font-size: 12px;
bottom: 10px;
}
/* The rest is just to get the side-by-side divs for comparison. */
div {
position: relative;
width: 140px;
float: left;
margin-top: 1.2em;
}
div::before {
display: block;
position: relative;
top: -1.2em;
}
#old::before {
content: "Old:";
}
#new::before {
content: "New:";
}
<div id="old">
<span class="newBadge"></span>
<span class="badgeText">
<strong>Text</strong>
</span>
</div>
<div id="new">
<span class="newBadge"></span>
<span class="badgeText">
<strong>Text</strong>
</span>
</div>
I am trying to achieve the slanted left and right borders like the following design
I have been successful in achieving something that looks like it, especially the left and right slanted borders in screen size 1360px. Unfortunately, when the screen size is increased/decreased the left and right borders really mess up the layout. Is there a better way of doing this so that it is responsive and borders stay in correct places?
Here is how i'm coding the layout currently:
.f-col1 {
width: 15%;
float: left;
position: relative;
margin-top: -30px;
}
.f-col1::before {
content: " ";
width: 104%;
border-bottom: 1px solid #FFF;
position: absolute;
left: 0;
top: 0;
-ms-transform: rotate(22deg);
-webkit-transform: rotate(22deg);
transform: rotate(22deg);
margin-top: -8px;
}
.f-col2 {
width: 70%;
float: left;
border-top: 1px solid #FFF;
padding-top: 12px;
}
.f-col3 {
width: 15%;
float: left;
text-align: right;
position: relative;
margin-top: -50px;
}
.f-col3::before {
content: " ";
width: 104%;
border-bottom: 1px solid #FFF;
position: absolute;
left: 0;
top: 0;
-ms-transform: rotate(-22deg);
-webkit-transform: rotate(-22deg);
transform: rotate(-22deg);
margin-top: 12px;
margin-left: -4%;
}
I have made a JSFiddle for it:
https://jsfiddle.net/btmxus6t/
Also, live link where you can see the layout is displaying correctly in 1360px but messes up when screen size is changed:
http://revolutionarycoder.com/footer/index.html
If you wish to keep the same HTML structure:
Forcing the width to stay the same so we'll make sure the element doesn't change in size, including a static top/left/right property to force it into place, rest of the border will just fall off if not neccesary. Do note that this is a custom solution, and will not be very responsive if you decide to change stuff.
.f-col1::before {
content: " ";
width: 260px;
border-bottom: 1px solid #FFF;
position: absolute;
top: -20px;
right: -10px;
-ms-transform: rotate(22deg);
-webkit-transform: rotate(22deg);
transform: rotate(22deg);
}
.f-col3::before {
content: " ";
width: 265px;
border-bottom: 1px solid #FFF;
position: absolute;
left: -10px;
top: 0;
-ms-transform: rotate(-22deg);
-webkit-transform: rotate(-22deg);
transform: rotate(-22deg);
}
You can use rotating pseudo elements with heading:
body {
background: black;
color: white;
margin: 0;
}
h2 {
box-shadow: inset 0 -1px 0 0 white;
line-height: 4.5em;
margin: 0 10em;
position: relative;
text-align: center;
}
h2:before, h2:after {
bottom: 0;
box-shadow: inherit;
content: "";
height: 1px;
display: block;
position: absolute;
width: 10em;
}
h2:before {
right: 100%;
transform: rotate(20deg);
transform-origin: right bottom;
}
h2:after {
left: 100%;
transform: rotate(-20deg);
transform-origin: left bottom;
}
<h2>Title</h2>
I am trying to put a point on the right side of a relative (no defined width) div.
HTML (using Wordpress and Bootstrap)
<div class="col-md-9 col-md-offset-1">
<h2 class="sml-title"><?php the_category(' - '); ?></h2>
...
CSS
.sml-title {
display: inline-block;
padding: 15px;
color: #fff;
background-color: #4ad2dc;
}
.sml-title:after {
right: 0px;
top: 0px;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(136, 183, 213, 0);
border-left-color: #88b7d5;
border-width: 30px;
margin-top: -30px;
}
the problem I'm running into is that the arrow goes all the way to the right side of the screen. I want it to go right after the sml-title. But I can't set a width on the sml-title because i don't control the content.
Trying to accomplish this
You can achieve the shape as either of the two ways-
.arrow {
border-right: 33px solid transparent;
height: 0;
width: 130px;
border-bottom: 34px solid black;
}
.invert {
-moz-transform: rotateX(180deg);
-webkit-transform: rotateX(180deg);
transform: transform: rotateX(180deg);
;
}
#base {
background: red;
display: inline-block;
height: 134px;
margin-left: 33px;
/* margin-top: 51px; */
position: relative;
width: 70px;
transform: rotate(90deg);
}
#base:before {
border-bottom: 35px solid red;
border-left: 36px solid transparent;
border-right: 34px solid transparent;
content: "";
height: 0;
left: 0;
position: absolute;
top: -35px;
width: 0;
}
<div class="arrow"></div>
<div class="arrow invert"></div>
<div id="base"></div>
h2{
background: #000;
color: #fff;
float: left;
font-family: Arial, sans-serif;
overflow: hidden;
padding: 20px 50px 20px 20px;
position: relative;
text-align: center;
min-width: 200px;
}
h2:before, h2:after {
content: '';
display: block;
width: 0;
height: 0;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid #fff;
position: absolute;
right: -10px;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
}
h2:before {
top: -20px;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
}
h2:after {
bottom: -20px;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
<h2 class="sml-title">TITLE</h2>
If you use position: absolute, it will position the element within the nearest parent which is either position: relative or absolute. In your case, .sml-title has neither of those properties, so .sml-title:after is not positioned within .sml-title.
If you want your ::after pseudoelement to be positioned within .sml-title, you'll need to add position: relative or absolute to .sml-title
Hi ,
I need create div which would look like one on the provided image. Notice black and grey zones. I have been experimenting with css 3 but i was able to create only differently rotated trapezoid. Is it possible to create this only with css ?
EDIT: What ive tried was this
trapezoid {
border-bottom: 100px solid red;
border-left: 150px solid transparent;
border-right: 0px solid transparent;
height: 0;
}
It produces trapezoid which is nice but its differnetly rotated and i cant figure out how to rotate it
You could use a skew'ed pseudo element for this. Something like:
div {
height: 100px;
background: tomato;
padding-top: 10px;
position: relative;
overflow: hidden;
}
div:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 150%;
background: gray;
-webkit-transform-origin: top left;
-webkit-transform: skewY(2deg);
-moz-transform-origin: top left;
-moz-transform: skewY(2deg);
transform-origin: top left;
transform: skewY(2deg);
}
<div></div>
Another Approach would be:
div{
height:100px;
width:90vw;
margin:0;padding:0;
padding-top:10px;
background:gray;position:relative;
}
div:before{
content:"";
position:absolute;
top:0;
left:0;
border-left:90vw solid transparent;
border-top:10px solid red;
-webkit-transform:translateZ(0);
transform:translateZ(0);
}
<div></div>
You have to take a dummy div to make it behave as want that to rotate and make the tail visible
#black {
background-color: black;
position: absolute;
-ms-transform: rotate(1deg);
/* IE 9 */
-webkit-transform: rotate(1deg);
/* Safari */
transform: rotate(1deg);
top: -95px;
}
#grey {
background-color: grey;
position: absolute;
top: 0px;
}
div {
width: 100%;
height: 100px
}
<div id="grey"></div>
<div id="black"></div>
This is what your expected output:
.main {
background: none repeat scroll 0 0 grey;
height: 80px;
overflow: hidden;
position: relative;
width: 380px;
}
.inner {
background: none repeat scroll 0 0 red;
height: 80px;
left: 400px;
margin: 0 auto;
top: 80px;
width: 150px;
z-index: 99999;
}
.inner::before {
border-bottom: 0 solid transparent;
border-right: 100px solid red;
border-top: 83px solid transparent;
bottom: 0;
content: "";
height: 66px;
left: 15px;
position: absolute;
right: 100%;
top: 0;
width: 0;
}
<div class="main">
<div class="inner"></div></div>
Hope it helps.
I'm Trying to get my :before arrow work nicely with my div, but i can't find a way to give the arrow
background-color: transparent
dashed border.
CSS:
position: absolute;
top: 30px;
right: 8px;
display: inline-block;
border-top: 12px dashed transparent;
border-left: 12px dashed #b3b3b3;
border-bottom: 12px dashed transparent;
border-left-color: #b3b3b3;
content: '';
JS FIDDLE
You should use same border-width and rotate the pseudo element.
Add a background to hide the box border where it stands. DEMO
CSS can become for the pseudo :
ul.timeline li.item-timeline:nth-child(even):before {
position: absolute;
top: 37px;
right: 15px;
display: inline-block;
border-top: 1px dashed #b3b3b3;
border-right: 1px dashed #b3b3b3;
width:10px;
height:10px;
transform:rotate(45deg);
background:white;
z-index:1;
content:'';
}
Use prefix wherever it is needed.
Extra infos,
if the buggy dotted radius border in FF bothers you, you can play with an outline-offset to cut into borders.DEMO, for FF only
#-moz-document url-prefix() {
/* a stupid way to fix here the border radius effect when dotted or dashed*/
div.inner-content {
outline:white double 4px;
outline-offset:-5px;
}
}
you can get the idea from this code http://codepen.io/romanstrobel/pen/EgCHi. You can't use the :before though, because of different z-indexes
HTML
<div class="wrap">
<div class="arrow"></div>
<div class="arrow-cover"></div>
<div class="box"></div>
</div>
CSS
.wrap {
margin: 100px auto;
width: 300px;
height: 150px;
position: relative;
}
.arrow {
width: 50px;
height: 50px;
border: 3px dotted gray;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
position: absolute;
top: 50%;
margin-top: -25px;
left: -25px;
z-index: 10;
border-radius: 10px;
}
.arrow-cover {
top: 50%;
margin-top: -25px;
left: -21px;
width: 50px;
height: 50px;
border: 3px solid transparent;
position: absolute;
background: white;
z-index: 30;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
border-radius: 10px;
}
.box {
width: 300px;
height: 150px;
background: white;
z-index: 20;
position: relative;
border: 3px dotted gray;
background: white;
border-radius: 10px;
}