I use a RestAPI, it's giving me different size SVG. Some images are fit but some images don't fit.
Example: If you look at the border and image, you gonna understand.
The main problem is that; I don't know all pictures sizes, How can ı set this case? (İf it's given 100% height change the card height and ı don't want this.)
<div className="countries__card card">
<div className="card__flag">
<LazyLoad
height={windowWidth >= 614 ? "210px" : '173px"'}
once
>
<img
width={windowWidth >= 614 ? "320px" : "100%"}
height={windowWidth >= 614 ? "210px" : '100%"'}
src="https://restcountries.eu/data/afg.svg"
alt="flag"
/>
</LazyLoad>
</div>
<div className="card__body">
<div className="card__body-name">
<h5>Lorem</h5>
</div>
<div className="card__body-infos">
<span className="country-capital">Capital: Lorem</span>
<span className="country-currencies">Currency: Lorem</span>
<span className="country-region">Region: Lorem</span>
</div>
</div>
<footer className="card__footer">
Go to detailed information.
</footer>
</div>
<div className="countries__card card">
<div className="card__flag">
<LazyLoad
height={windowWidth >= 614 ? "210px" : '173px"'}
once
>
<img
width={windowWidth >= 614 ? "320px" : "100%"}
height={windowWidth >= 614 ? "210px" : '100%"'}
src="https://restcountries.eu/data/blr.svg"
alt="flag"
/>
</LazyLoad>
</div>
<div className="card__body">
<div className="card__body-name">
<h5>Lorem</h5>
</div>
<div className="card__body-infos">
<span className="country-capital">Capital: Lorem</span>
<span className="country-currencies">Currency: Lorem</span>
<span className="country-region">Region: Lorem</span>
</div>
</div>
<footer className="card__footer">
Go to detailed information.
</footer>
</div>
.card {
border: 2px solid black;
text-align: center;
margin-bottom: rem(50px);
width: 320px;
overflow: hidden;
animation: showCard 0.7s ease-out forwards;
img {
vertical-align: middle;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
&__body,
&__footer {
background: $skyblue;
}
&__body {
&-name {
color: $text-navy;
padding: rem(10px) 0;
font-size: rem(20px);
font-weight: $font-bold;
font-weight: normal;
border-bottom: 4px solid $text-navy;
}
&-infos {
padding: rem(15px) 0;
display: flex;
justify-content: center;
color: $text-navy;
span {
white-space: nowrap;
font-size: rem(14.3px);
}
span:not(:last-child) {
padding-right: rem(5px);
border-right: 3px solid $text-navy;
}
span:not(:first-child) {
padding-left: rem(5px);
}
}
}
&__footer {
border-top: 3px solid $text-navy;
padding: rem(15px) 0;
background: $text-navy;
cursor: pointer;
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
}
There is no standard for flag dimensions. RestCountries provides flags in their true dimensions.
I created a 29 kB Single File Web Component that does all SVG flags in fixed dimensions (like most SVG flag Repos do).
And can use RestCountries (or any other SVG flag Repo) as alternative source:
https://flagmeister.github.io/
Alas, I did not create all crests, you picked the exact two I failed to complete: Afghanistan and Andorra for your screenshots. Those flags FlagMeister will default to RestCountries unless prevented with the detail setting.
<script src="https://flagmeister.github.io/elements.flagmeister.min.js"></script>
<style>
div {
display:grid;
grid-template-columns:repeat(6,100px);
gap:10px;
}
[nodetail] {
--flagmeisterdetail:99999;
}
</style>
<h3>RestCountries & FlagMeister (forced to no-detail)</h3>
<div>
<flag-af></flag-af>
<flag-af nodetail></flag-af>
<flag-by></flag-by>
<flag-by nodetail></flag-by>
<flag-ad></flag-ad>
<flag-ad nodetail></flag-ad>
</div>
If you can live with making local copies of all the flags. Then, if you add the following attribute to all SVGs, they will stretch to fit your <img> width and height.
preserveAspectRatio="none"
For instance, the Belarus flag becomes:
svg {
width: 300px;
height: 300px;
}
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="900" height="450" viewBox="0 0 1098 549" preserveAspectRatio="none">
<title>Flag of Belarus</title>
<rect fill="#C8313E" width="1098" height="549"/>
<rect y="366" fill="#4AA657" width="1098" height="183"/>
<rect fill="#FFF" width="122" height="549"/>
<g id="h">
<g id="q" fill="#C8313E" fill-rule="evenodd" transform="scale(5.304347826,9)">
<path d="M4,0h3v1h1v1h1v1h1v1h1v1h-1v1h-1v1h-1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h-1v-1h-1v-1h-1v-1h1v-1h1v-1h1v-1h1zM5,2h1v1h1v1h1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h1v-1h1zM5,4h1v1h-1zM0,1h1v1h-1zM0,7h1v1h-1zM11,0h0.6v2h-.6zM11,7h.6v2h-.6zM2,9h1v1h1v1h1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h1v-1h1zM2,11h1v1h-1zM8,9h1v1h1v1h1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h1v-1h1zM8,11h1v1h-1zM0,15h1v1h-1zM11,14h.6v2h-.6z"/>
<path d="M0,18h1v-1h1v-1h1v-1h1v-1h1v-1h1v1h1v1h1v1h1v1h1v1h1v1h.6v4h-.6v1h-1v1h-1v1h-1v1h-1v1h-1v2.6h-2v-0.6h-1v-1h-1v-1h-1v-1h-1 v-3h1v1h1v1h1v1h1v-1h1v-1h1v-1h1v-1h1v-1h1v-1h-1v-1h-1v-1h-3v1h2v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h-1zM0,22h1v1h-1zM11,25h.6v1h-.6zM9,27h1v1h1v1h.6v1.6h-.6v-.6h-1v-1h-1zM7,30h1v.6h-1z"/>
</g>
<use xlink:href="#q" transform="translate(122,0) scale(-1,1)"/>
</g>
<use xlink:href="#h" transform="translate(0,549) scale(1,-1)"/>
</svg>
Related
I've created a map image with overlaying hotspots. It was created in inkscape and exported as an SVG.
The map is a test sketch only. http://wilsonvisuals.art/zenmapillo/imagemap_responsive2.html
I have pasted the SVG code into an html page with css.
I am now trying to add mouse over functionality to the hotspots.
When the user mouses over a hotspot it shows a tooltip or other card. And hides again when moused off.
I've tried several methods of inserting html/css code into the svg code but never works. The one below is simple html css.
I's this method workable? and how would I fix it?
Is Javascript a better approach to this? I got it working this way but the sample code I used performed a different function than what I want. Is there some sample code specific to show/hide on mouseover? (I am Javascript illiterate).
Any ideas on this would be greatly appreciated.
<!DOCTYPE html>
<html>
<title>Zen Maps - Courtney & Comox, Vancouver Island</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="css/custom.css">
<style>
#myBtn {
margin: auto;
z-index: 99;
font-size: 18px;
border: none;
outline: none;
background-color: #4a178bff;
color: white;
cursor: pointer;
padding: 15px;
border-radius: 4px;
}
#myBtn:hover {
background-color: #555;
}
div {
text-align: center;
}
h2 {
color: #4287f5;
}
.hide {
display: none;
border: 5px double #b4b8bf;
}
.hide2 {
display: none;
border: 5px double #b4b8bf;
}
.hide3 {
display: none;
border: 5px double #b4b8bf;
}
a {
display: block;
margin-top: 15px;
cursor: pointer;
text-decoration: none;
}
a:hover + span {
display: block;
color: #4287f5;
font-size: 20px;
}
a.two {
display: block;
margin-top: 15px;
cursor: pointer;
text-decoration: none;
}
a.two:hover + span {
display: block;
color: #4287f5;
font-size: 20px;
}
a.three {
display: block;
margin-top: 15px;
cursor: pointer;
text-decoration: none;
}
a.three:hover + span {
display: block;
color: #4287f5;
font-size: 20px;
}
</style>
<body>
<div class="mapdiv">
<!----to make svg responsive change fixed width to percentage and remove height property in the svg tag---->
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
version="1.1"
id="svg366"
width="3272.7273"
height="2029.0909"
viewBox="0 0 3272.7273 2029.0909"
sodipodi:docname="Comox3hotspot.svg"
inkscape:version="1.2 (dc2aeda, 2022-05-15)"
inkscape:export-filename="Comox1hotspot.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs370" />
<sodipodi:namedview
id="namedview368"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="0.38072222"
inkscape:cx="1086.0937"
inkscape:cy="1016.4891"
inkscape:window-width="1732"
inkscape:window-height="1290"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="0"
inkscape:current-layer="g372" />
<g
inkscape:groupmode="layer"
inkscape:label="Image"
id="g372">
<image
width="3272.7273"
height="2029.0909"
preserveAspectRatio="none"
xlink:href="maps/Comox12.jpg"
id="image374" />
<a xlink:href="http://travelalberta.com/">
<clipPath id="alberta-clipper">
<path id="CA-AB" d="M1932…"/>
</clipPath>
<image clip-path="url(#alberta-clipper)"
width="1024" height="768"
xlink:href="crowsnest-pass.jpg" x="1300" y="150">
</image>
</a>
<a xlink:href="http://travelalberta.com/">
<path
style="opacity:1;fill:#310000"
d="m 853.64075,499.05151 c -152.34204,-2.62658 -152.34204,-2.62658 -152.34204,-2.62658 l 2.62658,168.10156 212.75354,31.51904 76.17102,-110.31665 z"
id="path562" />
</a>
<foreignObject x="20" y="20" width="160" height="160">
<span class="hide">
First Card
</span>
</foreignObject>
<a xlink:href="http://travelalberta.com/">
<path
style="opacity:1;fill:#333"
d="m 1452.5026,590.98206 -154.9687,186.48767 383.4817,84.05078 291.5512,7.87976 -112.9433,-309.93726 z"
id="path6362" />
</a>
<foreignObject x="20" y="20" width="160" height="160">
<span class="hide2">
Second Card
</span>
</foreignObject>
<a xlink:href="http://travelalberta.com/">
<path
style="opacity:1;fill:#777"
d="m 1329.053,1625.8573 57.7849,344.0829 643.5138,36.7722 -139.2091,-378.2285 z"
id="path6364"
inkscape:export-filename="path6364.svg"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96" />
</a>
<foreignObject x="20" y="20" width="160" height="160">
<span class="hide3">
Third Card
</span>
</foreignObject>
</g>
</svg>
</div>
</body>
</html>
I would put the card outside the svg element. The card can be a div with position absolute (so that you can position it where you need it to be) and display none that you make visible only when passing over the path.
For clarity i've simplified the code.
let paths = document.querySelectorAll("path");
paths.forEach((p) => {
p.addEventListener("mouseleave", (evt) => {
card.style.display = "none";
});
p.addEventListener("mousemove", (evt) => {
let pos = oMousePos(svg, evt);
let text = p.dataset.text;
card.style.display = "block";
card.style.top = pos.y + "px";
card.style.left = pos.x + "px";
card.innerHTML = text;
});
});
function oMousePos(element, evt) {
let ClientRect = element.getBoundingClientRect();
return {
//objeto
x: Math.round(evt.clientX - ClientRect.left),
y: Math.round(evt.clientY - ClientRect.top)
};
}
#card {
position: absolute;
width: 100px;
height: auto;
display: none;
border: solid;
background: white;
pointer-events: none;
color:red;
padding:1em;
}
<svg viewBox="0 0 3272.7273 2029.0909" id="svg" >
<g id="g372">
<image width="3272.7273" height="2029.0909" preserveAspectRatio="none" xlink:href="maps/Comox12.jpg" id="image374" />
<a xlink:href="http://travelalberta.com/">
<path style="opacity:1;fill:#310000" d="m 853.64075,499.05151 c -152.34204,-2.62658 -152.34204,-2.62658 -152.34204,-2.62658 l 2.62658,168.10156 212.75354,31.51904 76.17102,-110.31665 z" id="path562" data-text="first Card" />
</a>
<a xlink:href="http://travelalberta.com/">
<path style="opacity:1;fill:#333" d="m 1452.5026,590.98206 -154.9687,186.48767 383.4817,84.05078 291.5512,7.87976 -112.9433,-309.93726 z" id="path6362" data-text="Second Card" />
</a>
<a xlink:href="http://travelalberta.com/">
<path style="opacity:1;fill:#777" d="m 1329.053,1625.8573 57.7849,344.0829 643.5138,36.7722 -139.2091,-378.2285 z" id="path6364" data-text="third Card" />
</a>
</g>
</svg>
<div id="card"></div>
I have a svg icon and a span element side by side. When the text overflows inside the span element, the svg also comes down along with it. I don't want it to happen.
Here is a of what I'm doing.
As you can see, the arrow icon is proper in Section 1 but in Section 2, it comes down with the text.
Here is the HTML code -
.rightContent {
border: 2px solid green;
height: 100vh;
overflow-y: scroll;
}
.sectionHeading {
background: #f7f9fa;
text-align: left;
font-family: sf pro display, -apple-system, BlinkMacSystemFont, Roboto, segoe ui, Helvetica, Arial, sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol;
font-weight: 700;
line-height: 1.2;
letter-spacing: -.02rem;
font-size: 1rem;
padding-top: .75rem;
padding-bottom: 1.05rem;
}
.sectionHeading p {
padding: 0;
margin: 0;
}
.sectionHeading svg {
float: right;
}
.sectionHeading small {
font-size: 0.75rem;
font-weight: 500;
}
<div class="rightContent col col-lg-3 col-md-3 sol-sm-3" style="border: 2px solid green;">
<!-- Section 1: Introduction -->
<div class="row">
<div class="card">
<div class="sectionHeading">
<span>Section 1: Introduction</span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-down" viewBox="0 0 16 16">
<path d="M3.204 5h9.592L8 10.481 3.204 5zm-.753.659 4.796 5.48a1 1 0 0 0 1.506 0l4.796-5.48c.566-.647.106-1.659-.753-1.659H3.204a1 1 0 0 0-.753 1.659z"/>
</svg>
<p></p>
<small>14 / 14 | 1hr 5min</small>
</div>
</div>
</div>
<!-- Section 2: Experience -->
<div class="row">
<div class="card">
<div class="sectionHeading">
<span>Section 2: Experiences In The Corporate World</span>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-down" viewBox="0 0 16 16">
<path d="M3.204 5h9.592L8 10.481 3.204 5zm-.753.659 4.796 5.48a1 1 0 0 0 1.506 0l4.796-5.48c.566-.647.106-1.659-.753-1.659H3.204a1 1 0 0 0-.753 1.659z"/>
</svg>
<p></p>
<small>19 / 19 | 2hr 15min</small>
</div>
</div>
</div>
Most of the questions already present deal with aligning icons with text, but as I mentioned earlier, I want to align icons with span element and keep it fixed there, instead of aligning it with text.
Please feel free to share your inputs. I'll be grateful to learn from others since I'm still learning CSS. Thank you.
Please set max-width or width of span tag. As width svg tag is 16px, you can set that max-width of is calc(100% - 16px).
Try it
<style>
.sectionHeading span{
display: inline-block;
max-width: calc(100% - 16px);
}
</style>
In your case the best choice is using positions,using your .sectionHeading or.card as the relative element.
Try it:
.sectionHeading { /* you can also use your div .card */
position: relative;
}
svg { /* here you can also use a class name */
position: absolute;
top: 0;
right: 0;
}
Be in mind that maybe you will need to add a padding to your relative element, otherwise your svg will be leaning the border.
You had a few small problems like an empty p tag which I fixed.
I wrapped small & span tags in a container and Since you're using bootstrap, I added d-flex justify-content-between classes to sectionHeading. This fixed the problem.
* {
margin: 0;
padding: 0;
box-sizing: border-box
}
.rightContent {
border: 2px solid green;
height: 100vh;
overflow-y: scroll;
}
.sectionHeading {
background: #f7f9fa;
text-align: left;
font-family: sf pro display, -apple-system, BlinkMacSystemFont, Roboto, segoe ui, Helvetica, Arial, sans-serif, apple color emoji, segoe ui emoji, segoe ui symbol;
font-weight: 700;
line-height: 1.2;
letter-spacing: -.02rem;
font-size: 1rem;
padding-top: .75rem;
padding-bottom: 1.05rem;
}
.sectionHeading p {
padding: 0;
margin: 0;
}
.sectionHeading svg {
float: right;
}
.sectionHeading small {
font-size: 0.75rem;
font-weight: 500;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<div class="rightContent col col-lg-3 col-md-3 sol-sm-3" style="border: 2px solid green;">
<!-- Section 1: Introduction -->
<div class="row">
<div class="card">
<div class="sectionHeading d-flex justify-content-between">
<div>
<span>Section 1: Introduction</span><br/>
<small>14 / 14 | 1hr 5min</small>
</div>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-down" viewBox="0 0 16 16">
<path d="M3.204 5h9.592L8 10.481 3.204 5zm-.753.659 4.796 5.48a1 1 0 0 0 1.506 0l4.796-5.48c.566-.647.106-1.659-.753-1.659H3.204a1 1 0 0 0-.753 1.659z"/>
</svg>
</div>
</div>
</div>
<!-- Section 2: Experience -->
<div class="row">
<div class="card">
<div class="sectionHeading d-flex justify-content-between">
<div>
<span>Section 2: Experiences In The Corporate World</span><br/>
<small>19 / 19 | 2hr 15min</small>
</div>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-caret-down" viewBox="0 0 16 16">
<path d="M3.204 5h9.592L8 10.481 3.204 5zm-.753.659 4.796 5.48a1 1 0 0 0 1.506 0l4.796-5.48c.566-.647.106-1.659-.753-1.659H3.204a1 1 0 0 0-.753 1.659z"/>
</svg>
</div>
</div>
</div>
today wanted to set the size of a background on a svg using the background-size property, but it didn't worked because the background wasn't an image, but it was a normal color (#ecf2f8)
here is what i want to do:
here is what i did:
here is my code:
#svg-social {
position: absolute;
right: 50px;
bottom: 45px;
background-color: #ecf2f8;
border-radius: 100px;
}
<p id="main-text">
Ever been in a room and felt like something was missing?<br> Perhaps
it felt slightly bare and uninviting. I’ve got some<br> simple tips
to help you make any room feel complete.</p>
<div id="author">
<img src="/images/avatar-michelle.jpg" alt="Michelle Appleton avatar" id="avatar">
<h5 id="name">Michelle Appleton</h5>
<p id="date">28 Jun 2020</p>
</div>
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="13" id="svg-social">
<path fill="#6E8098"
d="M15 6.495L8.766.014V3.88H7.441C3.33 3.88 0 7.039 0 10.936v2.049l.589-.612C2.59 10.294 5.422 9.11 8.39 9.11h.375v3.867L15 6.495z" />
</svg>
<div id="socials">
<div id="triangle"></div>
</div>
</div>
Have a nice day!
Try using padding to increase the size of the background around your element:
#svg-social {
position: absolute;
right: 50px;
bottom: 45px;
background-color: #ecf2f8;
border-radius: 100px;
padding: 10px;
}
The px value you pick depends on what you want, just play around with different values and see if it gets your desired output.
Example code snippet with padding in CSS:
#svg-social {
position: absolute;
right: 50px;
bottom: 45px;
background-color: #ecf2f8;
border-radius: 100px;
padding: 10px;
}
<html>
<head>
<title>while</title>
</head>
<body>
<p id="main-text">
Ever been in a room and felt like something was missing?<br> Perhaps
it felt slightly bare and uninviting. I’ve got some<br> simple tips
to help you make any room feel complete.</p>
<div id="author">
<img src="/images/avatar-michelle.jpg" alt="Michelle Appleton avatar" id="avatar">
<h5 id="name">Michelle Appleton</h5>
<p id="date">28 Jun 2020</p>
</div>
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="13" id="svg-social">
<path fill="#6E8098"
d="M15 6.495L8.766.014V3.88H7.441C3.33 3.88 0 7.039 0 10.936v2.049l.589-.612C2.59 10.294 5.422 9.11 8.39 9.11h.375v3.867L15 6.495z" />
</svg>
<div id="socials">
<div id="triangle"></div>
</div>
</div>
</body>
</html>
Html-css-js snippet of code: Code
You could use padding to resize the background of your icon. You can also resize the SVG icon by using transform: scale(1);
#svg-social {
position: absolute;
right: 50px;
bottom: 45px;
background-color: #ecf2f8;
border-radius: 100px;
padding: .5em; /* You could also use px */
transform: scale(1.5); /*Resize/scale the SVG*/
}
<p id="main-text">
Ever been in a room and felt like something was missing?<br> Perhaps
it felt slightly bare and uninviting. I’ve got some<br> simple tips
to help you make any room feel complete.</p>
<div id="author">
<img src="/images/avatar-michelle.jpg" alt="Michelle Appleton avatar" id="avatar">
<h5 id="name">Michelle Appleton</h5>
<p id="date">28 Jun 2020</p>
</div>
<svg xmlns="http://www.w3.org/2000/svg" width="15" height="13" id="svg-social">
<path fill="#6E8098"
d="M15 6.495L8.766.014V3.88H7.441C3.33 3.88 0 7.039 0 10.936v2.049l.589-.612C2.59 10.294 5.422 9.11 8.39 9.11h.375v3.867L15 6.495z" />
</svg>
<div id="socials">
<div id="triangle"></div>
</div>
</div>
I added padding and transform:scale() in the CSS, please do check the snippet if it is your desired output
You need to create a div and add the background to the div, because i don't know why, with the padding property the svg disappears, here is the code:
<div id="svg1">
<svg id="arrow" xmlns="http://www.w3.org/2000/svg" width="15" height="13">
<path fill="#6E8098"
d="M15 6.495L8.766.014V3.88H7.441C3.33 3.88 0 7.039 0 10.936v2.049l.589-.612C2.59 10.294 5.422 9.11 8.39 9.11h.375v3.867L15 6.495z" />
</svg>
</div>
#svg1 {
position: absolute;
right: 50px;
bottom: 45px;
background-color: #ecf2f8;
border-radius: 50px;
padding: 10px;
height: 30px;
width: 30px;
}
#arrow {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%); /* this will center the svg in the div horizontally and vertically */
I'm trying to create a type of 'blurb' with SVG icon with Title & Text using Flex. I have attached a visual example to show you what I'm trying to achieve.
I feel close, but what I've got so far is still kinda sketchy, and I'm struggling to get the exact output. Any advice to point me in the right direction would be appercaited. Thanks
EDIT: How do you reduce the space between H3 & P tags? (I did try margin & padding, yet it didn't have any effect)
Link to CodePen
HTML
<div class="blurb-container">
<div class="blurb-icon">
<svg width="99px" height="89px" viewBox="0 0 99 89" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Homepage---Desktop---First-Time-Visitor" transform="translate(-780.000000, -859.000000)">
<g id="Group-6" transform="translate(180.000000, 828.000000)">
<g id="home-icon-1-copy" transform="translate(600.000000, 31.000000)">
<path d="M22.150176,37.2957114 L58.414244,16.7220133 C60.8963066,15.3138644 63.9757833,15.5045087 66.2652073,17.2080509 L95.4458727,38.9211515 C97.7262512,40.617963 98.7949315,43.4975614 98.1736475,46.2712415 L89.8690907,83.346375 C89.1324698,86.6349692 86.2132711,88.9726247 82.8431877,88.9726247 L30.3226487,88.9726247 C26.6804011,88.9726247 23.6118056,86.2526419 23.1746879,82.6367194 L18.5550504,44.4221834 C18.2065153,41.539034 19.6242293,38.7287571 22.150176,37.2957114 Z" id="Path" fill="#ADC4DA"></path>
<path d="M68.593607,3.0866438 L94.8814573,28.4607721 C95.8351433,29.3813096 95.8620155,30.900668 94.941478,31.8543541 C94.489197,32.3229217 93.8659168,32.5875735 93.2146766,32.5875735 L88.608603,32.5874054 L88.6088522,55.3077597 C88.6088522,57.9587266 86.4598189,60.1077599 83.808852,60.1077599 L64.7380969,60.1074054 L64.7382432,44.0318665 L71.7133122,44.0322664 C72.3680935,44.0322664 72.9944465,43.7647377 73.4471807,43.2916941 C74.3636574,42.334105 74.3303291,40.8148745 73.37274,39.8983979 L73.37274,39.8983979 L50.1500969,17.6714054 L65.2600458,3.0866438 C66.1899666,2.18904546 67.6636861,2.18904546 68.593607,3.0866438 Z" id="Combined-Shape" stroke="#000000" stroke-width="4.80000019"></path>
<path d="M39.9033277,7.86593791 L73.37274,39.8983979 C74.3303291,40.8148745 74.3636574,42.334105 73.4471807,43.2916941 C72.9944465,43.7647377 72.3680935,44.0322664 71.7133122,44.0322664 L64.7382432,44.0318665 L64.7389267,74.5510029 C64.7389267,77.2019698 62.5898934,79.3510031 59.9389265,79.3510031 L16.5488733,79.3510031 C13.8979064,79.3510031 11.7488731,77.2019698 11.7488731,74.5510029 L11.7482432,44.0318665 L4.77448753,44.0322664 C3.44900408,44.0322664 2.37448744,42.9577498 2.37448744,41.6322664 C2.37448744,40.9774851 2.64201622,40.3511321 3.11505975,39.8983979 L36.5844721,7.86593791 C37.5124905,6.97776243 38.9753093,6.97776243 39.9033277,7.86593791 Z" id="Combined-Shape-Copy-10" stroke="#000000" stroke-width="4.80000019"></path>
<path d="M31.0829269,50.4861382 L45.404878,50.4861382 C46.7303614,50.4861382 47.804878,51.5606549 47.804878,52.8861383 L47.804878,79.3510031 L47.804878,79.3510031 L28.6829268,79.3510031 L28.6829268,52.8861383 C28.6829268,51.5606549 29.7574435,50.4861382 31.0829269,50.4861382 Z" id="Rectangle" stroke="#000000" stroke-width="4.80000019"></path>
</g>
</g>
</g>
</g>
</svg>
</div>
<div class="blurb-content">
<h3 class="blurb-title font-graphikmedium">Search properties</h3>
<div class="blurb-label">Browse thousands of exclusive properties across the country.</div>
</div>
CSS
.blurb-container {
display: flex;
margin-top: 0px;
width: 470px;
height: 98px;
}
.blurb-container * {
box-sizing: border-box;
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.blurb-icon {
float: left;
display: block;
width: 99px;
height: 89px;
}
.blurb-content {
margin-left: 10px;
}
.blurb-title {
font-weight: bold;
font-size: 20px;
}
.blurb-label {
margin-top: 0px;
font-size: 18px;
}
.font-graphikmedium {
font-family: "graphikmedium";
}
You don't need to use floats. You can use flexbox for this entire thing. You also should be using a paragraph element underneath your h3 instead of a div.
The HTML and CSS is below, and I've also linked the codepen so you can play around with it and see the code in action.
https://codepen.io/bdlowery/pen/gOxqqKa
<div class="container">
<picture>
<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
</svg>
</picture>
<div class="text-content">
<h3>Search properties</h3>
<p>Browse thousands of exclusive properties across the country.</p>
</div>
</div>
/* main idea to get what you want */
picture {
max-width: 100px;
}
.container {
display: flex;
flex-direction: row;
align-items: center;
}
/* setup to get responsive svgs */
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
picture {
display: block;
}
svg {
display: block;
width: 100%;
height: 100%;
}
Add align-items: center; to the equation and replace the div under your h3 to a p tag instead. Here's the sandbox and I put a red border around it just so I could visually see what was going on. The code is the same as yours, I just added the align-items and replaced the div with a p. https://codesandbox.io/s/small-shadow-fde90?file=/index.html
Add this css
.text-content {
display:flex;
flex-direction:column;
width: 335px;
padding-left: 20px;
}
h3 {
font-family: 'Montserrat', sans-serif; font-size: 28px;
margin-bottom:-20px;
}
p {
color: #48525B;
font-family: "Helvetica Neue",Helvtica,Arial,sans-serif;
font-size: 20px;
line-height: 28px;
letter-spacing: 0;
}
I want the svg to change the fill color when a user have focus on the input.
But I don't understand how to write the css to make it happen.
Added Html and css for you to check out! I'm using scss for the css.
<div class="search">
<svg width="20px" height="20px" viewBox="0 0 88 88" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="Symbols" stroke="none" stroke-width="1" fill-rule="evenodd">
<g id="Icon-Search" fill="#b3b3b3" fill-rule="nonzero">
<path d="M86.829,81.172 L64.128,58.471 C69.055,52.312 72,44.5 72,36 C72,16.118 55.883,0 36,0 C16.118,0 0,16.118 0,36 C0,55.882 16.118,72 36,72 C44.5,72 52.312,69.054 58.471,64.127 L81.172,86.828 C81.953,87.609 82.977,88 84,88 C85.024,88 86.048,87.609 86.829,86.828 C88.391,85.267 88.391,82.733 86.829,81.172 Z M36,64 C20.536,64 8,51.464 8,36 C8,20.536 20.536,8 36,8 C51.465,8 64,20.536 64,36 C64,51.464 51.465,64 36,64 Z" id="Shape"></path>
</g>
</g>
</svg>
<input class="input inputSearchField" type="text" placeholder="Search...">
</div>
.input{
width: 250px;
height: 35px;
padding-left: 16px;
font-weight: 700;
background-color: $white-color;
border-radius: 4px;
border: 1px solid $lighter-gray;
font-size: 16px;
outline:none;
transition: all 0.30s ease-in-out;
&::placeholder {
color: $light-gray;
}
&:focus {
box-shadow: 0 0 5px #64e469;
border: 1px solid #64e469;
}
}
.search {
position: relative;
margin: 0 auto;
text-align: center;
width: 270px;
margin-bottom: 30px;
}
.search svg {
position: absolute;
top: 7px;
right: 22px;
fill: $lighter-gray;
}
Check out this CodePen Demo. You'll need to move your input before your SVG, otherwise you'll have to use some JavaScript to do this, because CSS doesn't have a "look behind" selector of any kind. Even the General Sibling Combinator only looks ahead of the current selector target.
If you move the input first, you can just do:
.input:focus + svg #Icon-Search {
fill: #64e469;
}
If you do want to keep the current structure, the JavaScript would look something like on this Demo
let search = document.getElementsByClassName('inputSearchField');
let svgFill = document.getElementById('Icon-Search');
search[0].onfocus = function(){ svgFill.style.fill = '#64e469'; }
search[0].onblur = function(){ svgFill.style.fill = '#b3b3b3'; }
You can see it's a fair bit more tedious!
I'm wondering that you have a html like it:
<div class="search">
<input class="input" />
<svg />
</div>
Your css can be something like this:
.input:focus + svg { ... }
If svg comes before input, then you can use ~ instead +