This is the needed code
.strokes {
display: flex;
width: 100%;
}
.stroke1 {
position: absolute;
z-index: 1002;
justify-content: center;
text-align: center;
align-items: center;
}
<section class="home" id="home">
<div class="max-width">
<div class="star star1"></div>
<div class="home-content">
<div class="text-1">Hello, my name is</div>
<div class="text-2">Hadi Zouhbi</div>
<div class="text-3">And I'm a <span class="txt-rotate"
data-period="2000"
data-rotate='[ "Developer.", "UX Designer.", " Programmer.", "Full-Stack Dev.", "Marketer" ]'
id="headSpan"></span></div>
Hire Me
</div>
</div>
</section>
</header>
<div class="strokes">
<svg class="stroke1" stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024" height="3em" width="3em" xmlns="http://www.w3.org/2000/svg"><path d="M456 231a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 280a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 280a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path></svg>
</div>
I want the stroke to be in the middle of the page but nothing is working , it always stays on the left side , am I doing anything wrong ?
If all you're trying to do is center the <svg> then there were a couple issues with your code. First, justify-content and align-items need to be set on the flex container itself (i.e. the same element that has the display: flex rule applied to it), not its children. Second, anything that is absolutely positioned will override any inherent flex positioning applied to it, so I don't think you want that in this case.
Here's an updated code snippet that addresses the above points and thus centers the dots.
.strokes {
display: flex;
justify-content: center;
text-align: center;
align-items: center;
width: 100%;
}
.stroke1 {
z-index: 1002;
}
<section class="home" id="home">
<div class="max-width">
<div class="star star1"></div>
<div class="home-content">
<div class="text-1">Hello, my name is</div>
<div class="text-2">Hadi Zouhbi</div>
<div class="text-3">And I'm a <span class="txt-rotate"
data-period="2000"
data-rotate='[ "Developer.", "UX Designer.", " Programmer.", "Full-Stack Dev.", "Marketer" ]'
id="headSpan"></span></div>
Hire Me
</div>
</div>
</section>
</header>
<div class="strokes">
<svg class="stroke1" stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024" height="3em" width="3em" xmlns="http://www.w3.org/2000/svg"><path d="M456 231a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 280a56 56 0 1 0 112 0 56 56 0 1 0-112 0zm0 280a56 56 0 1 0 112 0 56 56 0 1 0-112 0z"></path></svg>
</div>
Related
I need to add a exit button to the top left corner of the modal, also I would like for the modal to disappear after the link has been copied. How would i go about doing this ?
<div>
<svg xmlns="http://www.w3.org/2000/svg" class="h-10 w-100" viewBox="21 21" fill="currentColor">
<path fill-rule="evenodd" d="M12.586 4.586a2 2 0 112.828 2.828l-3 3a2 2 0 01-2.828 0 1 1 0 00-1.414 1.414 4 4 0 005.656 0l3-3a4 4 0 00-5.656-5.656l-1.5 1.5a1 1 0 101.414 1.414l1.5-1.5zm-5 5a2 2 0 012.828 0 1 1 0 101.414-1.414 4 4 0 00-5.656 0l-3 3a4 4 0 105.656 5.656l1.5-1.5a1 1 0 10-1.414-1.414l-1.5 1.5a2 2 0 11-2.828-2.828l3-3z" clip-rule="evenodd" />
<text x='35' y='18' style='fill:#444444' class='text-2xl'>Share Link</text>
</svg>
<br />
<div style="display: flex; flex-direction: row; justify-content: space-between;">
<h1 class="text-left" id='text' style='user-select: all'><%= #vacancy.slug %>
<h2 class="text-right" id='text' style='user-select: all'>
<button onclick= "Copy(document.querySelector('#text').innerText)('#closemodal').click(function() {$('#modalwindow').modal('hide');});">
<svg class="align:right w-30 h-9" fill="none" stroke="currentColor" viewBox="0 0 25 25" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7v8a2 2 0 002 2h6M8 7V5a2 2 0 012-2h4.586a1 1 0 01.707.293l4.414 4.414a1 1 0 01.293.707V15a2 2 0 01-2 2h-2M8 7H6a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2v-2"></path>
</svg>
</button>
</h2>
</h1>
</div>
</div>
<div class="text-center md:text-right mt-4 md:flex md:justify-end"></div>
<script src="//cdn.jsdelivr.net/npm/sweetalert2#11"></script>
<script type='text/javascript'>
function Copy(text) {
var elem = document.createElement('textarea');
elem.value = text;
document.body.appendChild(elem);
elem.select();
document.execCommand('copy');
document.body.removeChild(elem);
Swal.fire({
position: 'center',
icon: 'success',
showConfirmButton: false,
timer: 600
})
}
</script>
</div>
I looked at the site for the library you're using, SweetAlert2 and here is what I found...
To add a close button, add showCloseButton: true to the object passed to Swal.fire()
https://sweetalert2.github.io/#configuration
To close the modal call Swal.close()
https://sweetalert2.github.io/#methods
I copied this card template from bootstrap for a warning card. At the header of the card, I'm using an svg that I got from Bootstrap's icons https://icons.getbootstrap.com/icons/exclamation-triangle-fill/. There, you can see some examples where the icon is implemented properly. The icon is aligned exactly in the middle next to the next. However, in my code the icon is aligned at the bottom and so is not centered. Is there a way to fix this?
<div class="card" style="width: 18rem;">
<div class="card-body">
<div class="mb-3">
<h5 class="card-title">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 5zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/>
</svg>
Warning
</h5>
</div>
<p class="card-text">
Text of card
</p>
</div>
</div>
Use negative margin-top to adjust it.
For example:
<div class="card" style="width: 18rem;">
<div class="card-body">
<div class="mb-3">
<h5 class="card-title">
<svg class="myIcon" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 5zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/>
</svg>
Warning
</h5>
</div>
<p class="card-text">
Text of card
</p>
</div>
</div>
CSS:
.myIcon { margin-top: -5px; }
Check it here: https://jsfiddle.net/8t61qehn/
printf("%d\n", 42); /* You can simply add some css on style part in as follows: */
.card-svg {
position: absolute;
left: 50%;
transform: translate(-50%, -50%);
}
.card-txt{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
/*And add this styles as classes on your HTML code as follows: */
<img class="card-svg" src="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 5zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"/>
<img>
<h5 class="card-txt">Warning</h5>
/By the way i changed the svg into img you can try like that if this is what you want./
My Result
Just change first DIV style with text-align: center
Check the image from above make sure that way you want show
drop like if work for you.
I have a grid with 3 columns: I need the first 1 column to always take the smallest amount of space possible, so the second column is tight with the text. I also need to cover a situation where the text of the first column can be huge:
Here I want the CSS to be exactly as is, since it's perfect. The CSS is really simple:
.container {
display: grid;
}
.children {
grid-row: 1;
}
How can I achieve the desired result with css grid?
Codepen link for minimal case: https://codepen.io/ilia-reingold/pen/RwrdELR
Update: adding code ->
.margin-top {
margin-top: 1rem;
}
.row {
display: flex;
flex-direction: row;
flex: 1;
align-items: center;
}
.title-container {
display: grid;
// grid-template-columns: auto 10% 10%;
}
.title {
grid-row: 1;
font-family: Poppins;
font-style: normal;
font-weight: 600;
font-size: 24px;
line-height: 36px;
color: #000000;
}
.container {
grid-row: 1;
}
.buttons {
grid-row: 1;
}
.description {
font-family: Rubik;
font-style: normal;
font-weight: normal;
font-size: 16px;
line-height: 19px;
color: #404A56;
}
.end {
justify-content: flex-end;
}
.container {
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
margin: 0 0.5rem;
align-items: center;
}
<div data-v-31045a46="" class="pagetop row margin-top">
<div data-v-31045a46="" class="title-container row">
<div data-v-31045a46="" class="text-ellipsis title"> Hardik's Favourite </div>
<div data-v-52c45aaf="" data-v-31045a46="" class="container">
<div data-v-52c45aaf="" class="status-button read-only">
<svg data-v-52c45aaf="" width="16" height="22" viewBox="0 0 16 22" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M13 7.5H14C15.1 7.5 16 8.4 16 9.5V19.5C16 20.6 15.1 21.5 14 21.5H2C0.9 21.5 0 20.6 0 19.5V9.5C0 8.4 0.9 7.5 2 7.5H3V5.5C3 2.74 5.24 0.5 8 0.5C10.76 0.5 13 2.74 13 5.5V7.5ZM8 2.5C6.34 2.5 5 3.84 5 5.5V7.5H11V5.5C11 3.84 9.66 2.5 8 2.5ZM2 19.5V9.5H14V19.5H2ZM10 14.5C10 15.6 9.1 16.5 8 16.5C6.9 16.5 6 15.6 6 14.5C6 13.4 6.9 12.5 8 12.5C9.1 12.5 10 13.4 10 14.5Z" fill="black" fill-opacity="0.54"></path>
</svg>
<span data-v-52c45aaf="">Read-only</span>
</div>
<div data-v-52c45aaf="" class="status-button shared pointer">
<svg data-v-52c45aaf="" width="20" height="14" viewBox="0 0 20 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M7 7C8.93 7 10.5 5.43 10.5 3.5C10.5 1.57 8.93 0 7 0C5.07 0 3.5 1.57 3.5 3.5C3.5 5.43 5.07 7 7 7ZM0 12.25C0 9.92 4.66 8.75 7 8.75C9.34 8.75 14 9.92 14 12.25V14H0V12.25ZM7 10.75C5.21 10.75 3.18 11.42 2.34 12H11.66C10.82 11.42 8.79 10.75 7 10.75ZM8.5 3.5C8.5 2.67 7.83 2 7 2C6.17 2 5.5 2.67 5.5 3.5C5.5 4.33 6.17 5 7 5C7.83 5 8.5 4.33 8.5 3.5ZM14.04 8.81C15.2 9.65 16 10.77 16 12.25V14H20V12.25C20 10.23 16.5 9.08 14.04 8.81ZM16.5 3.5C16.5 5.43 14.93 7 13 7C12.46 7 11.96 6.87 11.5 6.65C12.13 5.76 12.5 4.67 12.5 3.5C12.5 2.33 12.13 1.24 11.5 0.35C11.96 0.13 12.46 0 13 0C14.93 0 16.5 1.57 16.5 3.5Z" fill="#6E6F73"></path>
</svg>
<span data-v-52c45aaf="">Shared with team</span>
</div>
</div>
<div data-v-31045a46="" class="buttons row end">
<button data-v-5ea9ad22="" data-v-31045a46="" data-testid="button" class="button">
<div data-v-5ea9ad22="" class="centered">
<svg data-v-31045a46="" width="22" height="22" viewBox="0 0 22 22" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-5ea9ad22="">
<rect x="7" y="7" width="14" height="14" rx="2" stroke="black" stroke-width="2"></rect>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3 2H13C13.5523 2 14 2.44772 14 3V6H16V3C16 1.34315 14.6569 0 13 0H3C1.34315 0 0 1.34315 0 3V13C0 14.6569 1.34315 16 3 16H6V14H3C2.44772 14 2 13.5523 2 13V3C2 2.44772 2.44772 2 3 2Z" fill="black"></path>
</svg>
<span data-v-5ea9ad22=""> Copy </span>
</div>
</button>
<button data-v-5ea9ad22="" data-v-31045a46="" data-testid="button" class="disabled button">
<div data-v-5ea9ad22="" class="centered">
<svg data-v-31045a46="" width="14" height="12" viewBox="0 0 14 12" fill="none" xmlns="http://www.w3.org/2000/svg" data-v-5ea9ad22="">
<path d="M13.7728 4.22774L8.96019 0.15672C8.53894 -0.199663 7.875 0.0896491 7.875 0.643255V2.78753C3.4828 2.83679 0 3.6991 0 7.77658C0 9.42231 1.08229 11.0527 2.27864 11.9051C2.65196 12.1711 3.18402 11.8373 3.04637 11.4061C1.80649 7.52179 3.63445 6.4906 7.875 6.43084V8.7857C7.875 9.34016 8.53946 9.62819 8.96019 9.27223L13.7728 5.20081C14.0755 4.94469 14.0759 4.48421 13.7728 4.22774Z" fill="#8d8f93"></path>
</svg>
<span data-v-5ea9ad22=""> Share </span>
</div>
</button>
<div data-v-31045a46="" role="listbox" tabindex="0" class="ui dropdown dropdown icon disabled-grey-btn" compact="compact">
<i aria-hidden="true" class="ellipsis horizontal icon"></i><span class="sizer"></span>
<div tabindex="-1" class="menu transition"></div>
</div>
</div>
</div>
</div>
You can achieve that by using grid-template-columns property.
.container {
display: grid;
grid-template-columns:20% 40% 40%; //It's just a hit, try on your own
}
You can add this to your CSS
.text-ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Result:
I have the following html:
<div class="text-center">
<img src="~/images/prof_grade_tech.svg" height="32" />
<span>Professional Grade Technology</span>
</div>
It comes out looking like this:
I would like to move the text span down by 2 pixels to better align it with the image. I've tried adding margin, padding, invisible border, but nothing seems to help. I've added vertical-align:bottom to the image and that kind of worked, but it moved the image too far down.
So how do I move the text 2 pixels down?
Consider these default factors:
<span> is an inline level element, top/bottom padding/margin will not apply.
vertical-align is set to baseline - aligns the baseline of the element.
To center align them vertically:
Option 1:
img, span {
display: inline-block;
vertical-align: middle;
}
span {
margin-bottom: -2px;
}
<div class="text-center">
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M7.5 0h1v3h-1zm0 13h1v3h-1zM16 7.5v1h-3v-1zm-13 0v1H0v-1zM1.99 2.697l.707-.707 2.121 2.12-.707.708zm9.192 9.193l.707-.708 2.121 2.121-.707.707zm2.121-9.9l.707.707-2.12 2.121-.708-.707zM4.11 11.182l.708.707-2.121 2.121-.707-.707zM8 10.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zm0 1a3.5 3.5 0 1 1 0-7 3.5 3.5 0 0 1 0 7z'%3E%3C/path%3E%3C/svg%3E" width="32" height="32" />
<span>Professional Grade Technology</span>
</div>
Option 2:
img, span {
display: inline-block;
vertical-align: middle;
}
span {
position: relative;
bottom: -2px;
}
<div class="text-center">
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M7.5 0h1v3h-1zm0 13h1v3h-1zM16 7.5v1h-3v-1zm-13 0v1H0v-1zM1.99 2.697l.707-.707 2.121 2.12-.707.708zm9.192 9.193l.707-.708 2.121 2.121-.707.707zm2.121-9.9l.707.707-2.12 2.121-.708-.707zM4.11 11.182l.708.707-2.121 2.121-.707-.707zM8 10.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zm0 1a3.5 3.5 0 1 1 0-7 3.5 3.5 0 0 1 0 7z'%3E%3C/path%3E%3C/svg%3E" width="32" height="32" />
<span>Professional Grade Technology</span>
</div>
Option 3:
img, span {
display: inline-block;
vertical-align: middle;
}
span {
transform: translateY(2px);
}
<div class="text-center">
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M7.5 0h1v3h-1zm0 13h1v3h-1zM16 7.5v1h-3v-1zm-13 0v1H0v-1zM1.99 2.697l.707-.707 2.121 2.12-.707.708zm9.192 9.193l.707-.708 2.121 2.121-.707.707zm2.121-9.9l.707.707-2.12 2.121-.708-.707zM4.11 11.182l.708.707-2.121 2.121-.707-.707zM8 10.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zm0 1a3.5 3.5 0 1 1 0-7 3.5 3.5 0 0 1 0 7z'%3E%3C/path%3E%3C/svg%3E" width="32" height="32" />
<span>Professional Grade Technology</span>
</div>
Option 4:
div {
display: flex;
align-items: center;
}
span {
margin-left: 4px;
margin-bottom: -2px;
}
<div class="text-center">
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M7.5 0h1v3h-1zm0 13h1v3h-1zM16 7.5v1h-3v-1zm-13 0v1H0v-1zM1.99 2.697l.707-.707 2.121 2.12-.707.708zm9.192 9.193l.707-.708 2.121 2.121-.707.707zm2.121-9.9l.707.707-2.12 2.121-.708-.707zM4.11 11.182l.708.707-2.121 2.121-.707-.707zM8 10.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5zm0 1a3.5 3.5 0 1 1 0-7 3.5 3.5 0 0 1 0 7z'%3E%3C/path%3E%3C/svg%3E" width="32" height="32" />
<span>Professional Grade Technology</span>
</div>
Apply display: inline-block; and position: relative; to the image. Now you can move it in relation to its default position, for example by adding bottom: -2px
(I applied -6px in the snippet below to make it a bit more obvious)
As an alternative, you could apply similar settings to the span to move the text instead of the image.
img {
display: inline-block;
position: relative;
bottom: -6px;
}
<div class="text-center">
<img src="https://picsum.photos/id/1/40/20" height="32" width="auto" />
<span>Professional Grade Technology</span>
</div>
You can use different divs and with that use the margin or padding!
<div class="text-center">
<img src="~/images/prof_grade_tech.svg" height="32" />
<span>Professional Grade Technology</span>
</div>
<div id="span2" class="text-center">
<span>Professional Grade Technology</span>
</div>
<!-- CSS FILE --!>
#span2{
margin-top: 2px;
}
In my opinion, I suggest to append some div tags inside the logo.
By using 2 div tags within float: left, we make the 2 div is inline.
Combine display: table and display: table-cell to vertical center the height of divs.
.float-left {
float: left;
}
.d-table {
display: table;
height: 32px;
}
.d-table-cell {
display: table-cell;
}
.align-middle {
vertical-align: middle;
}
<div class="text-center">
<div class="float-left">
<div class="d-table">
<div class="d-table-cell align-middle">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/67/Firefox_Logo%2C_2017.svg/1024px-Firefox_Logo%2C_2017.svg.png" height="32" />
</div>
</div>
</div>
<div class="float-left">
<div class="d-table">
<div class="d-table-cell align-middle">
<span>Professional Grade Technology</span>
</div>
</div>
</div>
</div>
What's the best way to center an SVG horizontally and vertically an SVG inside a div tag?
I know some ways are better than others, but for this what would be the best way of doing it?
<div style="width: 64px;height: 64px;background-color: rgba(0,0,0,.7);background-repeat: no-repeat;background-size: 24px;background-position: 58% 50%;border-radius: 500px;border: 1px solid blue;cursor: pointer;">
<svg viewBox="-22 0 1229 1481" width="24" height="29" style="display:block;margin: 0 auto;background-color:green;">
<path d="M0 1394V87C0 46.3 13.3 19.8 40 7.5 66.7-4.8 98.7.3 136 23l1034 634c37.3 22.7 56 50.3 56 83s-18.7 60.3-56 83L136 1458c-37.3 22.7-69.3 27.8-96 15.5-26.7-12.3-40-38.8-40-79.5z" fill="red"/>
</svg>
</div>
If you plan on setting fixed positions, pixel sizes and margins yourself, just adjust the svg vertical margin.
<div style="width: 64px;height: 64px;background-color: rgba(0,0,0,.7);background-repeat: no-repeat;background-size: 24px;background-position: 58% 50%;border-radius: 500px;border: 1px solid blue;cursor: pointer;">
<svg viewBox="-22 0 1229 1481" width="24" height="29" style="display:block;margin:16px auto;background-color:green;">
<path d="M0 1394V87C0 46.3 13.3 19.8 40 7.5 66.7-4.8 98.7.3 136 23l1034 634c37.3 22.7 56 50.3 56 83s-18.7 60.3-56 83L136 1458c-37.3 22.7-69.3 27.8-96 15.5-26.7-12.3-40-38.8-40-79.5z" fill="red"/>
</svg>
</div>
use this css style for your SVG element
margin: 0 auto;
display: block;
and this css for DIV element
display: flex;
align-items: center;
height: 100%;