How can I space evenly in both directions? - react-native

I am developing a React Native app using Expo and I am using Styled Components.
At boot, it downloads a list of languages via an API and the flags of those languages are displayed on a selection screen.
I'm using flex-wrap so, right now, I have 6 languages, three rows, 2 flags in each row.
I am trying to figure out how to use flexbox so that the flags are spaced evenly in both directions.
I'm using flex-wrap and get even-spacing on the row.
How do I do the same column-wise, bearing in mind that the quantity of flags is dynamic?
I'd like the screen of languages to have even-spacing around the flags, both vertically and horizontally.

Ill suggest you doing that via Dimensions,
const screenWidth = Dimensions.get("window").width
Suppose you want to render 3 flags in a row and column can be N
so each Flag suppose takes up const eachWidth = (screenWidth-(gutterSpace+marginHorizontal))/3
Now so basically your marginHorizontal can be used as marginVertical so that all things are properly spaced.
const marginHorizontal = 20;
const gutterSpace = 10;
//Flag view
<View style={{width:eachWidth, margin:marginHorizontal}}/>
Hope it works, feel free for doubts

Could adding align-items: center work? Perhaps also setting height: 100vh if you're making a selection screen.
section {
display: flex;
flex-wrap: wrap;
height: 100vh;
align-items: center;
}
div {
box-sizing: border-box;
padding: 8px;
width: 50%;
border: 1px solid black;
text-align: center;
}
<section>
<div>flag</div>
<div>flag</div>
<div>flag</div>
<div>flag</div>
<div>flag</div>
<div>flag</div>
</section>

Related

Vuetify: How to create a triangle badge?

I understand if I use v-badge, I get a circle badge but I want a triangle badge instead like below.
Could anyone give an advice of how to make it?
Thank you.
You could use the v-badge's badge slot to insert a div with 1, and style that div
In the template, apply a class to v-badge (named "triangle"), and insert a div in the badge slot to contain the number along with a class (named "my-badge"):
<v-badge class="triangle">
<template v-slot:badge>
<div class="my-badge">1</div>
</template>
</v-badge>
Add CSS styles for the .triangle .v-badge__badge and .my-badge:
.triangle .v-badge__badge {
/* remove border radius to allow icon to fill space */
border-radius: 0;
/* use a clip-path to form a quirky triangle */
clip-path: polygon(100% 51%, 0 0, 3% 100%);
height: 30px;
width: 30px;
}
.my-badge {
display: flex;
justify-content: center;
align-items: center;
padding-right: 0.9em;
font-size: 14px;
height: 100%;
color: #fff;
background: green;
}
demo

how to reset styles in vue carousel?

I am using vue carousel and I want to change tge color of the pagination dots' borders. I don't know how and if it's even possible. I looked up the style of this buttons in dev tools and tried to rewrite the style. But nothing works
vue-carousel has two properties that control the color of the dots:
paginationColor - (default: #000000) The fill color of the active pagination dot. Any valid CSS color is accepted.
paginationActiveColor - (default: #efefef) The fill color of pagination dots. Any valid CSS color is accepted.
For example:
<carousel paginationColor="gray" paginationActiveColor="red">
demo
Try this in your global CSS
.v-carousel__controls__item{
color: #FFC400 !important;
}
There is a work-around that can give you full control over the dots and their appearance with pure CSS, using pseudo-elements. Make the existing dots transparent, and use ::after to create new dots that you can style as you like.
.VueCarousel-dot {
position: relative;
background-color: transparent !important;
&::after {
content: '';
width: 10px;
height: 10px;
border-radius: 100%;
border: 2px solid black;
background-color: gray;
position: absolute;
top: 10px;
left: 10px;
}
&--active::after {
background-color: red;
}
}
This is not an ideal solution, however the provided options for styling dots in Vue Carousel are quite limited, and if you have a strict style guide to follow, this solution can give you the control you need.

Can I replace the button displayed by Blazor's InputFile component with another element?

I am using the element to upload image files to my hosted Blazor WASM site. The component renders a button with the words "Choose Files" on it.
I would like to replace this button with an image (or my own text, or anything else). I have tried using CSS to set a background image to the URL of an image I would want to use, and set the background-color of the button to "transparent", but this does not seem to change anything.
The source code for this component can be found here:
https://github.com/SteveSandersonMS/BlazorInputFile
I studied the code and found that this component is built using the standard Blazor input type.
<input type=file>
Steve shows a way to override the default functionality and style of the button using CSS.
Here is an example I created based on what I found:
<style>
.file-input-zone {
display: flex;
align-items: center;
justify-content: center;
background-color: blue;
color: white;
cursor: pointer;
position: relative;
width: 120px;
height: 30px;
}
.file-input-zone:hover {
background-color: lightblue;
}
.file-input-zone input[type=file] {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
}
</style>
<div class="file-input-zone">
<InputFile />
Get me a file!
</div>
It will give you a button that looks like this:
You might pick up more tips by studying his source code further.

Is there a bug in WebKit/Blink's implementation of flexbox's flex-flow: column wrap?

Is this a bug in WebKit/Blink?
I'm trying to implement an article summary page similar to that of a newspaper: article summaries flow down and 'wrap' from left to right, exactly as specified in the flex-direction and flex-wrap sections of the W3 specification. The remaining space in a column should be redistributed evenly between the blocks that occupy it (just like flex-grow: 1).
See the JSFiddle.
Firefox appears to have implemented this correctly, but I get a very strange layout from Chrome and Safari.
If this is indeed a bug, is there a workaround?
Firefox:
Chrome/Safari:
If you change max-height: 24rem to height: 24rem; then it works in Chrome.
It looks like Chrome is calculating the height based on the smallest block.
body {
background: #C6C2B6;
}
section {
background: white;
display: flex;
flex-flow: column wrap;
align-content: flex-start;
height: 24rem;
}
article {
background: #48929B;
flex: 1 0 auto;
min-height: 10rem;
width: 4rem;
margin: 0.5rem;
}
.big {
min-height: 14rem;
}
<section>
<article></article>
<article></article>
<article class="big"></article>
<article></article>
</section>

Line-height on nav in safari is different than every other browser

I have looked all over for a solution to this problem and nothing seems to work and I really don't want to use a hack if I can avoid it.
When I set the line-height to vertically center my nav it's centered everywhere but safari, it's sitting about 2px high. Here is the css for the nav bar:
nav {
padding: 0px;
margin: 0;
font-size: 16px;
height: 25px;
}
nav ul {
padding-left: 0px;
margin: 0;
line-height: 1.5em;
}
nav li{
display: inline;
text-transform: uppercase;
padding-right: 12px;
padding-left: 12px;
}
I've tried line-height in px, em, and % and it's still wrong in safari. Here is a screenshot of the correct nav position in firefox and the wrong position in safari.
Any help on this issue is much appreciated.
Some browser specific default styles could be interfering your defined styles. (Inherited styles, default more specifically defined styles for certain elements...)
For homogenous behavior in all browsers, use a CSS reset and define all the needed styles properly, not depending on browsers' defaults.
Here is a good source: http://meyerweb.com/eric/tools/css/reset/