css - make achor tag block but only highlight text, ot the whole element - inline

I'm trying to mimic a graphic print trend in which you highlight headers. Pretty simple.
I need to add little padding to the text to make it more pleasing to the eye and readable.
Problem arises when text is wrapped - the padding only affects the first line making it appear as if the header is indented. Making the element (anchor) block-level fixes this, but then the whole element is highligtet and not just the text.
Can this be done using only css? It would be loathsome having to add javascript for such a simple thing.
Tjek the website here. Most of the headers a fairly short why the problem doesn't occur.

CSS:
h1 {
background:#ff0;
color:#000;
box-shadow:0.2em 0 0 #ff0, -0.2em 0 0 #ff0;
-moz-box-shadow:0.2em 0 0 #ff0, -0.2em 0 0 #ff0;
-webkit-box-shadow:0.2em 0 0 #ff0, -0.2em 0 0 #ff0;
}
Where #ff0 is the color you want the background to be.

Yes, this can be done using only CSS. Here's a post on CSS-Tricks detailing several methods for handling this issue.
One of them involves using box-shadow to apply the padding effect. Simply set two shadows, each with a horizontal offset of your desired padding along with the color of the highlight:
.highlight {
-webkit-box-shadow: 10px 0 0 orange,
-10px 0 0 orange;
-moz-box-shadow: 10px 0 0 orange,
-10px 0 0 orange;
box-shadow: 10px 0 0 orange,
-10px 0 0 orange;
}
Demo

Related

Cannot set property as opacity for extrusion layer in mapbox

The bounty expires in 2 days. Answers to this question are eligible for a +200 reputation bounty.
slevin wants to draw more attention to this question.
I use mapbox 2.10 and react 18.2. I have a mapbox fill-extrusion that gets a filter after a button click
map.current.setFilter('my-extrude', ['==',["id"] , 0] )
to show some extruded polygons.
In that layer I try to set a value for each polygon based on a property of the feature.
This doesnt work, I get Error: The layer 'my-extrude' does not exist in the map's style and cannot be filtered. probably because of the error in setting the opacity. If I set the opacity to a static number like 0.6, all works well.
What am I missing?
Thanks
map.current.addLayer({'id': 'my-extrude',
'type': 'fill-extrusion',
'source': 'my-extrude',
'paint': {
'fill-extrusion-color':[
'case',
['boolean', ['feature-state', 'hover'], false],'rgb(253, 255, 0)',
['boolean', ['feature-state', 'click'], false],'rgb(253, 255, 0)',
'rgb(253, 255, 72)'
] ,
'fill-extrusion-opacity':['get', 'customTop'],
'fill-extrusion-height': ['+',['to-number', ['get', 'customTop']] , ['to-number', ['get', 'customHeight']]],
'fill-extrusion-base': ['+',['to-number', ['get', 'customTop']], ['to-number', ['get', 'customBase']]]
}
});
it seems to me that instead of using 'feature-state' you should create a variable which will get the state of the map element on the page, and if the state is hover then give a static number for that case, and if the state is clicked then give a different static number.
Here most probably because you forgot to convert customTop to number just like you did for fill-extrusion-height and fill-extrusion-base and the error occures because fill-extrusion-opacity only accepts numbers between 0 and 1.
'fill-extrusion-opacity' : ['to-number', ['get', 'customTop']]
Note also when you use a variable to define fill-extrusion-opacity it is recommanded to set it with an interpolate expressions to make fill-extrusion-opacity always between 0 and 1.
Interpolate :
Produces continuous, smooth results by interpolating between pairs of input and output values ("stops"). The input may be any numeric expression (e.g., ["get", "population"]). Stop inputs must be numeric literals in strictly ascending order. The output type must be number, array, or color.
There are multiple ways to interpolate and the one needed here is the "linear" type :
Interpolates linearly between the pair of stops just less than and just greater than the input.
Inspired by this example from docs that uses the interpolate operator to define a linear relationship between zoom level and circle size using a set of input-output pairs
{
"circle-radius": [
"interpolate", ["linear"], ["zoom"],
// zoom is 5 (or less) -> circle radius will be 1px
5, 1,
// zoom is 10 (or greater) -> circle radius will be 5px
10, 5
]
}
with the same logic :
{
"fill-extrusion-opacity": [
"interpolate", ["linear"], ['to-number', ['get', 'customTop']],
// customTop is 0 (or less) -> fill-extrusion-opacity will be 0
0, 0,
// customTop is 1 (or greater) -> fill-extrusion-opacity will be 1
1, 1
]
}

Array.set is not a function and cannot be applied

I need to make a function which turns a random pixel in a picture to black.
A picture is represented as an array of colors represented as Black or White.
Here is my code :
type color = Black | White
;;
type picture = color array array
;;
let rec color_rand_point (img : picture) : picture =
let randx = ref (Random.int (Array.length img))
and randy = ref (Random.int (Array.length img)) in
if (img.(!randx).(!randy) = White)then
begin
Array.set img.(!randx) (!randy) Black;
end
img
else
color_rand_point(img)
;;
Here is the result I have when I try compiling :
Lines 5-7, characters 4-7:
5 | ....begin
6 | Array.set img.(!randx) (!randy) Black;
7 | end
Error: This expression has type unit
This is not a function; it cannot be applied.
#
I'm pretty sure the answer would be obvious to anyone knowledgeable about ocaml and that it's bad style, but I'm working on this as a student and have close to no idea about what i'm doing with ocaml. We didn't learn the basics in depth so I would like a simple answer if possible.
I have no idea of why Array.set isn't considered as a function applicable in an imperative bloc.
The error message doesn't point to Array.set, but to the begin ... end block, which evaluates to unit because Array.set, the only expression inside the block, returns unit.
The problem is that img is outside the block, and not separated by a semicolon, so you're effectively telling the compiler to pass img as an argument to whatever the begin ... end block evaluates to. Which is unit, not a function, as the error message says.
The error can be fixed just by moving img inside the block.

Stylus concatenate variable and string

Following code
for $i in (1..81)
.block:nth-child({$i})
transition transform 500ms ease $i\s
will be compiled to
.block:nth-child(1) {
transition: transform 500ms ease 1 s;
}
......
But that space between number and seconds is redundant!
How can I remove it?
One possible approach:
for $i in (1..81)
.block:nth-child({$i})
transition transform 500ms ease 1s * $i
That's actually quite similar to the example given in Selector Interpolation section of Stylus documentation.
You can use the unit() function:
for $i in (1..81)
.block:nth-child({$i})
transition transform 500ms ease unit($i, 's')

Vendor Prefixing for both Property and Value in Stylus

Using Stylus CSS preprocessor, I'm trying to write a mixin that will handle vendor-prefixing of the transition property and its transform value, and be able to accept multiple values.
Here's an example of the output I'm looking for:
-webkit-transition: opacity .2s linear .2s, -webkit-transform .2s linear .2s, left 0s linear .45s;
-moz-transition: opacity .2s linear .2s, -moz-transform .2s linear .2s, left 0s linear .45s;
-ms-transition: opacity .2s linear .2s, -ms-transform .2s linear .2s, left 0s linear .45s;
-o-transition: opacity .2s linear .2s, -o-transform .2s linear .2s, left 0s linear .45s;
transition: opacity .2s linear .2s, transform .2s linear .2s, left 0s linear .45s;
Note the vendor prefixes on both transition and transform.
While you can achieve this in stylus like this:
transition()
fix_transform($values, $vendor)
$new_values = ()
if match(',', '%s' % $values)
for $val in $values
if length($new_values) > 0
$new_values = $new_values, fix_transform($val, $vendor)
else
$new_values = fix_transform($val, $vendor)
else
for $val in $values
$new_val = $val
if $val == transform
$new_val = unquote($vendor + $new_val)
push($new_values, $new_val)
return $new_values
for $vendor in ('-webkit-' '-moz-' '-ms-' '-o-' '')
{$vendor}transiton: fix_transform(arguments, $vendor)
I'd recommend you not to use Stylus itself to add prefixes, but to use a specialized tool like autoprefixer for this.
There is actually a Stylus autoprefixer plugin — that would be the best to use with Stylus.

Is it possible to use do loop inside multiplot in gnuplot?

I need to create a figure with multiple subplots whereas in each subplot I need to plot multiple lines. Each line has to have a different color. (if every 30-40 lines the colors are iterated its ok for my purpose).
For example: ( I want 8 subplots)
set multiplot layout 2, 4
for the first subplot I can do the following
plot for [i=2:101] 'mydata.txt' u 1:i w line notitle lw 2
which will plot 100 lines inside the first subplot
plot for [i=1022:201] 'mydata.txt' u 1:i w line notitle lw 2
which adds another set of lines in the second panel etc.
The problem with this solution is that each separate line within the subplot gets not only a different color but also a different line style, some are solids some are dashed and each with different dash pattern etc.
Is there any way to use a unique line style e.g. all continuous lines and have different colors?
In the past I had found the following workaround, which works in the case of a single plot
rgb(r,g,b) = 65536 * int(r) + 256 * int(g) + int(b)
set multiplot
do for [i=2:201] {
rr = 255*rand(0)
gg = 255*rand(0)
bb = 255*rand(0)
plot 'moredata.inp' u 1:i:(rgb(rr,gg,bb)) w line notitle lt 1 lc rgb variable lw 2
}
However I cannot replace the "plot for [i=2:101]" with the do loop because the result is one line per subplot.
Any ideas?
Thank you
To use only solid lines, use
set termoption solid
In order to iterate over line colors, you can use lc variable (without the rgb!). In that case the last column is used as linetype index. If you want other colors of the linetypes you can use set linetype .... If you use set style increment user, the index refers to linestyles.
Or you can use lc palette and define an appropriate palette, see e.g. Gnuplot repeats colors in rowstack histograms. I think this might be the best option, because you need a lot of colors:
set palette model HSV defined ( 0 0 1 1, 1 1 1 1 ) # rainbow palette
plot for [i=2:101] 'mydata.txt' u 1:i lc palette frac (i/101.0) w line notitle

Resources