I am trying to design the following image
The following has been my attempt so far, but i am just not able to get the content "x" to reach the four corners of the div.
HTML
<div id="cancel">X</div>
CSS
#cancel{
float: right;
border: 1px solid yellow;
font-family: 'Helvetica', 'Arial', sans-serif;
font-weight: lighter;
font-size: 3em;
width: 10%;
text-align: center;
background-color: #d5d6da;
color: white;
width: 12%;
cursor: pointer;
}
The following image is the output i was to be get to so far
I'd use a bit of scale for it - and a pseudo element :
Example
#cancel {
width: 0.9em;
height: 0.9em;
position: relative;
font-family: helvetica, arial, sans-serif;
font-weight: lighter;
font-size: 3em;
color: white;
background-color: #d5d6da;
cursor: pointer;
}
#cancel:after {
content: 'X';
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%,-50%) scaleX(1.2);
transform: translate(-50%,-50%) scaleX(1.2);
}
Or without any fonts and full control over how it looks :
Demo
#cancel {
width: 40px;
height: 40px;
position: relative;
background-color: #d5d6da;
cursor: pointer;
}
#cancel:before, #cancel:after {
content: '';
width: 110%;
height: 3px;
position: absolute;
top: 50%;
left: 50%;
background: white;
}
#cancel:before {
-webkit-transform: translate(-50%,-50%) rotate(45deg);
transform: translate(-50%,-50%) rotate(45deg);
}
#cancel:after {
-webkit-transform: translate(-50%,-50%) rotate(-45deg);
transform: translate(-50%,-50%) rotate(-45deg);
}
Here we create two pseudo elements (:before and :after) that are rectangles, both having a width of 110% of the parent and a few pixels height. They are then centered horizontally and vertically inside the parent with absolute positioning and a transform: translate. Last step is to make one rotate 45 degrees and the other the same amount but in the opposite direction. This will make them form a cross - the more width the elements are given, the closer they will be to the corners of the parent (at 141% they will be touching exactly since this is the length of the diagonal compared to it's the width).
I might recommend using an image file such as an svg so that you get a consistent look across all browsers. If you use text like an "X" or a multiplication sign, you might get an unexpected result if the user doesn't have the same fonts installed as you do.
Here is a live example of how you could go about using inline svg. Of course if you want to reuse the icon, you should use an img tag with an external .svg file instead:
Screenshot:
Demo:
#container {
width: 50px;
height: 50px;
background-color: gray;
}
<div id="container">
<svg version="1.1" id="Layer_1" xmlns="&ns_svg;" xmlns:xlink="&ns_xlink;" width="47" viewBox="0 0 14 14" overflow="visible" enable-background="new -1.301 -0.015 17.553 14.978" xml:space="preserve">
<g>
<line fill="none" stroke="#FFFFFF" stroke-width="2" x1="1" y1="1" x2="14" y2="14" />
<line fill="none" stroke="#FFFFFF" stroke-width="2" x1="14" y1="1" x2="1" y2="14" />
</g>
</svg>
</div>
You are looking for the Unicode Character 'MULTIPLICATION SIGN'. Perhaps there is a more elegant solution. This should work.
HTML
<div class="close"></div>
CSS
.close {
height: 100px;
width: 100px;
background-color: #2980b9;
border-radius: 5px;
}
.close:after {
position:relative;
content:"\d7";
font-size:235px;
color:white; /* #c0392b; */
font-weight:bold;
top:-100px;
left:-24px
}
JSFiddle
http://www.fileformat.info/info/unicode/char/00d7/index.htm
I like the svg solution as it will scale nicely, but if you want a CSS only solution, you can achieve something "similar" by doing this:
Create the box and assign it a relative position.
Use the pseudo-elements ::before and ::after to create the X (by positioning them absolutely, using the top border, and rotating them 45 and -45 degrees).
Here is a sample on how to do it:
.cancel {
position:relative;
width:100px;
height:100px;
background:#d0d0d0;
}
.cancel::before, .cancel::after {
content:"";
position:absolute;
top:calc(50% - 5px);
left:0px;
width:100%;
border-top:10px solid white;
transform:rotate(45deg);
transform-origin: 50% 50%;
}
.cancel::after {
transform:rotate(-45deg);
}
<div class="cancel"></div>
Some good things about this solution:
It can be easily animated using CSS3 transitions/animations (for example animate the X when clicked);
It "scales" a little: as it uses percentages for the ::before and ::after, the X grows proportionally if you grow/shrink the size of the .cancel box. Example.
Some cons about this solution:
It doesn't scale as nicely as the SVG.
You many need to use prefixes to make it work on some browsers.
Not sure if this is what you're looking for - but perhaps try a CSS solution with no "X" content? This solution is built with four div's that are all shaped like triangles with the help of CSS borders. Depending on how you position the triangles, your "X" in the middle can be as thin or as thick as you like, and the "X" will go all the way to the corners. The positioning in what I've posted isn't incredibly elegant, but you can get around this using floats and padding. I hope this helps!
HTML:
<div class="crossBox">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
CSS:
.crossBox div {
display: inline-block;
}
.crossBox div:first-child {
width: 0;
height: 0;
border-top: 58px solid blue;
border-left: 58px solid transparent;
border-right: 58px solid transparent;
background-color: transparent;
border-bottom: none;
position: relative;
top: -34px;
left: 5px;
}
.crossBox div:nth-child(2) {
width: 0;
height: 0;
border-left: 58px solid blue;
border-top: 58px solid transparent;
border-bottom: 58px solid transparent;
background-color: transparent;
border-right: none;
position: relative;
left: -118px;
top: 30px;
}
.crossBox div:nth-child(3) {
width: 0;
height: 0;
border-right: 58px solid blue;
border-top: 58px solid transparent;
border-bottom: 58px solid transparent;
background-color: transparent;
border-left: none;
position: relative;
left: -116px;
top: 30px;
}
.crossBox div:nth-child(4) {
width: 0;
height: 0;
border-bottom: 58px solid blue;
border-left: 58px solid transparent;
border-right: 58px solid transparent;
background-color: transparent;
border-top: none;
position: relative;
top: 36px;
left: -239px;
}
Related
I'm trying to make the following shape with just CSS:
Here is what I currently have:
.triangle {
width: 0;
height: 0;
border-style: solid;
border-width: 56px 56px 0 0;
border-color: #ff4369 transparent transparent transparent;
}
<div class="triangle">
</div>
I'm unable to use border radius to make the top-left corner rounded... Is there another way to do this or do I need to use an SVG?
Yes it's possible using border-radius:
.triangle {
box-sizing: border-box;
width: 60px;
height: 60px;
border-top: solid 30px rgb(200,30,50);
border-left: solid 30px rgb(200,30,50);
border-top-left-radius: 12px;
border-right: solid 30px transparent;
border-bottom: solid 30px transparent;
}
<div class="triangle triangle-0"></div>
To actually answer your question (and provide the first answer without border-radius): If you want a CSS only solution, you will have to use border-radius.
Nevertheless I would highly recommend to use SVG for creating shapes, as simple shapes like this are easy to create manually, it's responsive, it's widely supported now and (as #chharvey mentioned in the comments) semantically more appropriate.
<svg viewbox="0 0 50 50" height="56px">
<path d="M1 50 V10 Q1 1 10 1 H50z" fill="#ff4369" />
</svg>
You can find more information about the path properties in the specs.
You might consider the border-radius and clip-path: polygon() solution:
.triangle {
width: 56px;
height: 56px;
background: #ff4369;
border-top-left-radius: 12px;
-webkit-clip-path: polygon(0 0, 0% 100%, 100% 0);
clip-path: polygon(0 0, 0% 100%, 100% 0);
}
<div class="triangle"></div>
And another solution with the :before or :after pseudo-element, which can serve as a layer:
.triangle {
width: 56px;
height: 56px;
background: #ff4369;
border-top-left-radius: 12px;
position: relative;
overflow: hidden;
}
.triangle:after {
content: "";
position: absolute;
top: 0;
left: 50%;
width: 100%;
height: 100%;
background: #fff;
transform: skew(-45deg);
}
<div class="triangle"></div>
You can easily do with linear-gradient and it's well supported:
body {
background: #ccc;
}
.triangle {
margin: 10px;
width: 56px;
height: 56px;
background: linear-gradient(to bottom right, #ff4369 50%, transparent 0);
border-radius: 10px 0 0 0;
}
<div class="triangle">
</div>
I'm trying to use CSS and HTML to create a text underline that's curved. The curve in particular has been referred to as a "swoosh" in the design brief I was given, it needs to fall short of the first and last letter (i.e. to underline "help you", it would start at "e" and end at "o" - this part I figure is easy, applying the style to a span tag without the first and last letter), and has to have rounded ends. The swoosh is also not even.
Here's an example:
I'm not super crash hot with CSS, but I know I'm constrained to CSS and HTML in this case - no HTML5 or using javascript to get it done.
So far, I've only managed to come up with this:
.swoosh1 {
width: 500px;
height: 100px;
border: solid 5px #cb1829;
border-color: #cb1829 transparent transparent transparent;
border-radius: 50%/100px 100px 0 0;
}
Which looks like this (don't worry about the font): :(
Does anyone have any pointers? Done it before?
You can use :after pseudo-element to hold your underline:
.underlined {
position: relative;
margin-right: 1rem;
}
.underlined:after {
content: "";
position: absolute;
bottom: -10px;
left: 0;
height: 7px;
width: 100%;
border: solid 2px #cb1829;
border-color: #cb1829 transparent transparent transparent;
border-radius: 50%;
}
.small {
font-size: 60%;
}
.big {
font-size: 200%;
}
<span class="underlined">Test</span>
<span class="underlined small">Test</span>
<span class="underlined big">Test</span>
Use :after and then use border and radius and position it
Learn about pseudo:https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
.text:after{
content: "";
position: absolute;
height: 15px;
width: 70px;
left: 5px;
top: 37px;
border-top: 2px solid red;
border-radius: 50%;
}
.text{
font-family: "Comic Sans MS", cursive, sans-serif;
color:red;
}
<p class="text">Your local</p>
make sure to use : display: inline-block !important; on underlined class to be responsive.
Without : display: inline-block !important; on underlined class, it will as below on device.
.underlined {
position: relative;
display: inline-block !important;
}
.underlined::before {
content: "";
position: absolute;
bottom: -12px;
left: 0;
height: 7px;
width: 100% !important;
border: solid 8px yellow;
border-color: yellow transparent transparent transparent;
border-radius: 50%;
}
.big {
font-size: 50px;
}
<h1 class="big "> You're connected. Now, <span class="underlined "> automate!</span> </h1>
Desired Behaviour
I want to make this shape in CSS - it's a tab for a menu item.
[ example with text ]
The implementation scenario is an HTML template where CSS style sheets are switched to make color changes etc.
I want to use CSS to style the tab rather than background images so that I don't have to create a specific background image for each theme's version of a menu item tab.
What I've Tried
I looked around at some CSS shape sites and tried to pull them apart and adjust border widths etc, but haven't been able to get the desired result yet. Below are a few attempts.
.my_tab:before {
content: "";
position: absolute;
height: 0;
width: 0;
top: -45px;
left: 0px;
border-width: 0 105px 25px 0;
border-style: solid;
border-color: transparent transparent blue;
}
.my_tab {
position: relative;
width: 104px;
border-width: 20px 0 0 0;
border-style: solid;
border-color: red transparent;
top: 50px;
}
.my_tab_two {
background: purple none repeat scroll 0 0;
height: 22px;
position: relative;
top: 150px;
width: 104px;
}
.my_tab_two a {
color: white;
display: block;
font-family: arial;
margin: 0 auto;
text-align: center;
text-decoration: none;
width: 40px !important;
}
.my_tab_three {
background: green none repeat scroll 0 0;
border-radius: 0 5px 0 0;
height: 15px;
position: relative;
top: 113px;
width: 104px;
}
/* -------- */
p {
font-family: arial;
}
.para_two {
margin-top: 105px;
position: absolute;
}
<p>attempt 01:</p>
<div class="my_tab"></div>
<p class="para_two">attempt 02:</p>
<div class="my_tab_two">link
</div>
<div class="my_tab_three"></div>
<div class="my_tab_four"></div>
JSFiddle
http://jsfiddle.net/rwone/evz4d3mw/
You can create this by placing after and before pseudo-elements the after pseudo-element is skewed to make the slanted edges.
Note:This may not be the best solution i would suggest svg for this
.tab{
width:100px;
height:100px;
background:darkred;
border-top-left-radius:15px;
color:#fff;
position:relative;
padding:10px;
border-left:5px solid #000;
border-bottom:5px solid #000;
border-top:5px solid #000;
cursor:pointer;
}
.tab:after{
position:absolute;
content:"";
width:30%;
height:50%;
background:darkred;
right:-30%;
transform:skewY(45deg);
top:11%;
border-top:7px solid #000;
border-right:5px solid #000;
box-sizing:border-box;
}
.tab:before{
position:absolute;
content:"";
width:30%;
height:60%;
right:-30%;
background:darkred;
bottom:-5px;
border-bottom:5px solid #000;
border-right:5px solid #000;
box-sizing:border-box;
<div class="tab">Some text</div>
Svg solution
.tab {
width: 200px;
height: 200px;
}
<div class="tab">
<svg width="100%" height="100%" viewbox="0 0 100 100">
<path d="m5 5 l 75 0 15 15 0 60 -90 0 z" fill="darkred" stroke="#000" stroke-width="5"/>
</svg>
I couldn't find an already existing question that answers the following problem:
I have added a 300 x 300 Pixel squared png-image of a circle to my website. I am using Zurb's Foundation 5.0.2 as a CSS Grid-basis.
I would like to create a CSS-border around the circle and add an opacity-effect so that
the image is only fully visible when you hover over it with your mouse. The surrounding CSS-border and background should not be affected by this hovering-effect. Please have a look at the links to see the images.
This is my code so far:
HTML:
<div class="large-4 columns" id="border">
<div id="foto"><img src="/img/test.png" alt="Portrait" width="300" height="300"></div>
</div>
CSS:
#border #foto {
border-radius: 50%;
width: 300px;
height:300px;
background: #1ABC9C;
border: 15px solid #34495E;
}
#foto:hover {
opacity: 1.0;
}
#foto {
opacity:0.5;
}
This code correctly displays the border around the circle, but applies the hovering-effect to both, border and image:
https://www.dropbox.com/s/2r989g7d14exyfr/screenshot1.png
When I modify the CSS in the following way, it correctly applies the hover-effect only to the picture, but reduces the image size and doesn't display it centered any longer:
#border {
border-radius: 50%;
width: 300px;
height:300px;
background: #1ABC9C;
border: 15px solid #34495E;
}
https://www.dropbox.com/s/izmohri8bxkngp6/screenshot2.png?m=
Could you please advise me how to display the image correctly and apply the hover-effect as intended?
Thank you very much.
Add overflow:hidden to your border & foto div(s).
#border #foto {
border-radius: 50%;
width: 300px;
height:300px;
background: #1ABC9C;
border: 15px solid #34495E;
overflow: hidden;
}
http://jsfiddle.net/ufdM7/
Remove border from #border #foto and add overflow:hidden to it.
Write:
#foto:hover {
opacity: 1.0;
}
#foto {
opacity:0.5;
}
#border {
border-radius: 50%;
width: 300px;
height:300px;
background: #1ABC9C;
border: 15px solid #34495E;
overflow:hidden;
}
Fiddle here.
I did this way:
http://jsfiddle.net/u9LrK/1/
#foto, #foto img {
background: #1ABC9C;
border-radius:50%;
}
#foto {
border-radius: 50%;
border: 15px solid #34495E;
height: 300px;
width: 300px;
}
#foto:hover img {
cursor: pointer;
opacity: 0.5;
}
This is what you want?
I need to style box, please see attached screenshot.
Height and weight could differ. It could be 150 x 200 px but also 600
x 150 px.
Internet Explorer 8 is must. Due to this sadly no CSS3
technique could be used. IE 7 will not be supported.
Shadow is bottom and right. But if somebody know solution for four sided shadow
I´ll be also interested in.
Prefer not to use JavaScript based solution as I don´t have good experience with various libraries.
Clean construction instead of wrapping content in various divs. See
"code mockoup".
Position of arrow could differ. It could be on top, left etc.
<div class="dropdown">
<div class="leftTop"></div>
<div class="rightTop"></div>
<div class="leftBottom"></div>
<div class="rightBottom"></div>
<div class="arrow"></div>
<div class="dropdownContent">
</div>
</div>
As good start point I found zara.com solution ( expand e.g. shipping ). They use such image
Con is that background color of wrapper couldn't be changed in CSS as it is part of image. But it's not so important.
You can use rounded corners, shadows and other CSS3 features if you use CSS3 PIE. Some features are a bit cpu intensive to emulate, but it gives you a more or less CSS3 compliant IE starting from version 6.
Old post, but worth mentioning the following pure CSS3 solution. Given the following Less CSS:
// Tooltip Variables
#wcui_tt_radius: 6px;
#wcui_tt_arrow_size: 6px;
#wcui_tt_background: rgba(0,0,0,0.8);
#wcui_tt_foreground: white;
#wcui_tt_padding: 6px 10px;
#wcui_tt_font: 13px "Helvetica Neue", Arial, Helvetica, sans-serif;
#wcui_tt_z: 100;
#wcui_tt_max_width: 200px;
// Mixins
.opacity(#opacity) {
opacity: #opacity / 100;
filter: ~"alpha(opacity=#{opacity})";
}
.transition(#transition) {
-webkit-transition: #transition;
-moz-transition: #transition;
-ms-transition: #transition;
-o-transition: #transition;
transition: #transition;
}
.border-radius(#radius) {
-webkit-border-radius: #radius;
-moz-border-radius: #radius;
border-radius: #radius;
}
#arrow {
.top(#arrowWidth: 5px, #color: black) {
top: 0;
left: 50%;
margin-left: -#arrowWidth;
border-left: #arrowWidth solid transparent;
border-right: #arrowWidth solid transparent;
border-bottom: #arrowWidth solid #color;
}
.bottom(#arrowWidth: 5px, #color: black) {
bottom: 0;
left: 50%;
margin-left: -#arrowWidth;
border-left: #arrowWidth solid transparent;
border-right: #arrowWidth solid transparent;
border-top: #arrowWidth solid #color;
}
.left(#arrowWidth: 5px, #color: black) {
top: 50%;
left: 0;
margin-top: -#arrowWidth;
border-top: #arrowWidth solid transparent;
border-bottom: #arrowWidth solid transparent;
border-right: #arrowWidth solid #color;
}
.right(#arrowWidth: 5px, #color: black) {
top: 50%;
right: 0;
margin-top: -#arrowWidth;
border-top: #arrowWidth solid transparent;
border-bottom: #arrowWidth solid transparent;
border-left: #arrowWidth solid #color;
}
}
// Tooltip Styles
.tooltip {
font: #wcui_tt_font;
.opacity(0);
.transition(opacity 0.15 ease);
z-index: #wcui_tt_z;
position: absolute;
overflow: visible;
display: block;
visibility: visible;
.on { .opacity(100); }
.content {
position: relative;
overflow: hidden;
background-color: #wcui_tt_background;
color: #wcui_tt_foreground;
padding: #wcui_tt_padding;
.border-radius(#wcui_tt_radius);
max-width: #wcui_tt_max_width;
}
.arrow {
position: absolute;
width: 0;
height: 0;
margin: 0 auto;
}
&.top {
padding-top: #wcui_tt_arrow_size;
.arrow { #arrow > .top(#wcui_tt_arrow_size, #wcui_tt_background); }
}
&.bottom {
padding-bottom: #wcui_tt_arrow_size;
.arrow { #arrow > .bottom(#wcui_tt_arrow_size, #wcui_tt_background); }
}
&.left {
padding-left: #wcui_tt_arrow_size;
.arrow { #arrow > .left(#wcui_tt_arrow_size, #wcui_tt_background); }
}
&.right {
padding-right: #wcui_tt_arrow_size;
.arrow { #arrow > .right(#wcui_tt_arrow_size, #wcui_tt_background); }
}
}
It seems long, but it really isn't. The mixins get re-used throughout your Less CSS code. The HTML markup is straightforward:
<div class="tooltip left">
<div class="arrow"></div>
<div class="content">
<p>This is a sample large tooltip.</p>
</div>
</div>
All that remains is to position it and somehow add the "on" class using something like jQuery when you want it to appear. The result looks like:
Tooltip Sample http://f.cl.ly/items/2u2Z1H011p2R1h1D0B3N/tips.png