How to change text when scaling in %? - css

I have this code. Text changes when scaling through vw. How to do everything the same, only through % ?
https://jsfiddle.net/Camiastrw/bdg9rotm/
CSS
.container{
display: flex;
justify-content: space-between;
align-items:center;
padding: 1rem 2rem 0.75rem 2rem;
}
.wrapper{
align-items: center;
display: flex;
}
.qwe{
height: 40px;
width: 40px;
border: 1px solid #000;
margin-right:2rem;
}
.main-content{
max-width: calc(100vw - 15rem);
}
.text{
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

Related

First item is getting pushed down by title it seems. What is a common approach to fix this problem and keep everything centered?

The left most item is not aligned with the rest of the items. How to i center them correctly?
.activities{
display: flex;
align-items: center;
flex-direction: column;
padding-top: 25px;
background-color: #F3FAEF;
text-align: center;
}
.activities-image{
border-radius: 50%;
width: 150px;
height: 150px;
}
.activities-header{
font-size: 18px;
font-weight: bold;
}
.activities-cols{
display: flex;
align-items: center;
text-align: center;
}
.activity-col{
border: 1px solid red;
width: 330px;
height: 330px;
}
Demo: https://codepen.io/AdanRod133/pen/jOxPBEX
Full-page: https://codepen.io/AdanRod133/full/jOxPBEX
.activity-col {
border: 1px solid red;
width: 330px;
height: 330px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

Flex Column forcibly hides the initial items of the flexbox

I have a Sidebar which is built using FlexBox column layout as shown below:
.SideBarContainer {
// flex-grow: 1;
width: 100%;
height: 100%;
// display: flex;
// flex-direction: column;
padding: 0.5rem 1rem;
align-items: center;
justify-content: space-evenly;
overflow-y: auto;
overflow-x: hidden;
font-family: $font-family;
}
And looks like:
This is when I comment out flex layout (ideally which I want to keep). But when I enable flex layout as shown below:
.SideBarContainer {
// flex-grow: 1;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
padding: 0.5rem 1rem;
align-items: center;
justify-content: space-evenly;
overflow-y: auto;
overflow-x: hidden;
font-family: $font-family;
}
for some reason it forces the image to be shifted to top and it can't be scrolled to the view:
One way would be to get rid of flexbox and somehow align the items to center but I am more interested in understanding how can I achieve the same with FlexBox and what exactly it is that's pushing the image to cut off when flexbox is applied.
I have created this html code and CSS for you:
.main {
width: calc(100%/3 + 60px);
font-family: 'Jost', sans-serif;
}
.SideBarContainer {
display: flex;
flex-direction: column;
}
.name {
margin: 0;
font-size: 30px;
}
.desig {
color: #bcbcbc;
font-weight: 600;
}
.profile-img {
border-radius: 100%;
height: 100px;
width: 100px;
object-fit: cover;
}
.btn {
background-color: #f5f5f5;
color: #000000;
display: inline-block;
text-align: center;
text-decoration: none;
font-size: 16px;
padding: 4px 20px;
margin: 10px 0;
width: fit-content;
box-shadow: 0 0 5px 0 rgb(0 0 0 / 20%);
}
.btn.dark {
background-color: #000;
color: #f3ff26;
text-transform: capitalize;
font-weight: 400;
font-size: 18px;
width: calc(100% - 60px);
border-radius: 8px;
box-shadow: 0 0 5px 0 rgb(0 0 0 / 20%);
}
<div class="main">
<div class="SideBarContainer">
<img src="https://via.placeholder.com/150x150" class="profile-img" />
<h6 class="name">Rampy sharma</h6>
<span class="desig">Individual Singer</span>
Edit
<p>It is a long established fact that a reader will be distracted by the readable that it has a more-or-less normal distribution of letters, as opposed to using 'Content here.</p>
portfolio
</div>
</div>

How can I expand the empty margins on flex items?

The dark gray area is clickable but the blue margin has no action. How can I expand the rest of the smaller sized items to fill in the space?
div.scrollmenu {
display:flex;
justify-content: flex-start;
align-items: center;
background-color: #333;
overflow: auto;
flex-wrap: nowrap;
}
div.scrollmenu a {
display: flex;
color: white;
text-align: left;
padding: 14px;
text-decoration: none;
margin: auto;
min-width: 25%;
max-width: 25%;
}
Add the align-items: stretch; property to your div.scrollmenu and tweak your code a bit.
div.scrollmenu {
display:flex;
/* align-items: stretch; */ /* redundant */
background-color: #333;
flex-wrap: nowrap;
}
div.scrollmenu a {
display: flex;
align-items: center;
/* uncomment this if you want them to be centered horizontally */
/*justify-content: center;*/
padding: 1 14px;
color: white;
text-align: left;
text-decoration: none;
flex: 1;
}
Hope this helps.
EDIT You don't even need align-items: stretch because I believe that's the default property since the result is the same even if you leave it out.

Position sticky strange rendering

I have simple navigation bar with position:sticky that displays not clear when scrolled and everything seems to work fine then it is in the top.
As you can see from the images above there seems to be some render problem. Here is the css:
body{
/*For demo purpose*/
height:300vh;
}
* {
font-family: RobotoThin;
margin: 0;
padding: 0;
overflow-x: hidden;
outline: none;
-webkit-transition: 1s;
transition: 1s;
box-sizing: border-box;
background-repeat: no-repeat;
transition: 0.5s !important;
scroll-behavior: smooth;
}
div.window {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
box-sizing: border-box;
padding: calc(2vh + 2vw);
height: 100vh;
width: 95vw;
position: absolute;
right: 0;
top: 0;
display: none;
white-space: nowrap;
display: flex;
-ms-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
background-color: #ecf0f1;
margin-left: 5vw;
}
#help{
display:block;
transition:0s !important;
}
div#help{
height:200vh;
white-space: normal;
}
div#help a{
color:red;
text-decoration: none;
}
div#nav {
top: 0;
position: sticky;
display: flex;
justify-content: space-between;
color: black;
background-color: white;
padding-top: 1vmax;
padding-bottom: 1vmax;
font-size: 1.2vmax;
flex-wrap: wrap;
border-radius: 10em;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
div#nav>a {
color: black;
}
div#nav>*:hover {
color: gold;
letter-spacing: 0.3vw;
}
div#nav> :first-child {
margin-left: 1vw;
}
div#nav> :last-child {
margin-right: 1vw;
}
<body>
<div class='windows' id='help'>
<div id='nav'> <a>General important info</a> <a>Desktop</a> <a>Math calculators</a> <a>Notes</a> <a>Battery</a> <a>Quotes</a> <a>Settings</a> <a>Passwords and Data</a> </div>
</div>
</body>
Don't mind the color. I use a plugin so you will see everything in white, not in black.
Strangely I couldn't get the example to work properly and I can not represent the issue. Hopefully you can take a look at my code and tell what may cause this problem.
After much fiddling, the culprit is:
overflow-x: hidden;
body {
/*For demo purpose*/
height: 300vh;
}
* {
font-family: RobotoThin;
margin: 0;
padding: 0;
/* overflow-x: hidden; <-- The problem */
outline: none;
-webkit-transition: 1s;
transition: 1s;
box-sizing: border-box;
background-repeat: no-repeat;
transition: 0.5s !important;
scroll-behavior: smooth;
}
div.window {
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
-webkit-justify-content: center;
justify-content: center;
box-sizing: border-box;
padding: calc(2vh + 2vw);
height: 100vh;
width: 95vw;
position: absolute;
right: 0;
top: 0;
display: none;
white-space: nowrap;
display: flex;
-ms-flex-wrap: wrap;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
background-color: #ecf0f1;
margin-left: 5vw;
}
#help {
display: block;
transition: 0s !important;
}
div#help {
height: 200vh;
white-space: normal;
}
div#help a {
color: red;
text-decoration: none;
}
div#nav {
top: 0;
position: sticky;
display: flex;
justify-content: space-between;
color: black;
background-color: white;
padding-top: 1vmax;
padding-bottom: 1vmax;
font-size: 1.2vmax;
flex-wrap: wrap;
border-radius: 10em;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
div#nav>a {
color: black;
}
div#nav>*:hover {
color: gold;
letter-spacing: 0.3vw;
}
div#nav> :first-child {
margin-left: 1vw;
}
div#nav> :last-child {
margin-right: 1vw;
}
<body>
<div class='windows' id='help'>
<div id='nav'> <a>General important info</a> <a>Desktop</a> <a>Math calculators</a> <a>Notes</a> <a>Battery</a> <a>Quotes</a> <a>Settings</a> <a>Passwords and Data</a> </div>
</div>
</body>

Over flow scroll not working

.main-content{
height: 100%;
width: 60%;
min-height: 800px;
background-color: white;
border-radius: 5px;
margin-left: 1%;
border: solid 1px black;
}
.profile-banner{
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 100%;
height: 7vw;
margin-top: 7%;
background-color: rgba(71, 135, 195, 0.5);
}
.profile-avatar{
width: 18%;
margin-right: 3%;
img{
width: 100%;
border: solid white 2px;
}
}
.profile-username{
margin-left: 5%;
font-size: 4vw;
color: $font-blue;
font-family: 'Titillium Web', sans-serif;
-webkit-text-stroke: 1px white;
}
.profile-second-sec{
margin-top: 8%;
height: 20vw;
background-color: blue;
}
.profile-third-sec{
display: flex;
flex-direction: row;
align-items: center;
margin-top: 8%;
height: 30vw;
background-color: grey;
overflow-x: scroll;
white-space: nowrap
}
.profile-image-container{
display: flex;
align-items: center;
}
<div class="main-content">
<div class="tab-header font-large">
<i class="fa fa-user"></i> User profile
</div>
<div class="profile-banner flerowspb">
<div class="profile-username">
User profile
</div>
<div class="profile-avatar">
Avatar image
</div>
</div>
<div class="profile-second-sec">
</div>
<div class="profile-third-sec">
>> This is where the images go <<
</div>
</div>
EDIT: added in code snippit, Hope it helps
I trying to create a horizontal scroll div but when i add the content images all it does is squeeze all the images inside of it like so,
So its resizing the images to fit in but i would like them to be normal size and be able to scroll.
Now i tried to add overflow scroll but its not having that effect
.profile-third-sec{
display: flex;
flex-direction: row;
align-items: center;
margin-top: 8%;
height: 30vw;
background-color: $font-grey;
overflow-x: scroll;
}
.profile-image-container{
display: flex;
align-items: center;
}
Now i thought i knew enough on this to be able to do but obviously not! So any ideas will be appreciated.
Thanks
You can remove the flexbox rules. Then provide the image with some properties. Using white-space and overflow should work for you.
example:
.main-content {
height: 100%;
width: 60%;
min-height: 800px;
background-color: white;
border-radius: 5px;
margin-left: 1%;
border: solid 1px black;
}
.profile-banner {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 100%;
height: 7vw;
margin-top: 7%;
background-color: rgba(71, 135, 195, 0.5);
}
.profile-avatar {
width: 18%;
margin-right: 3%;
img {
width: 100%;
border: solid white 2px;
}
}
.profile-username {
margin-left: 5%;
font-size: 4vw;
color: $font-blue;
font-family: 'Titillium Web', sans-serif;
-webkit-text-stroke: 1px white;
}
.profile-second-sec {
margin-top: 8%;
height: 20vw;
background-color: blue;
}
.profile-third-sec {
margin-top: 8%;
height: 30vw;
background-color: grey;
overflow-x: scroll;
white-space: nowrap
}
.prgile-third-sec img {
display: block;
width: 100%;
height: auto;
}
.profile-image-container {
display: flex;
align-items: center;
}
<div class="main-content">
<div class="tab-header font-large">
<i class="fa fa-user"></i> User profile
</div>
<div class="profile-banner flerowspb">
<div class="profile-username">
User profile
</div>
<div class="profile-avatar">
Avatar image
</div>
</div>
<div class="profile-second-sec">
</div>
<div class="profile-third-sec">
<img src="https://unsplash.it/300">
<img src="https://unsplash.it/300">
<img src="https://unsplash.it/300">
<img src="https://unsplash.it/300"></div>
</div>
Flex have default wrap property, you can try on your code based on following stylesheet.
.className {
display: flex;
flex-wrap: nowrap;
overflow: auto;
-webkit-overflow-scrolling: touch;
-ms-overflow-style: -ms-autohiding-scrollbar;
}
.class {
display: flex;
flex-wrap: nowrap;
}

Resources