Multiline underlined button - css

I am having issues with underlining button text using box-shadow and wrapping it on multiple lines. It should be solved using just CSS.
Needs to use the following HTML (can't add HTML tags, special characters etc.):
<button class="button">
<span class="button__inner">
<span class="button__text">
Button with very very very long example text
</span>
<svg class="button__icon" width="24" height="24" viewBox="0 0 24 24">
<path d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z" />
</svg>
</span>
</button>
Visually it should look like this!
Requirements:
Use box-shadow to underline text on multiple lines.
Do not add additional HTML (needs to use HTML structure provided above).
.button__inner has to be display: flex or inline-flex.
The icon needs to be aligned right (in its own column), vertically centered and not have underline.
.button {
background: none;
border: none;
font-size: 12px;
cursor: pointer;
}
.button:focus {
outline: none;
}
.button__inner {
display: flex;
align-items: center;
justify-content: flex-start;
text-align: left;
}
.button__text {
box-shadow: inset 0 -1px currentColor;
}
.button:hover .button__text {
box-shadow: none;
}
.button__icon {
width: 1em;
height: 1em;
}
p {
font-size: 14px;
line-height: 1.2em;
}
<div style="max-width: 200px">
<p>
Following button using correct HTML, however box-shadow does not underline correctly on multiple lines. The icon needs to be on the right in its own column so therefore adding display: inline; to .button__inner is not an option.
</p>
<button class="button">
<span class="button__inner">
<span class="button__text">
Button with very very very long example text
</span>
<svg class="button__icon" width="24" height="24" viewBox="0 0 24 24">
<path d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z" />
</svg>
</span>
</button>
<p>
Below is the visually desired result, however it uses an additional span element. How to achieve this using just CSS and without altering the HTML?
</p>
<button class="button">
<span class="button__inner">
<span>
<span class="button__text">
Button with very very very long example text
</span>
</span>
<svg class="button__icon" width="24" height="24" viewBox="0 0 24 24">
<path d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z" />
</svg>
</span>
</button>
</div>
Is this even possible using just CSS?

Does it work in your case to use text-decoration: underline instead of box-shadow? like this example: https://codepen.io/annaazzam/pen/PoZEJwX

Related

why is my image not touching the border of this aside? [duplicate]

This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 9 months ago.
Quick question and a very simple HTML CSS question but I'm not getting it.
Here is my image rendering inside of a tag.
I don't really understand why there's a gap kind of padding-bottom in the aside which is not allowing my image to sit on the bottom => just like it would be bottom:0 if we were talking about position: absolute (which is not the case tho).
Here's the code:
<aside
class="aside"
>
<h1>This is the aside</h1>
<h2
>
Join this great community!
</h2>
<div class="link-container">
<a
class="link"
href="https://app.redpadel.com"
> Link </a
>
</div>
<div class="icon-container">
<svg
width="160"
height="161"
viewBox="0 0 160 161"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M12.9859 35.5114C12.9859 35.5114 14.7383 71.4143 37.308 84.3381C53.2318 93.4563 73.9771 87.9876 73.4958 75.7778C73.2413 69.3196 66.3035 68.1061 62.0894 70.5929C54.473 75.0874 59.0025 94.4066 67.3688 102.896C96.385 132.339 151.835 110.545 151.835 110.545"
stroke="white"
stroke-width="2"
stroke-linecap="round"
/>
<path
d="M147.668 119.084L152.597 110.624L143.688 104.809"
stroke="white"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</div>
<div
class="img-container"
>
<img
class="image"
:src="require('../assets/img/capsule_member.jpg')"
alt="Padel team"
/>
</div>
</aside>
<style scoped>
aside {
background: rgb(19, 20, 21);
width: 90%;
margin: 0;
padding: 0;
}
.link {
color: #fff;
text-decoration: none;
}
.image {
width: 100%;
height: 100%;
margin: 0;
}
.img-container {
margin: 0;
padding: 0;
}
</style>
The body is set to margin & padding: 0
Use display: block on the image, otherwise it's treated as an inline element, keeping space for descenders below the baseline.

Prevent parent CSS while focus on child button

I've a <div> wrapped within <a>. a:active has css to transform the element but I don't want that behaviour (transform) to be there while I focus on bx--overflow-menu child. I am using NextJS with styled-jsx and SaSS. Below is my code :
<a class="singleTile" data-cta-type="unimplemented" href="test">
<div class="bx--row">
<div class="bx--overflow-menu" role="button" aria-haspopup="true" aria-expanded="false" aria-label="Menu" tabindex="0">
<svg focusable="false" aria-label="open and close list of options" role="img" class="bx--overflow-menu__icon">
<circle cx="8" cy="3" r="1"></circle>
<circle cx="8" cy="8" r="1"></circle>
<circle cx="8" cy="13" r="1"></circle>
<title>open and close list of options</title>
</svg>
</div>
<div class="bx--col">
<p class="name-212">cougar</p>
<p class="name-213">Version:<span class="" style="display: inline;">test.1</span></p>
</div>
</div>
</a>
The styles:
<style>
.singleTile {
flex: none;
width: 100%;
border: 1px solid #e0e0e0;
display: block;
padding: 1rem;
transition: all 150ms cubic-bezier(0.2, 0, 0.38, 0.9);
background-color: #ffffff;
}
a.singleTile:hover {
border-color: red;
}
a.singleTile:active {
transform: scale(.994);
}
.bx--overflow-menu{
top: 0;
right: .25rem;
position: absolute;
}
</style>
I have some idea that it can't be done with CSS only and I am also not allowed to use jQuery.
Any other suggestions will be helpful.
There are no parent selectors in css right now. It could be possible to implement this on next css4.
.singleTile:has(> bx--overflow-menu:active) { /* styles to apply to the singleTile tag */ }

Need to draw two circles with same origin( same center point) using CSS styles

I have a requirement to display 2 circles with different widths and heights but circles should start from same origin ( same center ), it means even though I change the sizes of both the circles they should look same with different sizes.
I have seen some bunch of examples over internet,problem with them is when I change the width and heights center point of both the circles are not the same anymore.
Also when I do hover they have to increase the size with smooth transition.
I am guessing that I need two circles to draw something like this, if we can draw with using only one circle please let me know.
Outer circle details:
inner circle
width: 97.33px;
height: 97.33px;
color: #DEBF43;
opacity: 74%;
shadow: #D7E0F1, 100%;
blur: 30px;
x - 0px //no idea but is mentioned in requirement
y 10px //no idea but is mentioned in requirement
outer circle details:
width: 79.49
height: 79.49
shadow: #000000,15%;
blur: 6px;
opacity: 100%;
X - 0px //no idea but is mentioned in requirement
y - 1px //no idea but is mentioned in requirement
Thanks,
Rohan
I would use a SVG with circles. It is quite easy and well readable.
Get two circles aligned with different radius and manipulate them via Javascript. Just overwrite the r-property.
Here a quick example with Vue:
new Vue({
el: '#app',
data: {
r1: 120,
r2: 90,
}
});
/* circles */
.circle--1 {
fill: yellow;
}
.circle--2 {
fill: orange;
}
.transparent {
opacity: 0.4;
}
/* demo stuff */
.container {
display: flex;
flex-flow: row wrap;
justify-content: center;
align-content: flex-start;
background: #ccc;
height: 100vh;
}
.svg, aside {
background-color: #fff;
box-shadow: 0 0 4rem #00000033;
margin: 1rem;
}
aside {
width: 300px;
height: 300px;
display: flex;
flex-flow: column;
justify-content: space-evenly;
align-items: center;
}
label {
display: block;
font-weight: 700;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<main id="app" class="container">
<!-- svg with two circles -->
<svg class="svg" width="300" height="300">
<circle class="circle circle--1" cx="50%" cy="50%" r="120" stroke="black" stroke-width="2"/>
<circle class="circle circle--2" cx="50%" cy="50%" r="90"/>
</svg>
<!-- demo svg with editable radii -->
<svg class="svg" width="300" height="300">
<circle id="circle-1" class="circle circle--1 transparent" cx="50%" cy="50%" :r="r1" stroke="black" stroke-width="2"/>
<circle id="circle-2" class="circle circle--2 transparent" cx="50%" cy="50%" :r="r2"/>
</svg>
<!-- demo controls -->
<aside>
<section>
<label for="radius1">Radius 1 ({{r1}}px)</label>
<input type="range" id="radius1" min="0" max="140" v-model="r1">
</section>
<section>
<label for="radius2">Radius 2 ({{r2}}px)</label>
<input type="range" id="radius2" min="0" max="140" v-model="r2">
</section>
</aside>
</main>
Here is a simple idea where you can rely on multiple background. The trick is to make the gradient to cover only the content box and control the space using padding:
.box {
width:100px;
height:100px;
border-radius:50%;
border:5px solid;
padding:20px;
background:
linear-gradient(orange,orange) content-box,
yellow;
}
<div class="box">
</div>
Or like this with a radial-gradient
.box {
width:100px;
height:100px;
border-radius:50%;
border:5px solid;
padding:20px;
background:
radial-gradient(farthest-side,orange 60%,yellow 61%);
}
<div class="box">
</div>

Positioning a SVG icon as list-style-image

Is there a quick and easy way for me to vertically center my SVG icon with the corresponding text? I was able to get it to be close, but I'd like to nudge it down a bit. This is as close as I've got
Here's how I'm implementing it:
HTML:
<ul class="list-goals">
<li>Some text for li number one</li>
<li>Some text for li number two</li>
<li>Some text for li number three</li>
</ul>
CSS:
.list-goals li {
margin-bottom: 1rem;
background: url(../images/trophy.svg) no-repeat left top;
padding: 0px 0 3px 24px;
}
I figure I could always use a png with built in padding, but I'd rather stick to my svg and apply positioning or padding directly to the svg icon.
Thanks for the help!
I know this is a late answer, but you can try this as well.
li { list-style-image: url(img/iphone.svg); }
There is nothing else you need to do because the SVG is applied with default spacing.
Just use the background-position CSS property to move the image where you want it.
Here's a simple example (using a data URI image, but will work just as well with an external file):
li {
font-size: 30px;
list-style-type: none;
margin-bottom: 1rem;
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiID8+PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgd2lkdGg9IjIwIiBoZWlnaHQ9IjIwIiB2aWV3Qm94PSIwIDAgMjAgMjAiPjxwYXRoIGQ9Ik0wIDAgMjAgMTAgMCAyMFoiIGZpbGw9IiNhYWEiLz48L3N2Zz4=) no-repeat left top;
padding: 0px 0 3px 24px;
}
ul.better li {
background-position: left 4px;
}
<p>ok:</p>
<ul class="ok">
<li>Text</li>
</ul>
<hr />
<p>better:</p>
<ul class="better">
<li>Text</li>
</ul>
Given this simple SVG example:
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 600 600">
<style type="text/css">
circle:hover {fill-opacity:0.9;}
</style>
<g style="fill-opacity:0.7;">
<circle cx="6.5cm" cy="2cm" r="100" style="fill:red; stroke:black; stroke-width:0.1cm" transform="translate(0,50)" />
<circle cx="6.5cm" cy="2cm" r="100" style="fill:blue; stroke:black; stroke-width:0.1cm" transform="translate(70,150)" />
<circle cx="6.5cm" cy="2cm" r="100" style="fill:green; stroke:black; stroke-width:0.1cm" transform="translate(-70,150)"/>
</g>
</svg>
If I were to change the viewBox to viewBox="0 -20 600 600", it would move the image down -20 units. The result would be this in browser (-20 on right):

CSS and creating border of svg figure

I have file with star in SVG format. How to make border of that figure(not entire square with that star) using css? Also, how make fill that image on hover effect?
I tried to add in html:
<i class="favorite"></i>
and in scss:
.favorite {
width: 17px;
height: 16px;
display: block;
text-indent: -9999px;
background-size: 17px 16px;
background: url(../../../../../assets/images/icon-star.
}
But I dont see anything. When i change background-color to for example red I see white star on red square. How to make it work?
You can't change the colours of an SVG that's included via <img> or background-image. You'll need to include it inline in your page. You can then change the colours using the fill and stroke properties.
.square {
fill: red;
stroke: blue;
stroke-width: 4;
}
<div>
<p>Hello world</p>
<svg>
<rect class="square" x="5" y="5" width="100" height="100"/>
</svg>
</div>

Resources