How to underline a text (with full width) using CSS - html

I've this html code:
<a class="jstree-anchor jstree-disabled textualstatements-jstreenode-parent" href="#" tabindex="-1" id="td72383_anchor"><i class="jstree-icon jstree-themeicon fa fa-folder jstree-themeicon-custom" role="presentation"></i>My example text</a>
And this CSS:
.textualstatements-jstreenode-parent {
text-decoration: underline !important;
text-decoration-color: #2eaaa1 !important;
text-decoration-thickness: 2.5px !important;
text-underline-offset: 2px !important;
font-weight: bold;
width: 100%;
}
And this is rendered like:
However, I want the green line to be expanded using the full width from the block, can this be done using text-decoration?

Instead of underline, create bottom border,
border-bottom:1px solid #000;

Use border.
p{
border-bottom: 2px solid black;
}

Put it in a div and set the bottom-line to green.
div {width: 100%; border-bottom: 1px solid #2eaaa1;}
Or if you perse want to underline, you can expand the a text with spaces: a lot of & nbsp;.

This solution works for me.
Here is an explanation already on stackoverflow CSS Styling text areas like notebook-look
.textualstatements-jstreenode-parent {
font-weight: bold;
width: 100%;
border-bottom: solid #2eaaa1 2.5px;
display: inline-block;
}
<a class="jstree-anchor jstree-disabled textualstatements-jstreenode-parent" href="#" tabindex="-1" id="td72383_anchor"><i class="jstree-icon jstree-themeicon fa fa-folder jstree-themeicon-custom" role="presentation"></i>My example text</a>

You are trying to make width 100% for an anchor tag which is an inline element.
width:100% will not have any effect unless the element is block or inline-block.
Try this
.textualstatements-jstreenode-parent {
text-decoration: underline !important;
text-decoration-color: #2eaaa1 !important;
text-decoration-thickness: 2.5px !important;
text-underline-offset: 2px !important;
font-weight: bold;
width: 100%;
display: block;
}

Related

Remove underline for an image inside a link - SCSS

How do I get rid of the underline for the image inside the link in SCSS. Could anyone please help?
I created a working example using CodeSandbox
HTML
<p>
<a href="#">
Link
<span>
<img src="imagePath" alt="logo" />
</span>
</a>
</p>
SCSS
a {
text-decoration: none;
&:hover{
border-bottom: 1px solid red
}
}
As yiu can't alter the HTML, this snippet puts the underline on a pseudo element rather than on the actual element. The pseudo element is made to have the same width as the text ('Link') by using that as its content - which is slighly nasty as it means if the text of the Link changes the CSS/SCSS will also have to change.
a {
text-decoration: none;
position: relative;
}
a:hover::before {
content: 'Link';
position: absolute;
top: 0;
left: 0;
width: auto;
height: 100%;
border-bottom: 1px solid red;
z-index: 1;
}
<p>
<a href="#">
Link
<span>
<img src="imagePath" alt="logo" />
</span>
</a>
</p>
Try to put background color on span border-bottom:
body {
font-family: sans-serif;
}
a {
text-decoration: none;
border-bottom: 1px solid transparent;
}
a:hover{
border-bottom: 1px solid red;
}
a:hover span {
border-bottom: 1px solid white;
}
<div id="app">
<p>
<a href="#">
Link
<span>
<img
width="10"
src="https://bitsrc.imgix.net/3b69976526d31a20a1fd238f5a32a704cf437dd6.png"
alt="logo"
/>
</span>
</a>
</p>
</div>
We'll thats tricky and also not the best practices when it comes to frontend buuutt
Since you know the size of the image, you can add a fake border-bottom with the pseudo:after element with width 100% - [width-of-the-element]:
a {
text-decoration: none;
position:relative;
&:before{ // we initialize it before showing to avoid creating elements on interaction
position:absolute;
content:'';
left:0;
bottom:-2px;
border-bottom:1px solid red;
width:calc(100% - 10px - 0.2em); // the image is 10px and the space bar is ~0.2em
display:block;
opacity:0; // just some nice transitioning
transition:all .5s ease;
}
&:hover{
//border-bottom: 1px solid red;
&:before{
opacity:1;
}
}
}
<p>
<a href="#">
Link
<span>
<img
width="10" src="https://bitsrc.imgix.net/3b69976526d31a20a1fd238f5a32a704cf437dd6.png" alt="logo"
/>
</span>
</a>
</p>
Check here a working sample
There's a few different ways to do it but here's one that doesn't change your HTML flow. Since the image is inside the <a> and the border is being applied to the <a>, you can move the img outside the bounds of the <a> with positioning so it doesn't affect the width of the element and thus the border.
a
{
text-decoration: none;
position: relative;
&:hover{
border-bottom: 1px solid red;
}
img
{
position: absolute;
left: 100%;
padding-left: 5px;
padding-top: 3px;
}
}
The left is to push it to the outside of the element on the right side, and the padding-left and padding-top are to put it in roughly the same position it was in your sandbox.
Updated sandbox
An alternative would be to wrap the text inside the <a> in their own element, like a span, and then apply the border just to the span.
I would recommend wrapping your anchor text inside the span and using CSS to underline that. One thing to keep in mind is that border is going to add to the elements height and will cause a "jumping" effect when you add/remove the border. I would go about making sure a border is always present, but "hidden" when it's being hovered over. You can do this by either using "transparent" as a color or match the color with the background hex value.
https://codesandbox.io/s/cocky-rgb-6he0j
<p>
<a href="#">
<span>Link</span>
<img src="imagePath" alt="logo" />
</a>
</p>
body {
font-family: sans-serif;
}
a {
position: relative;
&, &:hover, span {
text-decoration: none;
}
span {
border-bottom: 1px solid transparent;
}
img {
position: absolute;
left: 100%;
padding-left: 5px;
padding-top: 3px;
}
&:hover span {
border-bottom-color: red;
}
}
EDIT: updated code formatting and added missing body styles

How to put a line on top of text in html?

So I want to try to do this in html and css but I can't seem to find anything. I only way I can think is by importing the text as an image but that will look bad. P.S Light blue line is for centering as I am designing the site in Photoshop first
<p class="test">
Conact Me
</p>
.test {
border-top-style: solid;
border-bottom-style: solid;
border-bottom-width: 1px;
}
A simple solution is using text-decoration: underline overline;.
p {
text-decoration: overline underline;
}
<p>
CONTACT ME
</p>
You can use border-top in css to create a line above text.
.mytextbox {
border-top: 1px solid #ff0000;
}
border-top property
Example of use
Try using borders to achieve the look you are wanting:
a.my-class {
display: inline-block;
padding: 5px 15px;
border-top: 2px solid #000;
border-bottom: 2px solid #000;
line-height: 1em;
text-decoration: none;
}
Well, you'd want to have the text element within a div, set the bg color property of the div to the color you're going for, and then set margins for the text element to push off the text by ~10px or so (looks like that's about where it's at in your mock up). From there you can set a border to only top, and bottom and style accordingly.
You can put the text inside a block level element and apply a top and bottom border. Advantage of this method against the text-decoration: underline overline; is, that you can simply define the space between text and lines with padding as you need it.
To make the width as long as the text is, just use display: inline-block;.
body {
background: #5cc8f6;
}
div {
display: inline-block;
padding: .5em;
border-top: 1px solid white;
border-bottom: 1px solid white;
color: white;
text-transform: uppercase;
font-family: Verdana;
font-size: 2em;
}
<div>Contact me</div>

Different border bottom for links with bold text

On this page (http://nate.fm/testing/) you can see that the text link's bottom border gets pushed down. Can anyone tell me where I can change that in the CSS?
You can set the <a> tag to display: inline-block; then reduce the line-height.
Something like this maybe:
.post-content a {
line-height: 15px;
display: inline-block;
}
.post-content a {
/* border-bottom: 3px solid #eee; */
text-decoration: underline;
}
They are using border-bottom along with line-height, the line-height property causes the effect of "pushing" down the border you are mentioning
.post-content a {
border-bottom: 3px solid #eee;
line-height: 160%;
}

removing strange clickboxes on image-link

I'm using bootstrap to make some buttons containing images.
But when I click them, a strange horizontal line appears, as well as a dotted bounding box on FF.
i have tried outline: none;,but it doesn't change anything...
how can i re-arrange the html (or edit the css) to fix this? I don't want those boxes (especially the horizontal one in the middle)
thanks
html
<div class="button frontbutton col-md-4">
<a href="/tips">
<img src="url.png" class="buttonPic">
<span data-i18n="buttons.tips">Tips</span>
</a>
</div>
css
.frontbutton {
padding: 15px;
}
.button {
display: inline-block;
color: #444;
border: 1px solid #CCC;
background: rgba(210, 210, 210, 0.62);
box-shadow: 0 0 5px -1px rgba(0,0,0,0.2);
margin: 0px;
cursor: pointer;
vertical-align: middle;
text-align: center;
}
a {
color: #199ACE;
outline: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
img.buttonPic {
width: 95%;
}
thanks
https://jsfiddle.net/pLkyqz0x/
UPDATE
while making the fiddle, i noticed what caused the gray bar (box shadow on a:active)
but the red box on FF remains....
This is the a:focus { } style. So you can remove it by setting a:focus { outline: none; } however this is not considered best practice as the focus style is an accessibility requirement. You should instead redefine focus styles that work for you. (For further reading on why this is bad practice: http://www.outlinenone.com/)

Lower space between text and border

My HTML
<div id="ctl00_cphBreadCrumb_TDDF5635D005_ctl00_ctl00_Breadcrumb" class="RadSiteMap RadSiteMap_Sitefinity">
<li class="rsmItem sfBreadcrumbNavigation">
<a class="rsmLink" href="default">Default</a>
<span class="arrow"> ></span>
</li>
<li class="rsmItem sfNoBreadcrumbNavigation">
<span style="color: #999;font-family: myriadpro-bold-webfont;font-size: 10px;">Services</span>
</li>
</ul>
</div>
CSS:
.rsmLink {
position: relative;
text-decoration: none !important;
color: #044470 !important;
border-bottom: 1px solid #044470 !important;
font-family: myriadpro-bold-webfont !important;
font-size: 10px !important;
padding: 0 !important;
letter-spacing: 1px;
}
But I am getting some space between link and border. If I use underline instead of border it is not that much below as expected. I want space between what border is giving and what underline is giving. And border should be little less in size than it is. Could you please help me?
Fiddle
Thanks.
It's much of a muchness between text-decoration and border-bottom, but you could try using a pseudo element like this:
.rsmLink:before
{
content: '';
position:absolute;
bottom:0;
width: 100%;
height: 1px;
background: #044470;
}
FIDDLE
If that's not exactly what you need, you could play with the bottom rule ... say bottom:-1px .
The results looks similar to border-bottom but hey, i'll let you do the squinting.
Just Added line-height: 11px; and its done. Thanks for your time dears.