How to make text underline css - html

I have two <a> tags and I need them to be underlined like this:
(notice that I can't use border-bottom: dashed 10px because lines are thin but the space between them is quite big.
HTML:
text1
text2
CSS:
.t1 {
color: #8bb09e;
}
.t2 {
color: #ffee90;
}

There is 2 approaches, but this approach would be the usage of the border-bottom: value;
.t1 {
border-bottom: 1px dashed #333;
}
If you want to use some other style that isn't going to happen. Like the space you're talking about. Then you're more likely to be using an image for the bottom border and create a border-like-effect.

If you can give the anchor a position:relative attribute, I would use an absolutely positioned pseudo element. You can use a background image or a linear gradient like I did in my demo
Demo: http://jsfiddle.net/6Jzu6/1
a {
position: relative;
...
display: block;
...
}
a:after {
content: '';
position:absolute;
height: 1px;
width: 100%;
top: 100%;
left: 0;
background-image: -webkit-linear-gradient(left, transparent 50%, #8b0 50%);
background-image: -moz-linear-gradient(left, transparent 50%, #8b0 50%);
background-image: -ms-linear-gradient(left, transparent 50%, #8b0 50%);
background-image: -o-linear-gradient(left, transparent 50%, #8b0 50%);
background-image: linear-gradient(left, transparent 50%, #8b0 50%);
background-size: 20px 20px;
}
Edit: Oops! credit where credit is due. I got the linear gradient concept from this source

This is all you need :)
.t1 {
display:inline-block; /* make width equal to link content */
padding-bottom:5px; /* margin between underline and text*/
border-bottom:1px dashed red; /* height type and color of underline */
}
Edit
What you need is an addition of min-width property added to your <a> styles.check the demo
Demo

Here's a method I've used in the past. It uses a pseudo element that acts as a border.
http://jsfiddle.net/h7Z9K/
p {
display: inline-block;
position: relative;
}
p::after {
content: "";
display: block;
width: 100%;
border-bottom: 1px dashed #000;
position: absolute;
left: 0;
bottom: -0.5em;
}
Adjust the position of the pseudo element border relative to the element by adjusting its bottom position.

.t1 {
color: #8bb09e;
border-bottom-style: dashed !important;
width:30%;
text-align:center;
display:inline-block;
}
.t2 {
color: #ffee90;
text-align:center;
border-bottom-style: dashed !important;
float:right;
width:30%;
}
text1
text2

Related

How to scale a triangle with rectangle content in css?

I have created a triangle with a border and a coloured background. However it is attached to a rectangle with some content and i can't figure out how to scale the triangle with it.
I have used a pseudo element and put a triangle on top of another triangle to create the border, so not sure if this way is possible to scale with.
My problem is the triangle
HTML:
<div class="skipcontent">
<i class="bi bi-skip-end-circle" style="font-size:36px;"></i>
<p class="alertcontent">content can span onto 2 lines. content can span onto 2 lines. content can span onto 2 lines. content can span onto 2 lines. </p>
</div>
</div>
Here is my CSS:
.container {
width: 700px;
height: 100%;
background: #D9F1FF;
border: 1px solid #7197C9;
position: relative;
color: #000000;
font-size:15px;
border-radius: 5px;
font-family: Arial,Helvetica,sans-serif;
}
/* this CS forms the triangles */
.container:after,
.container:before {
content: '';
display: block;
position: absolute;
left: 100%;
width: 0;
height: 0;
border-style: solid;
}
/* this border color controls the color of the triangle (what looks like the fill of the triangle) */
.container:after {
top: 0px;
border-color: transparent transparent transparent #D9F1FF;
border-width: 26px;
margin-left:-2px;
}
/* this border color controlls the outside, thin border */
.container:before {
top: 0px;
border-color: transparent transparent transparent #7197C9;
border-width: 26px;
margin-left:-1px;
}
.skipcontent {
padding:0 0 0 20px;
display:flex;
align-items:center;
}
You can do it easily by using "Clippy - clip-path". But you can't add the border and border-radius on everywhere.
Reference site link - https://bennettfeely.com/clippy/
Demo Screenshot - https://prnt.sc/-J3_o3rHqlFU
.skipcontent {
color: #ffffff;
background: red;
border-radius: 5px;
padding: 20px 40px;
clip-path: polygon(50% 0%, 97% 0, 100% 28%, 97% 50%, 97% 100%, 0 100%, 0% 35%, 0 0);
}

Style nav button with css shap with gradient, gradient background, and centered text

So I'm trying to make a nav buttons without using a image. But I can't get the CSS to work out properly. I managed to get everything but the vertical alignment of the text, yet to get that far I feel the code as become more sloppy than necessary. Here is what I have:
.nav_button {
height: 18px;
background: linear-gradient(#3D3C3B 0%, #0A0B0A 50%);
margin-top: 5px;
}
.arrow_container {
display: inline-block;
width: 35px;
}
.nav_arrow {
width: 20px;
height: 18px;
background: linear-gradient(#D2DA76 0%, #5EB649 50%);
}
.nav_link {
display: inline-block;
width: 125px;
text-align: center;
}
.nav_arrow::after {
display: block;
content: '';
height: 18px;
width: 20px;
background: linear-gradient(to bottom right, #D2DA76 0%, #5EB649 50%);
transform: translate(10px, 0px) scale(.8, .715) rotate(45deg);
}
<a href='#'>
<div class='nav_button'><span class='arrow_container'><div class='nav_arrow'></div></span><span class='nav_link'>Test</span></div>
</a>
Is there a better way to write this? if not I at least need to know how to vertical align the text. line-height did not work.
Edit: Here is a demo pic. the arrow is backwards but it's close.
A better solution may be to actually build your button's structure relative to the size of the text's line-height, rather than trying to hardcode the size and then update the line-height secondly.
The simplification of the html is based upon the idea that we use a single gradient overlay on the button rather than fading both the button background and the "arrow" section with different colours independently. However, this doesnt exactly match the design.
.nav_button_alt{
display:inline-block;
border:1px solid #888;
color:#FFF;
text-decoration:none;
font-family:Helvetica, Arial, sans-serif;
position:relative;
background:#5EB649;
font-size:1.2em;
line-height:1.4em;
padding:0 0.2em 0 40px;
min-width:125px; /* remove this if you wish the buttons to be relative to the size of the text*/
}
.nav_button_alt > span{
display:inline-block;
position:relative;
width:100%;
z-index:3;
text-align:center;
}
/* provides the fade */
.nav_button_alt:before{
content:"";
position:absolute;
top:0;
left:0;
right:0;
z-index:2;
height:100%;
background-image: linear-gradient(rgba(255,255,255,0.6) 0%, rgba(255,255,255,0) 50%);
}
/* provides the "black" overlay of the green background */
.nav_button_alt:after{
content:"";
position:absolute;
left:1.2em; /* distance from the right that the arrow starts */
top:0;
height:0;
right:0;
border-left:1em solid transparent; /* size of the green arrow's point */
border-top:0.7em solid #000; /* half the height of the button */
border-bottom:0.7em solid #000; /* half the height of the button */
z-index: 1;
}
<a href="#" class="nav_button_alt">
<span>Test</span>
</a>
Try vertically aligning the text inside the button.
.nav_button {
height: 18px;
background: linear-gradient(#3D3C3B 0%, #0A0B0A 50%);
margin-top: 5px;
}
.arrow_container {
display: inline-block;
width: 35px;
}
.nav_arrow {
width: 20px;
height: 18px;
background: linear-gradient(#D2DA76 0%, #5EB649 50%);
}
.nav_link {
display: inline-block;
width: 125px;
text-align: center;
vertical-align:top;
}
.nav_arrow::after {
display: block;
content: '';
height: 18px;
width: 20px;
background: linear-gradient(to bottom right, #D2DA76 0%, #5EB649 50%);
transform: translate(10px, 0px) scale(.8, .715) rotate(45deg);
}
<a href='#'>
<div class='nav_button'><span class='arrow_container'><div class='nav_arrow'></div></span><span class='nav_link'>Test</span></div>
</a>
Use "line-height" for vertical alignment of text. Here's an example
div {
height: 90px;
line-height: 90px;
text-align: center;
border: 2px dashed #f69c55;
}
<div>
Hello World!
</div>

Button with partial border on top and bottom

Hi all,
I would like to insert a <button> in my code that has a gap in border-top and border-bottom. I have seen some examples where it is possible to remove a part with it, but it's not exactly what I am looking for. Do you have an idea on how to get something like the above mentioned picture?
Thanks in advance for your replies!
EDIT:
I add more information: the best is that the background of the button is transparent and that the border-size is customisable.
Use pseudo elements
.brd {
font-size: 30px;
padding: 4px 20px;
position: relative;
border: none;
background-color: white;
}
.brd:before,
.brd:after {
content: ' ';
position: absolute;
border: 1px solid black;
top: 0;
bottom: 0;
width: 10px;
}
.brd:before {
border-right: 0;
left: 0;
}
.brd:after {
border-left: 0;
right: 0;
}
<span class="brd">Title</span>
<button class="brd">Title</button>
Another possible solution is to use gradient as border-image. Look at the snippet below
.box{
display:inline-block;
margin: auto;
padding: 10px;
border: 3px solid transparent;
-moz-border-image: -moz-linear-gradient(to right, #aaa 10%, #fff 10%, #fff 90%, #aaa 90%);
-webkit-border-image: -webkit-linear-gradient(to right, #aaa 10%, #fff 10%, #fff 90%, #aaa 90%);
border-image: linear-gradient(to right, #aaa 10%, #fff 10%, #fff 90%, #aaa 90%);
border-image-slice: 1;
}
<div class="box" >TITLE HERE</div>
If you want the top and bottom border parts to be exactly X pixels, you can change the percents with pixels like this:
border-image: linear-gradient(to right, #aaa 20px, #fff 20px, #fff calc(100% - 20px), #aaa calc(100% - 20px));
A simple way would be using a custom made image as the background of your button, tho it wouldn't scale well on different screen sizes.
Another idea would be to have a div underneath with a normal border, and then your smaller button on top of it, with the same height and a white border, so as to hide the top and bottom part.
I've created a JSFiddle for you: enter link description here
HTML:
<div class="back-with-border">
<div class="front-no-border">
Title Here
</div>
</div>
CSS:
.back-with-border{
border:1px solid gray;
width:200px;
height:100px;
position: relative;
}
.front-no-border{
display:flex;
justify-content:center;
align-items:center;
border:0px;
background-color:white;
position: absolute;
width:110px;
height:110px;
top:-1px;
left:45px
}
Check this [JSFiddle][1], hope this will solve your problem
body {
background-color: white;
}
.parent {
border: 1px solid black;
width: 200px;
height: 100px;
position: relative;
background-color: white;
}
.child {
display: flex;
justify-content: center;
align-items: center;
border: 0px;
background-color: white;
position: absolute;
width: 150px;
height: 103px;
top: -1px;
left: 25px
}
<div class="parent">
<div class="child">
Write your text here
</div>
</div>
[1]: https://jsfiddle.net/anshul24mehta/eocst0uv/3/

Right banner arrows purely in CSS

I'm trying to recreate these arrows in CSS for a website I'm redesigning to be responsive. These two guys were done with static images but I'd like them to be pure CSS.
This is a sprite that was used for mouseover replacement. The bottom is the mouseover state. The background behind the arrow needs to be transparent.
I thought it would be a simple div with a p or heading tag inside:
<div class="arrow_box">
<p>UTILITIES</p>
</div>
I've searched for examples everywhere and everything I've tried to modify never lets me seem to have full control of the width and height of the element. The width (with the arrow) is 114px. The height (of a single state) would be 29px.
I've played with this for the better part of an hour trying to get it properly sized but nothing seems to work. http://codepen.io/anon/pen/bpBGQL My lack of knowledge on how this works is partially to blame.
So the trick, here, is being able to control the height correctly. Here, I've got the text in a span with a line-height : 0, and padding:15px. Now, we have precisely 30px of height, and can use an ::after pseudo element to fabricate the arrow. The width will be set by the text content, but can be defined with an explicit width rule, as well.
<div class="arrow"><span>text</span></div>
.arrow{
display:inline-block;
height:auto;
background-color:orange;
}
.arrow span{
display:inline-block;
line-height:0;
padding:15px;
color:white;
}
.arrow::after{
width: 0;
height: 0;
position: absolute;
right:0
top: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid orange;
content: "";
}
Add whatever colors / hover states you require. You can see some basic rules in the working fiddle.
Fiddle
You can do this with :after pseudo element. You can change color of pseudo element on hover state like this .arrow_box:hover:after
* {
box-sizing: border-box;
}
p {
margin: 0;
padding-left: 10px;
}
.arrow_box {
background: #627680;
display: block;
color: white;
position: relative;
height: 30px;
line-height: 30px;
width: 114px;
transition: all 0.3s ease-in;
}
.arrow_box:after {
content: '';
height: 0;
width: 0;
position: absolute;
top: 0;
right:0;
transform: translateX(100%);
border-bottom: 15px solid transparent;
border-top: 15px solid transparent;
border-left: 20px solid #627680;
border-right: 15px solid transparent;
transition: all 0.3s ease-in;
}
.arrow_box:hover {
background: #2A92C2;
}
.arrow_box:hover:after {
border-left: 20px solid #2A92C2;
}
<div class="arrow_box">
<p>UTILITIES</p>
</div>
did you consider gradient backgrounds ?
body {
background: linear-gradient(45deg, gray, lightgray, gray, lightgray, gray, lightgray, gray, lightgray, gray, lightgray, gray, lightgray);
/* demo purpose only */
}
.arrow {
text-transform: uppercase;
/* optionnal */
padding: 3px 1.5em 3px 0.5em;
color: white;
background: linear-gradient(225deg, transparent 0.6em, #627680 0.6em) top no-repeat, linear-gradient(-45deg, transparent 0.6em, #627680 0.6em) bottom no-repeat;
background-size: 100% 50%;
/* each gradient draws half of the arrow */
}
.arrow:hover {
/* update gradient color */
background: linear-gradient(225deg, transparent 0.6em, #2A92C2 0.6em) top no-repeat, linear-gradient(-45deg, transparent 0.6em, #2A92C2 0.6em) bottom no-repeat;
background-size: 100% 50%;
}
<span class="arrow"> Utilities</span> <span class="arrow"> testing</span>
You may also want to take a look at Responsive Arrow Breadcrumb Navigation for breadcrumbs and imbricated arrows or Create dynamic arrow-like shape with CSS
Does this pen provide what you need?
http://codepen.io/anon/pen/dMOPmV (may require some pixel pushing to get it perfect)
It just required adjusting:
border-width: 27px;
margin-top: -35px;
and adding a hover state for the main element and before element.

Is it possible to progressively taper a CSS 'border-right' like a needle?

Edit: *old question was using images which have since expired; rewritten the same question.
I am needing to progressively taper a line in css to sub-single pixel widths. This is to mimic a design which was handed to me, imagine a single-side border with 2px width progressively thinning along a line until it's nothing.
Any tips are much appreciated!
Here, a quick example (live demo):
HTML:
<nav id="main-nav">
Link 1
Link 2
Link 3
Link 4
Link 5
</nav>
CSS:
#main-nav {
padding: 40px 20px;
width: 150px;
position: relative;
}
#main-nav a {
display: block;
}
#main-nav:after {
content: '';
position: absolute;
right: 0;
top: -10%;
width: 1px;
height: 120%;
background-image: linear-gradient(to top, #666 75%, transparent);
}
#main-nav:before {
content: '';
position: absolute;
left: -10%;
top: 0;
width: 120%;
height: 1px;
background-image: linear-gradient(to right, #666 75%, transparent);
}
You could use this. This is only any use if you a) are happy with CSS only and b) don't want any content in the div.
Think of the border-top and border-left as sort x and y coordinates.
By specifying a width and height of 0px, it allows you to shape the div purely using your borders:
div {
width:0px;
height:0px;
border-left:solid 5px rgba(0,0,0,0);
border-top:solid 50px rgba(0,0,0,0);
border-right:solid 5px blue;
border-bottom:solid 50px blue;
}
Bear in mind that this approach only allows linear tapering.