Home > Net >  Allign elements to left within the flex container
Allign elements to left within the flex container

Time:03-03

Basically, I have this flex container named question__container, inside of which are my flex-items. I want to align the question, the input and the button to the left within that container. Tried

  • wrapping the elements inside another container and set align-items to left
  • tried flex-start within that container, overflows.

Please guide.

:root {

  /* Colors*/
    --primary: #FF7300;
    --primary-light: #FFE3CC;
    --secondary: #334762;
    --white: #ffffff;

  /* Fonts */
    --font-one: 'Poppins', sans-serif;
    --font-two: 'Exo', sans-serif;
    --font-three: 'Baloo Da 2', cursive;
    --font-four: 'Fira Sans', sans-serif;
    --font-five: 'Lato', sans-serif;
}

body {
  background-color: var(--primary-light);
  font-family: var(--font-four);
  color: var(--secondary);
  font-size: 16px;
}

.question__container {
    height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    gap: 1.25rem;
}

.question {  
  font-family: var(--font-four);
  text-align: left;
}

.question__container input.text-answer {
  font-size: 1.125rem;
  color: var(--primary);
  font-weight:700;
  margin: 0 auto;
  height: 40px;
  border: none;
  border-bottom: 3px solid var(--secondary);
  background-color: var(--bg-color);    
}
a.start-button {
    margin-top: 30px;
     font-family: var(--font-three);
     min-width: 120px;
     padding: 15px 28px;
     background-color: var(--primary);
     color: var(--white);
     font-size: 18px;
     font-weight: 900;
     line-height: 18px;
     text-decoration: none;
 }
<section id="name">
            <div >
                <div >
                    <img src="logo.svg" alt="">
                </div>
                    <div >What is your Name?</div>
                    <input type="text"  placeholder="Type here" tabindex="1" required>
                    <a href="#email" >Submit</a>
     
        </section>

CodePudding user response:

You could wrap the elements and give that wrapper display: flex;, justify-content: flex-start; and flex-direction: column;

CodePudding user response:

You will need to add align-items: flex-start; instead of center on your .question__container to do that and remove margin: 0 auto on .question__container input.text-answer.

Edit:

You can add this to those elements


width: fit-content;
margin-right: auto !important;

  • Related