Absolute position a line under multiple lines of text - html

I have a very simple setup, whereby I add a 2px high 'line' under all my A href's, in an :after psuedo element.
The problem is that I want that line to be under each line of text within the a html tag, not just the bottom of the a.
Is there a way to make the :after appear under each line of text, rather than the text block as a whole?
I am not using text-decoration: underline; is because I want to control the look/styling of the underline and also then animate it on hover.
HTML:
Some text here that will wrap onto 2 lines because it is quite long
CSS:
a:after {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: currentColor;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}
I want the :after line to appear under BOTH lines of text, when it wraps (so appears like a common a link underline), but current it only shows under the A block as a whole...
I want:
Some text that will wrap onto 2 lines
_____________________________________
because it is quite long.
_________________________
What I get:
Some text that will wrap onto 2 lines
because it is quite long.
_____________

ok, probably not the most elegant solution, but you can try with a gradient Background:
.gradientLink{
line-height: 50px;
text-decoration: none;
color: #212121;
padding: 14px 0;
background: linear-gradient(0deg, red 1px, white 1px);
}
https://codepen.io/giannidk/pen/MZGPNX

Try this css code please.
a::after{
max-width: 50%;
border-bottom: 1px solid black;
content: '';
display: block;
}
It will set border after every a tag ,u can manually adjust the border width by changing max-width size.

Why don't you use border instead ?
a{
padding-bottom: 10px;
border-bottom: 1px solid grey;
text-decoration: none;
}

I am afraid you cannot do that with pure CSS. The only solution coming to my mind at this point is to add elements/lines to the dom using javascript:
I would advice subscribing to the 'resize' event on the window and to change the amount of your needed underlines according to the number of lines your a tag takes up.

Related

space between text and border bottom

How do I create distance between the text and the border below the text as shown in the image attached using sass/css?
I want the distance to be 5px and the font-size of the text to be 15px.
I tried doing
.selected {
color: #284660;
}
.selected:after {
content: '';
position: absolute;
width: 100%;
height: 0;
left: 0;
bottom: 5px;
border-bottom: 2px solid #284660;
}
but that created a border that was too wide.
I feel couple of things which can be improved in the above snippet.
You may not need psuedo element for desired effect
You should not use absolute positioning for that , in case you want to use psuedo element
In any case you can try this out.
&.selected {
color: #284660;
border-bottom: 2px solid #284660;
padding-bottom:10px ; // this should give you some spacing.
}
Try a negative
{
bottom: -5px;
}
Besides the complete lack of knowledge of your DOM profile or what element the & refers to, if you just slap a border and padding on an inline element, you'll have the effect you want.
No need to play with pseudoelements.
<span style="padding-bottom:5px; border-bottom:2px solid black;">Some Text</span>
Obviously, you should put that styling info in the css file, I merely inlined it for the example.
Oh and next time, please include sample HTML with your sample CSS. Only reason I even bothered was because the solution was as simple as "What is padding for 15, Trebek?"

CSS - Create a custom dotted line out divs

I want to create a line with circles. Can this be done with background-repeat? Or do I need to set a picture as background? The circles should have a 5px radius.
p:after {
content: '';
background: 'rounded div of size 10x10px' repeat-x
width: 50%;
}
This is the only solution without using background-image or border-image encoded in base64 or using external files.
https://jsfiddle.net/3r6xsr0m/
html:
<div class="line"></div>
css:
.line:before {
content: "..................................................................................................";
display: block;
font-size: 60px;
font-family: Georgia;
color: #aaa;
max-width: 100%;
overflow: hidden;
}
Dots may differ depending of browser font rendering algorithm.
You'll have to create a 10px x 10px image of the dot and then use your method of repeating the background using either pseudo or just a new element. I'd go with a new div element if you can to prevent any issues across browsers like IE8. You'll also have to give your element a width if you go pseudo.

Pseudo element takes up space in IE9

I have a div that I want to behave like an text input field.
Here's the full source code example:
HTML:
<div contenteditable='true'></div>
CSS:
div:empty:before {
content: 'Type here...';
color: #ccc;
}
div{
padding: 4px;
border: 1px solid #ccc;
}
See the fiddle in IE9.
In IE9, the problem is that the keyboard caret is displayed at the end.
In Chrome, the caret is at the beginning, which is correct.
It seems like the problem is that the pseudo :before element is taking up space in IE9. How can I make it take up no space like it does it Chrome (behave like a placeholder)?
To make it work in IE:
div:empty:before {
content: 'Type here...';
color: #ccc;
display: inline-block;
width: 0;
white-space: nowrap;
}
display: inline-block makes it possible to set a width.
width: 0 makes sure that the element does not take up space.
white-space: nowrap forces the text to be in one line (would break lines otherwise because of the limited space)
updated fiddle

Button hover effect pulls up paragraph beneath

I'm trying to create a fancy button hover state for the default button in Bootstrap 3. Basically, the button starts out with 4px of border-bottom and when hovered this reduces to 2px. Because of this, I compensate with top: 2px on the button.
This works fine, however it's affecting other elements which I don't want it to do. For example, it pulls the paragraph beneath it up. Here's a JSFiddle example:
http://jsfiddle.net/kD6dQ/
You can see when you hover over the button the paragraph below changes position. How do I stop that?
I've tested this in the latest versions of Chrome and Firefox.
You used top for your element. When changed to margin-top it works.
fiddle
css:
.btn-default:hover {
background: #eba22b;
color: white;
border-bottom: 2px solid #db9016;
margin-top: 2px;
}
Try this for the hover declaration:
.btn-default:hover {
background: #eba22b;
color: white;
border-bottom: 2px solid #db9016;
top: 2px;
margin-bottom: 2px;
}
Check this fiddle: http://jsfiddle.net/kD6dQ/1/
The best way to solve this is to simply add height to .btn-default
E.G: height: 35px;
DEMO HERE

Double borders in CSS

I'm creating PHP, Javascript based photo-gallery from scratch
The problem is, I want to make difference between simple picture and photo-album.
So simple picture borders look like that
Is that possible to create facebook like photo-album borders (double borders, which creates multiple images effect) via css or CSS3?
P.S Don't know if it will be possible with old css standarts. I mean, CSS3 probably can do it but it will not be backward compatible. In other hand, currently my php side generates 100x100 px thumbs. I need something that will not be ruined if I will increase size of thumbs.
Thx in advance
Use a pseudo element like :before or :after, for example:
Turns out, most browsers don't like :before on images because it's not a text-containing element. You could still do this if you did it on an alternative element, like a div, and set the div's background to the original image. Or, you could try:
http://jsbin.com/otivaj/edit#html,live
Is this what you're looking for?
jsfiddle
HTML:
<div class="facebook-album"></div>
CSS:
.facebook-album, .facebook-album:before
{
background: red;
width: 100px;
height: 100px;
margin: 20px;
border: 3px solid #FFF;
box-shadow: 0 0 0 1px #999;
position: relative;
}
.facebook-album:before
{
margin: 0;
content: "";
position: absolute;
top: -7px;
left: -7px;
background: white;
z-index: -1;
}
You could just look at Facebook's source to figure it out. This will also work:
http://jsfiddle.net/g9A6a/
Yep, you can definitely do this with CSS. It looks like all your images are the same size, too, which will make this very straightforward. Simply place your <img> inside a containing element with position: relative; and an offset. Both the container and image should have a border, with padding and offsets you so desire. Set the width and height of the containing element based off the child image's dimensions.
Here is a
DEMO on jsfiddle
I'm not sure you can achieve that effect with simply CSS2. If adding more markup is an option, I would do something like this:
<ul>
<li><img></li>
</ul>
li {
position: relative;
border: 1px solid gray;
}
img {
padding: 6px;
border: 1px solid gray;
position:absolute;
top:6px;
left: 6px;
background-color:white;
}