I'm having trouble figuring out how to apply a split border on an element using CSS.
The effect I'm trying to achieve is this:
Where the red line and the grey line take up a % of the elements width. Preferably, I would like to apply this effect to an element using a single class.
Edit: for those asking for a code sample:
<!-- spans width 100% -->
<div id="wrapper">
<h1 class="title">DDOS Protection </h1>
</div>
Red text and a red underline? There's some simple CSS for this.
<span style='color:red; border-bottom: 1px solid red;'>DDOS</span>
<span style='color:#999; border-bottom: 1px solid #999;'>Protection</span>
Well, assuming that you want to use a single class, and without seeing your exact markup, this will work:
<div class="message">
<span>DDOS</span>
<span>Protection</span>
</div>
And then your CSS could look like this:
.message span {
border-bottom: 1px solid #ccc;
padding-bottom: 5px;
color: #ccc;
}
.message span:first-child {
border-bottom-color: red;
color: red;
margin-right: 10px;
}
Here's a jsFiddle demo.
You can also try to play with :before and :after:
.line {
background-color: #DDD;
padding: 5px 10px;
position: relative;
}
.line:before, .line:after {
content: '';
width: 10%;
height: 2px;
background-color: red;
position: absolute;
bottom: 0;
left: 0;
}
.line:after {
width: 90%;
background-color: green;
left: 10%;
}
http://jsfiddle.net/DHDuw/
Ok I've made a similar one but that was asked for vertical, but now am changing the gradient direction so that it will help you
Demo (Works On Chrome, If Anyone Knows Cross-Browser, Please Feel Free To Edit, Because Am Using Old Browsers So Won't Be Able To Test)
CSS
div {
font: 40px Arial;
background: -webkit-gradient(linear, left top, right top, color-stop(0%,#ff0505), color-stop(50%,#ff0000), color-stop(50%,#000000), color-stop(100%,#000000));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
Related
I would like to have a colored underline that looks like this when it breaks:
text-decoration-color seems to be not supported widely enough.
I tried this:
.underline {
position: relative;
}
.underline:after {
position: absolute;
content: '';
height: 1px;
background-color: #ffc04d;
bottom: .1rem;
right: 0;
left: 0;
z-index: -1;
}
<h1><span class="underline">Sprouted Bread</span></h1>
What about a linear-gradient where it will be easy to control color, size and distance within a single element:
.underline {
position: relative;
font-size:28px;
background:
linear-gradient(yellow,yellow) /* Color */
left 0 bottom 2px/ /* Position */
100% 2px /* Size (width height)*/
no-repeat;
}
<div style="width:150px;text-align:center"><span class="underline">Sprouted Bread</span></div>
As a side note, border-bottom works fine used with inline element but of course you cannot easily control the distance to make it behave as a text-decoration:
.underline {
position: relative;
font-size:28px;
border-bottom:2px solid yellow;
}
<div style="width:150px;text-align:center"><span class="underline">Sprouted Bread</span></div>
Try this JSFiddle
By wrapping the elements like you have in a span. You can put the text decoration on the parent element and the text color on the span.
HTML:
<h1><span class="underline">Some Text</span></h1>
CSS:
h1 {
text-decoration: underline;
color: red;
}
.underline {
color: blue;
}
Just add a border!
Using display: inline, add a bottom border and space it with padding.
You could also use line-height and then place negative margins to increase the space in between the lines.
And...you could also animate it!
.underline {
position: relative;
padding-bottom: 1px;
border-bottom: 1px solid #ffc04d;
}
<h1 style="width: 5em">
<span class="underline">Sprouted Bread</span>
</h1>
As mentioned by #chriskirknielsen, you could use box-decoration-break, although not supported by IE or Edge. Credits: #Temani Afif
How can I add an underline to an inline-element in CSS, that is (1.) "stylable" and (2.) at the baseline (unlike solutions using only border-bottom or box-shadow)?
This is for a responsive layout, so the underline has to be able to reach over multiple lines. Also, it cannot displace any other (not underlines) text that might be inline with the link.
This is a mock-up to demonstrate the desired effect.
Thanks in advance!
I think you'd want to use a pseudo element to style your underline. I threw a simple animation too on hover to showcase its flexibility.
h1 {
position: relative;
}
h1::before {
content: "";
position: absolute;
left: 0;
bottom: 5px;
z-index: -1;
background: aqua;
height: 2px;
width: 200px;
transition: width 0.3s;
}
h1:hover::before {
width: 300px;
}
<h1>This is a styleable baseline</h1>
I don't know why you aren't able to use border-bottom but try this:
<!DOCTYPE html>
<html>
<style>
</style>
<body>
<a><u>LINK OVER </u><br><u>MULTIPLE</u> LINES</a><br><br>
<a><span style="border-bottom: blue solid 3px;">LINK OVER
<br>MULTIPLE</span> LINES</a><br><br>
<a><span style="text-decoration: underline; text-decoration-color:
blue;">LINK OVER<br>MULTIPLE </span> LINES</a>
</body>
</html>
For everyone interested, this is the solution I came up with. It only works on a solid background.
background: linear-gradient(white, white), linear-gradient(blue, blue);
background-position: 0px calc(1em + 5px), 0px 1em;
background-repeat: repeat-x;
color: black;
background-color: white;
I can't figure out how to write HTML code for the picture below:
The CSS looks like this:
.borderbox {
border-style: dashed;
border-width: 2px;
border-color: #d3d3d3;
position: absolute;
height: 90%;
width: 90%;
top: 0;
left: 0;
margin: 5%;
}
h3.header-3 {
font-size: 130px;
text-align: center;
color: #00a0df;
margin: 4px auto 17px;
}
p.paragraph-text {
font-size: 20px;
text-align: center;
color: #00a0df;
text-transform: uppercase;
font-family: HelveticaNeueBold;
}
The text is <p> visa fler bästsäljare </p> <h3>+<h3>.
The code I have gotten help with so far is:
<body>
<div class="borderbox">
<h3 class="header-3">+</h3>
<p class="paragraph-text">visa fler bästsäljare</p>
</div>
</body>
The only issue is that this code does not create the image as I posted. URL to the website URL. Scroll down a bit. The browser I am testing this on is Google Chrome.
remove the
.borderbox {
height: 90%;
}
then the dashed border should work as you expected.
I think this might be a solution: http://jsfiddle.net/e7Levykn/
I don't think you can style border with one argument. You would have to use
border-style , border-color, border-width.
EDIT: Nvm about the border thing. Your css-code should work, it works in the jsfiddle. Maybe your elements in html don't have the right classes
Use css border-style property.
.selector{
border-style: dashed;
}
or like this
.selector{
border:2px dashed #F1F1F1;
}
For an example, check out this fiddle (not in IE, please).
(You can see a description of the control at this link.)
She uses -ms-fill-lower and -ms-fill-upper to control the color on either side of the thumb, like this:
input[type=range]::-ms-track {
width: 300px;
height: 5px;
/*remove bg colour from the track, we'll use ms-fill-lower and ms-fill-upper instead */
background: transparent;
/*leave room for the larger thumb to overflow with a transparent border */
border-color: transparent;
border-width: 6px 0;
/*remove default tick marks*/
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #777;
border-radius: 10px;
}
input[type=range]::-ms-fill-upper {
background: #ddd;
border-radius: 10px;
}
input[type=range]::-ms-thumb {
border: none;
height: 16px;
width: 16px;
border-radius: 50%;
background: goldenrod;
}
input[type=range]:focus::-ms-fill-lower {
background: #888;
}
input[type=range]:focus::-ms-fill-upper {
background: #ccc;
}
(source: brennaobrien.com)
However, as far as I can tell, the ... ::-ms- ... pseudo-elements only work in IE. In Chrome, the code above seems to have no effect. In Chrome, I just end up with this:
(source: brennaobrien.com)
What can I do to achieve this effect cross-browser?
Thanks!
You can achieve this effect using gradient, look here: http://codepen.io/ryanttb/pen/fHyEJ
For example:
input::-moz-range-track{
background: linear-gradient(90deg,black 50%,grey 50%);
}
Of course you need js as well to change percentage values.
For anyone else finding this - with HTML5 now standard background-size is a great option if you don't want the fading look of a gradient. I've built my ranges around the tutorial at https://www.w3schools.com/howto/howto_js_rangeslider.asp.
So my solution was in css:
.slidecontainer {
display:inline-block;
vertical-align:middle;
width: 60%;
position:relative;
margin:5px 0;
background:url('/images/cyan_back.png') no-repeat left top;
background-size:0 14px;
border-radius:7px;
}
Then with jquery:
$('.slidecontainer').css('background-size',$(this).val()+'% 14px');
I believe this is also a bit more cross browser friendly.
Is a simple exercice, probably some solution better than others, but I wonder which is the best to create this kind of structure in html and css:
What I want is the text, then create 2 pixel line, 1px red and other 1 px green.
Not sure what is the best solution for crossbrowser , want to lines end same time.
Already tried with border, hr , background .. but seems not perfectly finish.
ps-looking for a solution without recurring to a image
Simple answer is to use a simple tag (<i> for example) and apply CSS styles to it.
<p>Your text <span class="line"></span></p>
CSS might look like this:
.line {
position: relative;
display: inline-block;
* display: inline; /* fix for IE bugs */
* zoom: 1; /* fix for IE bugs */
height: 1px;
width: 100px;
background-color: #f00;
border-bottom: 1px solid #00f;
vertical-align: middle;
margin-bottom: 5px;
}
CSS:
#lines{
border-bottom: 1px solid red;
border-top: 1px solid green;
display: inline-block;
height: 5px;
margin-left: 10px;
width: 100px;
}
Markup:
<span id='text'>My text</span>
<span id='lines'></span>
Here is my 2 cents... similar to Rodolfo but no spacers
http://jsfiddle.net/c4HjQ/
Use the CSS :after along with content:
<div class="container">
<div class="linetext">Text</div>
</div>
.container {
padding: 15px;
border: 4px solid black;
}
.linetext:after {
content: "";
display:inline-block;
width: 50px;
height:1px;
border-top: 1px solid green;
border-bottom: 1px solid red;
margin-left: 6px;
}
Try it: http://jsfiddle.net/wBTqV/
Documentation
CSS :after pseudo-selector on MDN - https://developer.mozilla.org/en/CSS/:after
CSS content property on MDN - https://developer.mozilla.org/en/CSS/content
you probably have a 'spacer' image (1x1 transparent image), so you can just do a
<div style="float:left">Your text</div>
<div style="float:left">
<div style="background-color:green"><img src="spacer.gif" width="100px" height="1px"></div>
<div style="background-color:red"><img src="spacer.gif" width="100px" height="1px"></div>
</div>