How to stop the influence of CSS grid to just what's visible. Experimenting on vertical buttons - css

I'm experimenting on vertical buttons using CSS display grid & inline-grid and have them working. It's when I try to add regular buttons that things go wrong.
The image displays the issue.
]1
The grid's influence extends out past the visible items it contains and hence the "control" buttons are ending up below the vertical buttons instead of up top next to the first vertical button. I've tried surrounding the grid divs with other divs to try to contain their influence, but no luck.
How do I get the "control" buttons currently at the bottom back up toward the top?
<div id="control">
<div id="title">
Buttons In Grid
</div>
<div class="sideButtonsOuterContainer">
<div class="sideButtonsInnerContainer">
<button id="buttonR0" class="sideButtons">A</button>
<button id="buttonR1" class="sideButtons">B</button>
<button id="buttonR2" class="sideButtons">C</button>
</div>
<div class="sideButtonsInnerContainer">
<button id="buttonR3" class="sideButtons">D</button>
<button id="buttonR4" class="sideButtons">E</button>
<button id="buttonR5" class="sideButtons">F</button>
</div>
<div class="sideButtonsInnerContainer">
<button id="buttonR6" class="sideButtons">G</button>
<button id="buttonR7" class="sideButtons">H</button>
<button id="buttonR8" class="sideButtons">I</button>
</div>
</div>
<div id="sideControls">
<button class="topButtons">Control</button>
<button class="topButtons">Control</button>
<button class="topButtons">Control</button>
<button class="topButtons">Control</button>
<button class="topButtons">Control</button>
</div>
</div>
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
#control{
width: 20%;
}
#title{
text-align: center;
font-size: 43px;
color: rgb(255, 0, 0);
}
.sideButtonsOuterContainer{
display: grid;
width: 52px;
grid-template-rows: auto auto auto;
gap: 10px;
background-color: #000000;
padding-left: 0px;
padding-right: 0px;
padding-top: 10px;
padding-bottom: 10px;
}
.sideButtonsInnerContainer {
display: inline-grid;
width: 45px;
grid-template-rows: auto auto auto;
gap: 4px;
padding: 3px;
}
.sideButtons{
background-color: #4CAF50; /* Green */
color: white;
width: 45px;
height: 127px;
text-align: center;
font-size: 38px;
}
.topButtons{
background-color: #4CAF50; /* Green */
border: none;
color: white;
text-align: center;
text-decoration: none;
font-size: 38px;
}

Related

How to display element on the right between elements using css

I have element 1, element 2, element 3 on may page, how can i place element3 on right top below element1 in right top?
It should looks like on the screen below:
I read a lot of examples but it didn't work for me,
i have tried to use
position: absolute;
float: right;
with position: absolutel it places this element on the top of the page but i don't want it,
the maximum i achievedit's right bottom position
Also i tried to use:
margin-top: -150px;
it didn't help neither, while minimizing windows it becomes a mess:
Please help me to solve this issue ?
Edited:
1999,19,1600+,8 is .hero-fact-title,
Founded in Helsinki, Offices, Digital Natives, Design Studios is .hero-fact-description, .fact-summary is that text i want to move also it element3.
.fact-wrapper {
margin-top: 10px;
display: grid;
grid-template-columns: 300px 1fr;
grid-gap: 3px;
//display: inline-block;
&__hero-fact-title {
width: 90px;
height: 42px;
font-family: MaisonNeue;
font-size: 32px;
font-weight: bold;
font-stretch: normal;
font-style: normal;
letter-spacing: -1px;
color: #333333;
}
&__hero-fact-description {
width: 193px;
height: 22px;
font-family: MaisonNeue;
font-size: 16px;
font-weight: normal;
font-stretch: normal;
font-style: normal;
letter-spacing: normal;
color: #333333;
}
}
.fact-summary {
width: 596px;
height: 96px;
font-family: MaisonNeue;
font-size: 24px;
font-weight: normal;
font-stretch: normal;
font-style: normal;
line-height: 1.33;
letter-spacing: normal;
color: #333333;
float: right;
}
to display this mess on page i use the code below:
<div className="fact-wrapper">
{facts.map(obj => {
return (
<div>
<div className="fact-wrapper__hero-fact-title">{obj.title}</div>
<div className="fact-wrapper__hero-fact-descriptio">
{obj.description}
</div>
</div>
)
})}
</div>
<h2 className="fact-summary">{factSummary}</h2>
Use flexbox
.container {
display: flex;
flex-direction: column;
justify-content: center;
width: 80%;
margin: 0 auto;
}
.bottom {
display: flex;
align-items: flex-start;
}
.box {
display: flex;
flex: 1;
margin: 5px;
}
.box-one {
border: 2px solid tomato;
padding: 2rem 5px;
}
.box-two {
border: 2px solid teal;
padding: 2rem 5px;
}
.box-three {
border: 2px solid goldenrod;
padding: 1rem 5px;
}
<div class="container">
<div class="top">
<div class="box box-one">box one</div>
</div>
<div class="bottom">
<div class="box box-two">box two</div>
<div class="box box-three">box three</div>
</div>
</div>
I'd propose you to use flex.
Basically you have here two lines.
The first line is a simple div. The second line is a combination of two divs side by side.
There are multiple options to place them side by side you, but it's usually better for future changes to use flex.
To make it work you need to
1. Add "display: flex" to the parent div.
2. Add "flex-grow: 1" style to children. That's it.
Flex-grow defines the ability for a flex item to grow if necessary.
<div>
<div class='block'>Element 1</div>
<div class='parent'>
<div class='block child'>Elemet 2</div>
<div class='block child'>Elemet 3</div>
</div>
</div>
.parent {
display: flex;
}
.child {
flex-grow: 1;
}
.block {
padding: 10px;
border: 1px solid #ccc
}
Example: https://codepen.io/tony-freed/full/vYOrYVE
You can learn more about it here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
You could use Flexbox, giving flex-basis: 100% to the first element, e.g.
main {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: space-between;
}
div {
box-sizing: border-box;
border: 5px solid currentColor;
flex-basis: calc(50% - 5px);
margin-bottom: 10px;
}
.e1 { color: red; flex-basis: 100%; }
.e2 { color: blue; }
.e3 { color: green; }
<main>
<div class="e1">element 1</div>
<div class="e2">element 2 <br /><br />Lot of text</div>
<div class="e3">element 3</div>
</main>

Ionic app not responsive need help in scss

I have done the app which is clone of wouldyourather . i have a problem its working fine on samsung normal size devices . but in bigger screen phone its not responsive if any one can help how ill do this to responsive on every device ?
i know just need to change some css if any one can help ? Thanks
html
<ion-navbar color="grey" center>
<ion-title >Would You Rather ?</ion-title>
<ion-buttons class="bttn" right><button right class="bttn" (click)="presentPrompt()"> <ion-icon color="light" name="md-more"></ion-icon></button></ion-buttons>
</ion-navbar>
</ion-header>
<ion-content class="background">
<ion-slides *ngIf="questions" #slides (ionSlideDidChange)="slideChanged()" class="slidee">
<ion-slide *ngFor="let question of questions | async; let i = index;" >
<!-- <div class="orca">
this is for or round
</div> -->
<!-- <h3>Question {{i+1}}</h3> -->
<div class="quizcontainer" >
<div class="upper" text-center (click)="show(question.ckc)" (click)="clickedButton(1,question.would)" >
<p *ngIf="showclicks" style="color: white" item-end class="p1">{{ clickPercentage1 }}% </p>
<div class="another"><p class="q1" style="text-align: center;">{{question.would}}</p> </div>
</div>
<div class="or" style="color: white" ><p class="pp">OR </p></div>
<div class="down" text-center (click)="show(question.ckc)" (click)="clickedButton(2,question.rather)" >
<p *ngIf="showclicks" style="color: white" item-end class="p1">{{ clickPercentage2 }}% </p>
<div class="another"> <p class="q1" >{{question.rather}}</p></div>
</div>
</div>
</ion-slide>
</ion-slides>
</ion-content>
scss
page-newp {
ion-icon {
font-size: 40px; //Preferred size here
}
.bttn{
background-color: transparent; // <===== For change the icon background color //
}
ion-title {
text-align: center;
font-family: "Comic Sans MS" !important;
font-weight: 650 !important;
}
.upper{ // <==== Red Box / uppwer box class //
position: relative;
background-color: red !important; // <===== For change the red color //
height: 50% !important;
color: white;
justify-content: center;
align-items: center;
}
.background {
background-color: #383838; //<==== For change the Background color //
}
.pp {
text-align: center;
font-family: "Comic Sans MS" !important;
font-weight: 500;
font-size:22px;
}
.or{
margin-top: -15px;
position: relative;
height: 0%;
height: 0.2%;
}
.down{ //<==== Blue Box / lower box class //
position: relative;
margin-top: 33px;
width: 100%;
background-color: blue !important; // <===== For change the blue color //
height: 60% !important;
color: white;
justify-content: center;
align-items: center;
}
.another { //<===== Question postion //
position: absolute;
text-align: center;
width: 100%;
top: 30px;
}
.slidee {
margin-top: -30px !important;
}
.q1{
text-align: center !important;
font-family: Comic Sans MS !important; font-size: 25px !important; text-align: center;
}
.p1{
position: absolute;
margin-left: 300px;
font-family: Comic Sans MS !important;
font-size: 23px !important;
}
ion-item{
background-color: transparent !important;
}
.quizcontainer{
height: 520px;
widhth: 100%;
}
h1{
color: white !important;
}
/* .orca{
width: 100px;
height: 100px;
background-color: aqua;
position: absolute;
margin-top: 60%;
margin-left: auto;
border-radius: 50%;
} */
}
this is iphonex in web
Use media queries with different device port Size so that it can be render across different screens

How to make text start at space place on x-axis (different divs)

This may seem like a simple question and may have a simple solution but I was wondering how I can get two text elements (from a button) start at the space spot on the x-axis (they are two different divs). I am referring to the button's text in the image below.
How can I get both the text "Dashboard" and "A new button" to start at the same position on the x axis?
* {
margin: 0;
padding: 0;
}
body {
background-color: #ced4da;
font-family: sans-serif;
}
.wrapper {
height: 100vh;
}
input[type="button"] {
border: none;
background-color: Transparent;
outline: none;
height: 20px;
width: 92%;
font-size: 13px;
font-weight: regular;
color: white;
}
.side-bar {
display: flex;
flex-direction: column;
width: 17%;
height: 100%;
background-color: #272C32;
}
.sub-title {
margin-top: 10%;
margin-left: 7.5%;
}
.sub-title h3 {
color: #B9B9B9;
font-size: 13px;
font-weight: lighter;
}
.splitter {
display: flex;
align-self: center;
width: 85%;
height: 0.5px;
background-color: grey;
margin-top: 12px;
margin-bottom: 4%;
}
.button {
position: relative;
margin-left: 7.5%;
margin-bottom: 3%;
}
.button form i {
color: white;
font-size: 14px;
transition: 0.3s;
position: absolute;
left: 0px;
top: 0px;
padding: 5px 0px;
}
.button input:hover+i {
color: dodgerblue;
}
<div class="wrapper">
<div class="side-bar">
<div class="sub-title">
<h3>ADMIN TOOLS<h3>
</div>
<div class="splitter"></div>
<div class="button">
<form>
<input type="button" value="Dashboard" onclick="window.location.href='http://www.google.com'"/>
<i class="fas fa-tachometer-alt fa-lg" aria-hidden="true"></i>
</form>
</div>
<div class="button">
<form>
<input type="button" value="A new button" onclick="window.location.href='http://www.google.com'"/>
<i class="fas fa-hand-paper fa-lg" aria-hidden="true"></i>
</form>
</div>
</div>
<div class="nav-bar"></div>
</div>
And if you have time, how does my CSS code look? I am still learning and would like some feedback too if you don't mind :) Thanks!
All you have to do is put a <div> element around your <form> element s, then set its position to wherever you want it, and its text-align: left;. BTW your CSS looks excellent, just keep in mind that some things can be simplified, e.g.
{margin: 0; padding: 0;}
This is very good, but * is the same as body, even though it's documented differently. * applies to all the content, but content is only displayed if it's in the <body> element.
Very good looking however, keep it up!
P.S. I'd vote you up if I could, but I'm out of votes - I'll do it tomorrow

Flex item being bumped down exactly half height of previous item

I'll include an image for context, then the code:
The box at far right with "ABC" in it and a left/bottom border is being bumped down exactly half the height of the gradient image next to it. I know a lot of the heights/etc don't make sense, but I've removed them all and the problem persists. Any guidance here?
The HTML:
<div className="thing">
<img src="https://unsplash.it/75/90/?blur" alt="hey there" className="thingImage" />
<div className="content">
<span className="thingName">Jibber Jabb Super Long Title of a Movie or Thing Here</span><br/>
<span className="thingRanks">
Rank1: 1<br/>
Rank2: 2<br/>
Rank3: 2
</span>
</div>
<div className="thingMeta">
<img src="https://unsplash.it/30/30/?blur" alt="name" className="thingIcon" />
<span className="thingAbbrev">ABC</span>
</div>
</div>
(the "className" is from React, just read it as "class" if you're not familiar with React)
The CSS:
.thing{
border: 1px solid #ccc;
width: 564px;
min-height: 68px;
padding: 10px;
font-family: "Helvetica", arial, sans-serif;
font-size: 14px;
line-height: 18px;
display: flex;
}
.thingImage{
border-radius: 5px;
margin-right: 10px;
}
.thingName{
font-weight: bold;
margin-right: 0.3em;
}
.thingMeta{
margin-left: auto;
align-self: flex-start;
height: 35px;
}
.thingAbbrev{
border-bottom: medium solid #000000;
border-left: medium solid #000;
align-self: flex-start;
padding-left: 5px;
padding-bottom: 5px;
margin-left: 10px;
width: 30px;
}
.thingIcon{
height: 30px;
}
The main focus of this project for me is learning React, using Flexbox is just a bonus for me here. Thanks in advance, any help or guidance is greatly appreciated!
Since the thingMeta is not a flex container (doesn't have display: flex;(1)), the thingAbbrev is not a flex item, hence the align-self: flex-start won't apply .
As the img and span in the thingMeta are normal inline elements, they align along the baseline, so i.e. adding vertical-align: top will align them at the top.
.thing{
border: 1px solid #ccc;
width: 564px;
min-height: 68px;
padding: 10px;
font-family: "Helvetica", arial, sans-serif;
font-size: 14px;
line-height: 18px;
display: flex;
}
.thingImage{
border-radius: 5px;
margin-right: 10px;
}
.thingName{
font-weight: bold;
margin-right: 0.3em;
}
.thingMeta{
margin-left: auto;
align-self: flex-start;
height: 35px;
}
.thingAbbrev{
border-bottom: medium solid #000000;
border-left: medium solid #000;
/* align-self: flex-start; removed */
vertical-align: top; /* added */
padding-left: 5px;
padding-bottom: 5px;
margin-left: 10px;
width: 30px;
}
.thingIcon{
height: 30px;
}
<div class="thing">
<img src="https://unsplash.it/75/90/?blur" alt="hey there" class="thingImage" />
<div class="content">
<span class="thingName">Jibber Jabb Super Long Title of a Movie or Thing Here</span><br/>
<span class="thingRanks">
Rank1: 1<br/>
Rank2: 2<br/>
Rank3: 2
</span>
</div>
<div class="thingMeta">
<img src="https://unsplash.it/30/30/?blur" alt="name" class="thingIcon" />
<span class="thingAbbrev">ABC</span>
</div>
</div>
Alternatively you can of course also simply add display: flex to the thingMeta. The downside with that is that your img then becomes a flex item and based on what you want to do with it, there is some cross browser issues, and many of them can be avoided by wrapping the img (which I didn't in below sample)
.thing{
border: 1px solid #ccc;
width: 564px;
min-height: 68px;
padding: 10px;
font-family: "Helvetica", arial, sans-serif;
font-size: 14px;
line-height: 18px;
display: flex;
}
.thingImage{
border-radius: 5px;
margin-right: 10px;
}
.thingName{
font-weight: bold;
margin-right: 0.3em;
}
.thingMeta{
margin-left: auto;
align-self: flex-start;
height: 35px;
display: flex; /* added */
}
.thingAbbrev{
border-bottom: medium solid #000000;
border-left: medium solid #000;
align-self: flex-start;
padding-left: 5px;
padding-bottom: 5px;
margin-left: 10px;
width: 30px;
}
.thingIcon{
height: 30px;
}
<div class="thing">
<img src="https://unsplash.it/75/90/?blur" alt="hey there" class="thingImage" />
<div class="content">
<span class="thingName">Jibber Jabb Super Long Title of a Movie or Thing Here</span><br/>
<span class="thingRanks">
Rank1: 1<br/>
Rank2: 2<br/>
Rank3: 2
</span>
</div>
<div class="thingMeta">
<img src="https://unsplash.it/30/30/?blur" alt="name" class="thingIcon" />
<span class="thingAbbrev">ABC</span>
</div>
</div>
(1) When display: flex is set on an element, it is only its children that becomes flex items
You need to set the below CSS and html
CSS:
.vcenter{
display: flex;
align-item: center;
justify-content: center;
}
Also I wrapped the <span class="thingAbbrev">ABC</span> in another span to get rid of an height issue due to margins.
HTML:
<div class="thingMeta vcenter">
<img src="https://unsplash.it/30/30/?blur" alt="name" class="thingIcon" />
<span class="vcenter"><span class="thingAbbrev">ABC</span></span>
</div>
JSFiddle: here

How can I keep a button horizontally centered with an input if they have different font sizes?

I have an input box for text and directly next to it is a button. The problem is when the button font-size and input box font-size is different, the button won't be correctly aligned.
Ex - different font-sizes. Notice the bottom of the button extends past the input box much more than the top
input{
font-size:20px;
}
.btn {
padding: 8px 12px;
font-size: 14px;
border-radius: 2px;
}
<input>
<button class="btn btn-primary m-l">Add</button>
Ex: Same font sizes: button is aligned:
input{
font-size:20px;
}
.btn {
padding: 8px 12px;
font-size: 20px;
border-radius: 2px;
}
<input>
<button class="btn btn-primary m-l">Add</button>
I'm not sure this is the best solution, but you can achieve this by giving the input a height, and vertically aligning both elements to the middle. See snippet below.
input{
font-size:20px;
height: 30px;
vertical-align: middle;
}
.btn {
padding: 8px 12px;
font-size: 14px;
border-radius: 2px;
vertical-align: middle;
}
<input>
<button class="btn btn-primary m-l">Add</button>
Use CSS Flexbox. And apply align-items: center to make your child <div>s vertically centered. In my case I've used body as my parent element
Have a look at the snippet below:
input{
font-size:20px;
}
.btn {
padding: 8px 12px;
font-size: 14px;
border-radius: 2px;
margin-left: 5px;
}
body {
display: flex;
align-items: center;
}
<input>
<button class="btn btn-primary m-l">Add</button>
Hope this helps!
Simply wrap your content into a .container div and apply dispaly: flex to it and that should do the trick for you.
.container {
display: flex;
}
input{
font-size:20px;
margin-right: 5px;
}
.btn {
padding: 8px 12px;
font-size: 14px;
border-radius: 2px;
}
<div class="container">
<input>
<button class="btn btn-primary m-l">Add</button>
</div>
Hope helps (y).

Resources