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 set a FontAwesome icon as a "defualt thumbnail" for a list of articles. My problem is that the icon is appearing off center horizontally in my div. See the jsFiddle.
<div class="card-row-image fa fa-cutlery thumbnail-default">
<div class="card-row-label">Restaurants
</div>
<div class="card-row-price">Pennsylvania</div>
</div>
.thumbnail-default {
position: relative;
text-align: center;
border: 1px solid #547b97;
background: #e4e4e4;
}
.thumbnail-default:before {
position:absolute;
font-family: 'FontAwesome';
font-size: 72px;
color: #547b97;
text-align: center;
padding: 0px;
margin: 0px;
top: 50%;
transform: translateY(-50%);
}
.card-row-price {
background-color: #009f8b;
bottom: 0px;
color: #fff;
font-size: 13px;
left: 50%;
padding: 3px 15px;
position: absolute;
transform: translateX(-50%);
-webkit-transform: translateX(-50%);
white-space: nowrap;
z-index: 2;
}
.card-row-label {
background-color: #c6af5c;
color: #fff;
left: 50%;
font-size: 13px;
padding: 3px 15px;
position: absolute;
top: 0px;
transform: translateX(-50%);
-webkit-transform: translateX(-50%);
z-index: 2;
}
.card-row-image {
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
height: 200px;
position: relative;
width: 262px; }
Here is my current output:
Any ideas? Thanks for your time!
set these css codes to make it centered. This happens because on absolute positioned pseudo elements, if you do not specify where to be horizontally (you did not set left or right property), it will follow the text flow and would obey the text-align: center set on the parent.
.thumbnail-default:before { left: 50%; transform: translate(-50%, -50%); }
Working Fiddle
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
Im trying to do the following x icon, exactly the way it is in here:
So here is the html:
<div class='error-circle'>
<div>X</div>
</div>
And here is the css:
.error-circle{
width: 70px;
height: 70px;
background: #990000;
border-radius: 100px;
border: 4px solid white;
color: white;
font-size: 45px;
font-weight: bold;
padding-left: 17px;
}
It's close, but i really need the same result as the image (without the background), I think the X should not be the x character but two lines crossed one on the other, How should i achieve this result?
1) Remove padding
2) Change border-radius to 50%
3) Try a different font like verdana
FIDDLE
.error-circle {
width: 70px;
height: 70px;
line-height: 70px;
background: #990000;
border-radius: 50%;
border: 4px solid white;
color: white;
font-size: 45px;
font-family: verdana;
text-align: center;
}
<div class='error-circle'>
<div>X</div>
</div>
A real draw would look like this
*{box-sizing: border-box}
:root{background: #ccc}
div{
width: 150px;
height: 150px;
border-radius: 50%;
position: relative;
margin: 40px auto;
box-shadow: 0 0 0 10px white
}
div:before, div:after{
content: '';
position:absolute;
width: 20px;
height: 100px;
left: 64px;
top: 25px;
background: white
}
div:before{
transform: skew(28deg)
}
div:after{
transform: skew(-28deg);
}
<div/>
If you want it to look more real add some shadow
*{box-sizing: border-box}
:root{background: #ccc}
div{
width: 150px;
height: 150px;
border-radius: 50%;
position: relative;
margin: 40px auto;
box-shadow: 0 0 0 10px white, 0 0 24px 12px #B3B3B3, inset 0 0 16px 1px #B3B3B3;
}
div:before, div:after{
content: '';
position:absolute;
width: 20px;
height: 100px;
left: 64px;
top: 25px;
box-shadow: 0 0 16px 1px #B3B3B3;
background: white
}
div:before{
transform: skew(28deg)
}
div:after{
transform: skew(-28deg);
}
<div/>
The same result with a red background
*{box-sizing: border-box}
:root{background: #ccc}
div{
background: red;
width: 150px;
height: 150px;
border-radius: 50%;
position: relative;
margin: 40px auto;
box-shadow: 0 0 0 10px white, 0 0 24px 12px #B3B3B3, inset 0 0 16px 1px #B3B3B3;
}
div:before, div:after{
content: '';
position:absolute;
width: 20px;
height: 100px;
left: 64px;
top: 25px;
box-shadow: 0 0 16px 1px #B3B3B3;
background: white
}
div:before{
transform: skew(28deg)
}
div:after{
transform: skew(-28deg);
}
<div/>
Now you are ready to use transform: scale(.5,.5); on div to have multiple sizes
Use border radius as shown below.
body {
background-color: #A5A5A5; /* just to help outline the error icon */
}
#circlude {
width: 100px;
height: 100px;
background-color: red;
border-radius: 50%;
color: white;
font-weight: bold;
text-align: center;
font-size: 72px;
font-family: calibri; /* Pick the font that works for you */
line-height: 100px;
border: solid 4px white;
}
<div id="circlude"> X </div><!-- End Circlude -->
Try this :
.error-circle {
color: #000;
font-size: 2em;
font-weight: bold;
text-align: center;
width: 40px;
height: 40px;
border-radius: 5px;
}
.error-circle{
position: relative;
width: 70px;
height: 70px;
border-radius: 40px;
background-color: #990000;
border: 5px solid #fff;
}
.error-circle > div {
position: absolute;
top: 50%;
left: 50%;
margin-left: -15px;
margin-top: -27px;
text-align: center;
width: 20px;
font-size: 48px;
font-weight: bold;
color: #fff;
font-family: Arial;
}
<div class='error-circle'>
<div>X</div>
</div>
I would use pseudo effects with absolute positioning, removing the need for extra elements.
Using Pseudo effects
By making use of the :before and :after pseudo effects, you can make this button without using X:
LIVE DEMO
html{
background-color:gray;
}
.error-circle {
width:70px;
position:relative;
height: 70px;
background: #990000;
border-radius: 50%;
border: 4px solid white;
}
.error-circle:after,.error-circle:before {
position:absolute;
content:'';
width:10%;
left:45%;
top:10%;
height:80%;
background-color:white;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.error-circle:before{
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
<div class='error-circle'>
</div>
by using pseudo effects, it makes editing and management easy:
Example 1 <-- probably the best actually
Example 2
In terms of cross compatibility, you need to ensure you use -webkit- prefix in order for safari to accept the rotate.
other answers all solve the circle problem, i want to focus on the X that should be two cross lines.
You can try this for that porpuse (two arrows)
body{padding:20px;}
#arrow-left{
position: relative;
padding: 30px;
}
#arrow-left:before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 40%;
background: blue;
-webkit-transform: skew(135deg, 0deg);
-moz-transform: skew(135deg, 0deg);
-ms-transform: skew(135deg, 0deg);
-o-transform: skew(135deg, 0deg);
transform: skew(135deg, 0deg);
}
#arrow-left:after {
content: '';
position: absolute;
top: 100%;
right: 60%;
height: 100%;
width: 40%;
background: blue;
-webkit-transform: skew(-135deg, 0deg);
-moz-transform: skew(-135deg, 0deg);
-ms-transform: skew(-135deg, 0deg);
-o-transform: skew(-135deg, 0deg);
transform: skew(-135deg, 0deg);
}
#arrow-right{
position: relative;
padding: 30px;
}
#arrow-right:before {
content: '';
position: absolute;
top: 0;
left: 0px;
height: 100%;
width: 40%;
background: red;
-webkit-transform: skew(45deg, 0deg);
-moz-transform: skew(45deg, 0deg);
-ms-transform: skew(45deg, 0deg);
-o-transform: skew(45deg, 0deg);
transform: skew(45deg, 0deg);
}
#arrow-right:after {
content: '';
position: absolute;
top: 100%;
right: 60%;
height: 100%;
width: 40%;
background: red;
-webkit-transform: skew(-45deg, 0deg);
-moz-transform: skew(-45deg, 0deg);
-ms-transform: skew(-45deg, 0deg);
-o-transform: skew(-45deg, 0deg);
transform: skew(-45deg, 0deg);
}
<span id="arrow-right"></span>
<span></span>
<span id="arrow-left"></span>
You can also use a svg:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 22.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
viewBox="0 0 256 256" style="enable-background:new 0 0 256 256;" xml:space="preserve">
<title>icon / close / dark</title>
<desc>Created with Sketch.</desc>
<g id="icon-_x2F_-close-_x2F_-dark">
<polygon id="icon-_x2F_-close" points="224.3,0 128,96.3 31.7,0 0,31.7 96.3,128 0,224.3 31.7,256 128,159.7 224.3,256 256,224.3
159.7,128 256,31.7 "/>
</g>
</svg>
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;
}