Just trying to evenly space my text and search bar and also center them horizontally in my navbar. I've manage to center the text and space them out but having trouble centering the search bar horizontally.
Any help would be great!
<nav class="TopNav">
<h1>Locals RUs Pet Store</h1>
<form action="" class="SearchBar">
<input type="text" placeholder="Search here..." name="q" />
<button type="submit">
<img src="/Icons/MagnifierSearchIcon.png" />
</button>
</form>
</nav>
.TopNav{
padding-top: 10px;
padding-bottom: 10px;
display: flex;
justify-content: space-around;
}
.TopNav h1{
padding-left: 200px;
font-family: macho,sans-serif;
font-weight: 900;
font-style: normal;
font-size: 4rem;
}
.SearchBar{
margin: 0 auto;
width: 100%;
max-width: 500px;
height: 40px;
display: flex;
align-items: center;
border-radius: 60px;
padding: 10px 20px;
background: white;
}
.SearchBar input{
background: transparent;
flex: 1;
border: 0;
outline: none;
padding: 24px 20px;
font-size: 20px;
color: black,
}
.TopNav {
padding-top: 10px;
padding-bottom: 10px;
display: flex;
justify-content: space-between;
flex: 1 1 10px;
max-width: 80%;
margin: 0 auto;
align-items: center;
}
.TopNav h1{
padding-left: 0px;
font-family: macho,sans-serif;
font-weight: 900;
font-style: normal;
max-width: 40%;
font-size: 2rem;
}
.SearchBar{
margin: 0 auto;
width: 100%;
max-width: 60%;
height: 40px;
display: flex;
align-items: center;
border-radius: 60px;
padding: 10px 20px;
background: white;
max-width: 250px;
}
.SearchBar input{
background: transparent;
flex: 1;
border: 0;
outline: none;
padding: 24px 20px;
font-size: 20px;
color: black,
}
<nav class="TopNav">
<h1>Locals RUs Pet Store</h1>
<form action="" class="SearchBar">
<input type="text" placeholder="Search here..." name="q" />
<button type="submit">
<img src="/Icons/MagnifierSearchIcon.png" />
</button>
</form>
</nav>
Related
So I'm still new to web developing and currently working on a restaurant site but when I view the page on smaller screens it's not displaying properly (not show full width) and the navbar is completely gone. How can I get this to properly show on smaller screens and the navbar to either become a togglebar or display under the logo? I think my current CSS setting might be to blame. Thanks
I have tried optimising with CSS and see if it can show the full page on smaller screens and have been able to achieve that for iPad Air and bigger screens but still no luck on smaller ones.
Happy to share my code if needed
HTML
<body>
<p class="catering">*Catering services available for hire</p>
<header>
<img class="shop-logo w-55" src="/FBS LOGO.png">
<nav class="navbar navbar-default">
<div class="hover-underline-animation"> Menu </div>
<div class="hover-underline-animation">Order</div>
<div class="hover-underline-animation">Location </div>
<div class="hover-underline-animation">Contact</div>
</nav>
</header>
<section class="about" id="about">
<div class="row">
<div class="image">
<img src="FBS_ISLAND GIRL_.png" alt="">
</div>
<div class="content">
<h3>
<span class="line-1"> "Authentic </span> <span class="line-2"> <br> Caribbean </span> <span class="line-3"><br> Cuisine" </span>
<span class="line-4"><br> jus lik momma use tah mek it </span>
</h3>
</div>
</div>
<p class="share"> Like, Follow `n Share <br> <i class="fa-brands fa-instagram"> </i> FOOD_BY_SOPHIE </i> </p>
</section>
<section class="order" id="order">
<h3 class="sub-heading">
Order Now
</h3>
<h1 class="heading">
Collection Only
</h1>
<form action="https://formsubmit.co/a5f5a32519da94e6ed9ceef9fd5cf8af" class="form-alert" method="POST">
<!- Honeypot -->
<input type="text" name="_honey" style="display: none;">
<!- Disaple Captcha -->
<input type="hidden" name="_captcha" value="false">
<input type="hidden" name="_next" value="https://sprightly-meerkat-b47b9e.netlify.app/">
<div class="inputBox">
<div class="input">
<span>
Your name
</span>
<input type="text" name="name" placeholder="Enter your name">
</div>
<div class="input">
<span>
Your number
</span>
<input type="number" name="number" placeholder="Enter your number">
</div>
</div>
<div class="inputBox">
<div class="input">
<span>
Your order
</span>
<input type="text" name="order" placeholder="Enter your order">
</div>
<div class="input">
<span>
Additional orders
</span>
<input type="text" name="extras" placeholder="Extras">
</div>
</div>
<div class="inputBox">
<div class="input">
<span>
How much
</span>
<input type="number" name="amount" placeholder="How many orders">
</div>
<div class="input">
<span>
Collection date & time
</span>
<input type="datetime-local" name="time">
</div>
</div>
<div class="inputBox">
<div class="input">
<span>
Your message
</span>
<textarea name="message" placeholder="Enter your message" id="" cols="30" rows="10"></textarea>
</div>
</div>
<input type="submit" value="Order now" class="btn btn-dark">
</form>
</section>
CSS
#import url('https://fonts.googleapis.com/css2?family=Libre+Bodoni:ital#1&family=Nunito:wght#200;300;400;600;700&display=swap');
:root{
--green:#27ae60;
--black:#192a56;
--light-color:#666;
--box-shadow:0 .5rem 1.5rem rgba(0,0,0,.1);
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
text-decoration: none;
outline: none;
border: none;
text-transform: capitalize;
transition: all .2s linear;
}
html {
font-size: 62%;
scroll-padding-top: 5.5rem;
scroll-behavior: smooth;
}
.loader-container {
position:fixed;
top: 0; left: 0;
height: 100%;
width: 100%;
z-index: 10000;
background: #fff;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.loader-container img{
width: 35rem;
}
.loader-container.fade-out{
top: 110%;
opacity: 0;
}
header {
top: 0;
left: 0;
right: 0;
bottom: 0;
background: #a8b98a;
display: flex;
align-items: center;
justify-content: center;
}
.hover-underline-animation {
display: inline-block;
position: relative;
color: white;
}
.hover-underline-animation::after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 0;
left: 0;
background-color: white;
transform-origin: bottom right;
transition: transform 0.25s ease-out;
}
.hover-underline-animation:hover::after {
transform: scaleX(1);
transform-origin: bottom left;
}
header .navbar a{
font-size: 40px;
border-radius: .5rem;
padding: .5rem 1.5rem;
color: white;
text-decoration: none;
font-family: 'Hi Melody', cursive;
}
.navbar a:hover {
font-size:88px;
font-size-adjust: 20px;
}
img.shop-logo {
width: 650px;
border-radius: 50%;
margin-bottom: -0px;
border: 10px;
margin-top: 0;
}
body {
background: #a8b98a;
}
.about .row{
display: flex;
flex-wrap: wrap;
gap: 1.5rem;
align-items: center;
}
.about {
background: #fbe7d7;
padding-right: 10px;
padding: 20rem 9% 40rem 0rem;
}
.about .row .image {
flex: 1 1 45rem;
position: absolute;
display: block;
}
.about .row .image img{
max-width: 1250px;
max-height: inherit;
height: inherit;
width: inherit;
padding-top: 100px;
}
.about .row .content {
flex: 1 1 45rem;
}
.about h3{
text-align: end;
}
.about .row .content p{
color: #aa401b;
font-size: 45px;
text-align: center;
font-family: 'Hi Melody', cursive;
font-weight: bolder;
}
.line-1 {
margin-right: 80px;
padding-left: 0px;
font-family: 'Hi Melody', cursive;
font-weight:bolder;
color: #d45a28;
font-size: 100px;
line-height: 0;
}
.line-2 {
margin-left: 5px;
padding-left: 150px;
font-family: 'Hi Melody', cursive;
font-weight:bolder;
color: #d45a28;font-family: 'Hi Melody', cursive;
font-size: 100px;
line-height: 1;
}
.line-3 {
margin-left: 5px;
padding-left: 100px;
font-family: 'Hi Melody', cursive;
font-weight:bolder;
color: #d45a28;
font-size: 100px;
line-height: 1;
}
.line-4{
margin-left: 5px;
padding-left: 100px;
font-family: 'Hi Melody', cursive;
font-weight:bolder;
color: #d45a28;
font-size: 40px;
line-height: 1;
}
.share {
color: #d45a28;
font-weight: bolder;
font-size: 20px;
float:right;
padding-top: 80px;
text-decoration: none;
font-family: 'Hi Melody', cursive;
padding-top: 250px;
}
.share a {
color: #d45a28;
text-decoration: none;
font-weight: bolder;
}
.sub-heading {
color: black;
text-align: center;
margin-top: 30px;
padding-top: 20px;
}
.heading {
color: black;
text-align: center;
}
.order form {
max-width: 90rem;
border-radius: .5rem;
box-shadow: var(--box-shadow);
border: .1rem solid rgba(0,0,0,.2);
background: #fff;
padding: 1.5rem;
margin: 0 auto;
}
.order form .inputBox {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.order form .inputBox .input {
width: 49%;
}
.order form .inputBox .input span{
display: block;
padding: .5rem 0;
font-size: 1.5rem;
color: var(--light-color);
}
.order form .inputBox .input input,
.order form .inputBox .input textarea{
background: #eee;
border-radius: .5rem;
padding: 1rem;
font-size: 1.6rem;
color: var(--black);
text-transform: none;
margin-bottom: 1rem;
width: 100%;
}
.order form .inputBox .input input:focus,
.order form .inputBox .input textarea:focus{
border: 1rem solid var(--green);
}
.order form .inputBox .input textarea{
height: 20rem;
resize: none;
}
.order form .btn {
margin-top: 0;
}
.order {
padding-bottom: 20px;
}
.footer .box-container{
display: grid;
grid-template-columns: repeat(auto-fit, minmax(25rem, 1fr));
gap: 1.5rem;
text-align: center;
}
.footer .box-container .box{
padding: 5rem 0;
font-size: 2.5rem;
color: var(--black);
}
.footer .box-container a{
display: block;
padding: 5rem 0;
font-size: 1.5rem;
color: var(--light-color);
text-decoration: none;
}
.footer .box-container a:hover{
color: black;
text-decoration: none;
}
.footer .credit {
text-align: center;
border-top: .1rem solid rgba(0,0,0,.1);
font-size: 2rem;
color: var(--black);
padding: .5rem;
padding-top: 1.5rem;
margin-top: 1.5rem;
}
.footer .credit span {
color: black;
}
.footer {
background: #fbe7d7;
}
\\\\ Order CSS \\\\\
.order .sub-heading {
color: white;
}
.order .heading {
color: white;
}
.catering {
color: #d45a28;
text-align: right;
font-size: 20px;
padding-top: 40px;
padding-right: 10px;
font-weight: bold;
font-family: 'Times New Roman';
}
#media (max-width:991px){
html {
font-size: 55%;
}
header{
padding: 1rem 2rem;
}
section{
padding: 2rem;
}
}
#media (max-width:850px){
.about {
display: block;
text-align: center;
padding-bottom: 900px;
}
.content {
text-align: end;
}
.catering {
text-align: center;
}
p .share {
text-align: center;
}
.about .row .image img {
display: block;
position:absolute;
padding-top: 150px;
justify-content: center;
height: auto;
margin-right: 10px;
}
.share{
padding-left: 5000px;
}
}
#media (max-width:800px){
header .icon #menu-bars{
display: inline-block;
}
header .navbar {
position: absolute;
top: 100%; left: 0; right: 0;
background: #a8b98a;
border-top: .1rem solid rgba(0,0,0,.2);
border-bottom: .1rem solid rgba(0,0,0,.2);
padding: 1rem;
clip-path: polygon(0 0, 100% 0, 100% 0, 0 0);
}
header .navbar.active{
clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%);
}
header .navbar a{
display: block;
padding: 1.5rem;
margin: 1rem;
font-size: 2rem;
background: #eee;
}
.image {
display: block;
text-align: center;
}
.about .row .image img{
height: auto;
width: 40%;
margin-left: 200px;
}
.home .home-slider .slide .content h3{
font-size: 5rem;
}
.about h3{
text-align:center;
font-size: 2rem;
}
}
#media (max-width:400px){
html {
font-size: 50%;
}
.dishes .box-container .box img {
height: auto;
width: 100%;
}
.order form .inputBox .input {
width: 100%;
}
.about {
display: block;
text-align: center;
}
.content {
text-align: end;
}
.catering {
text-align: center;
}
p .share {
text-align: center;
}
.about .row .image img {
display: block;
position:absolute;
padding: 200px 0 200px 0;
justify-content: center;
height: auto;
margin-right: 1000px;
}
}
Please check this https://www.w3schools.com/css/css3_mediaqueries.asp for learning CSS responsiveness and media queries.
Also check this one please: https://www.w3schools.com/css/css_rwd_mediaqueries.asp
I am trying to move this form but it keeps 'hitting' the h3 tag and the button. I want to move them around without them interfering with one another.
I am talking about the gray panel:
Even when resizing the window, they interact and push one another.
I have tried using margin and padding, but that doesn't seem to work.
.section-3 {
position: relative;
background-color: white;
height: 600px;
top: 959px;
text-align: center;
}
.join-btn {
height: 45px;
font-size: 16px;
text-transform: uppercase;
text-align: center;
border-radius: 2px;
padding: 9px 20px 7px;
color: #373f3d;
border: 2px solid rgba(55, 63, 61, 0.2);
}
.section-3 .heading_section_3 {
font-size: 20px;
position: absolute;
bottom: 70%;
}
.description {
position: absolute;
color: #6e6e6e;
padding-left: 200px;
padding-right: 200px;
}
.join-right-side {
overflow: auto;
background-color: #c9c8c8;
position: absolute;
height: 300px;
padding: 30px;
margin-left: 50%;
display: flex;
align-items: center;
justify-content: center;
width: 50%;
}
.Join-left-side {
overflow: auto;
position: absolute;
height: 300px;
padding: 30px;
background-color: #f5f5f1;
display: flex;
align-items: center;
justify-content: center;
width: 50%;
}
.text-join-left {
color: black;
text-align: center;
padding-left: 200px;
padding-right: 200px;
}
.form {
height: fit-content;
overflow: hidden;
}
input[type="email"] {
border-color: black;
border-width: 2px;
background-color: #c9c8c8;
box-sizing: border-box;
list-style: none;
direction: ltr;
box-sizing: border-box;
padding: 0;
margin: 200px 200px 0px 0px;
display: block;
width: 100%;
appearance: none;
background: none;
border: none;
color: #373f3d;
font-family: GT Pressura Mono, Roboto Mono, monospace;
font-size: 28px;
line-height: 28px;
font-weight: 400;
}
<div class="section-3">
<div class="join-right-side">
<div class="join-btn">Join</div>
<h3 class="text-join-left">Sign up and get 10% off your first purchase.</h3>
<form class="form" action="/">
<input
class="input"
placeholder="Your email address..."
type="email"
name="EMAIL"
/>
</form>
</div>
<div class="join-left-side">
<h2 class="heading_section_3">Swallowtail Tea</h2>
<h3 class="description">
Swallowtail Tea is a Virginia-based tea company sourcing only the highest
quality tea, herbs, and spices from around the world.
</h3>
</div>
</div>
I think it could be linked to the way I'm accessing the div classes, or to the structure of the div's.
You can try:
CSS
.section-3 {
display:flex;
justify-content: space-between;
}
.join-left-side , .join-right-side {
width : 50%;
height: 300px;
}
.section-3 {
position: relative;
background-color: white;
height: 600px;
top: 959px;
text-align: center;
}
.join-btn {
height: 45px;
font-size: 16px;
text-transform: uppercase;
text-align: center;
border-radius: 2px;
padding: 9px 20px 7px;
color: #373f3d;
border: 2px solid rgba(55, 63, 61, .2);
}
.section-3 .heading_section_3 {
font-size: 20px;
}
.description {
color: #6e6e6e;
}
.join-right-side {
background-color: #c9c8c8;
height: 300px;
padding: 30px;
display: flex;
align-items: center;
justify-content: center;
width: 50%;
}
.join-left-side {
align-items: center;
display: flex;
flex-direction: column;
justify-content: center;
}
.form{
height: fit-content;
overflow: hidden;
}
input[type=email] {
border-color: black;
border-width: 2px;
background-color: #c9c8c8;
box-sizing: border-box;
list-style: none;
direction: ltr;
box-sizing: border-box;
padding: 0;
margin: 200px 200px 0px 0px;
display: block;
width: 100%;
appearance: none;
background: none;
border: none;
color: #373f3d;
font-family: GT Pressura Mono,Roboto Mono,monospace;
font-size: 28px;
line-height: 28px;
font-weight: 400;
}
HTML
<div class="section-3">
<div class="join-left-side">
<h2 class="heading_section_3">Swallowtail Tea</h2>
<h3 class="description">
Swallowtail Tea is a Virginia-based tea company sourcing only the highest
quality tea, herbs, and spices from around the world.
</h3>
</div>
<div class="join-right-side">
<div class="join-btn">Join</div>
<h3 class="text-join-left">Sign up and get 10% off your first purchase.</h3>
<form class="form" action="/">
<input
class="input"
placeholder="Your email address..."
type="email"
name="EMAIL"
/>
</form>
</div>
</div>
This is my html file
body {
background-color: rgb(231, 59, 59);
font-family: "Alata";
font-size: 20px;
margin: 30px;
}
h1 {
margin-top: 100px;
color: #202124;
text-align: center;
}
.box {
width: 1000px;
}
input {
position: relative;
display: inline-block;
box-sizing: border-box;
}
input[type="text"] {
background: #fff;
width: 600px;
height: 50px;
padding: 0 10px;
border: none;
outline: none;
border-radius: 25px 0 0 25px;
font-size: 15px;
}
button {
left: -5px;
position: relative;
border-radius: 0 25px 25px 0;
width: 110px;
height: 50px;
border: none;
outline: none;
cursor: pointer;
background: #ffc170;
color: #fff;
font-size: 21px;
}
<h1>This is my page title...</h1>
<div class="box">
<form>
<input type="text" name="" placeholder="Search here" />
<button type="button">Search</button>
</form>
</div>
My question is how can I align the box div align center(horizontally) responsively(dynamically) and how to make this webpage responsive when I checked this page's responsiveness it's not showing responsiveness.
Try this code:
body {
background-color: rgb(231, 59, 59);
font-family: "Alata";
font-size: 20px;
margin: 30px;
}
h1 {
margin-top: 100px;
color: #202124;
text-align: center;
}
.box {
max-width: 1000px;
width:100%;
margin:0 auto;
}
input {
position: relative;
display: inline-block;
box-sizing: border-box;
}
input[type="text"] {
background: #fff;
width: 600px;
height: 50px;
padding: 0 10px;
border: none;
outline: none;
border-radius: 25px 0 0 25px;
font-size: 15px;
}
button {
left: -5px;
position: relative;
border-radius: 0 25px 25px 0;
width: 110px;
height: 50px;
border: none;
outline: none;
cursor: pointer;
background: #ffc170;
color: #fff;
font-size: 21px;
}
<h1>This is my page title...</h1>
<div class="box">
<form>
<input type="text" name="" placeholder="Search here" />
<button type="button">Search</button>
</form>
</div>
What I have done is that I have changed the
.box {
width: 1000px;
}
to
.box {
max-width: 1000px;
width:100%;
margin:0 auto;
}
You can also use display: flexbox; and justify-content: center; in the div box to get almost the same result
Here is the code that I think will work if you want to use flexbox:
body {
background-color: rgb(231, 59, 59);
font-family: "Alata";
font-size: 20px;
margin: 30px;
}
h1 {
margin-top: 100px;
color: #202124;
text-align: center;
}
.box {
display: flexbox;
justify-content: center;
}
input {
position: relative;
display: inline-block;
box-sizing: border-box;
}
input[type="text"] {
background: #fff;
width: 600px;
height: 50px;
padding: 0 10px;
border: none;
outline: none;
border-radius: 25px 0 0 25px;
font-size: 15px;
}
<h1>This is my page title...</h1>
<div class="box">
<form>
<input type="text" name="" placeholder="Search here" />
<button type="button">Search</button>
</form>
</div>
NOTE I have used max-widht: 1000px; in my first method, you can change that as per need.
Change this
.box{
max-width: 1000px;
width:100%;
margin:0 auto;
}
use this but the condition is your parent div has 100% width(window width).
or another way to use flex
form{
width: 200px;
margin: auto;
}
<body>
<h1>This is my page title...</h1>
<div class="box">
<form>
<input type="text" name="" placeholder="Search here">
<button type="button">Search</button>
</form>
</div>
</body>
You can follow the below code. I try to give some explanation where I changed and why I did it
body {
background-color: rgb(231, 59, 59);
font-family: "Alata";
font-size: 20px;
margin: 0px;
}
h1 {
margin-top: 100px;
color: #202124;
text-align: center;
}
.box {
/*if you want to take result as a responsive then you need to add width as % not fixt size */
width: 100%;
text-align: center;
margin: 0 auto;
}
/*This div for form responsive */
.search-form{
width: 90%;
text-align: center;
margin: 0 auto;
}
input {
position: relative;
display: inline-block;
box-sizing: border-box;
}
input[type="text"] {
background: #fff;
width: 70%; /* I change here for px to % base one your requerment */
height: 50px;
padding: 0 10px;
border: none;
outline: none;
border-radius: 25px 0 0 25px;
font-size: 15px;
float: left; /* I change here for div assign as a left */
}
button {
position: relative;
border-radius: 0 25px 25px 0;
width: 30%; /* I change here for px to % base one your requerment */
height: 50px;
border: none;
outline: none;
cursor: pointer;
background: #ffc170;
color: #fff;
font-size: 21px;
float: left; /* I change here for div assign as a left */
}
<h1>This is my page title...</h1>
<div class="box">
<div class="search-form">
<form>
<input type="text" name="" placeholder="Search here" />
<button type="button">Search</button>
</form>
</div>
</div>
display: block fix needs these two blocks to be inserted in the css
.box {
max-width: 1000px;
margin: 0 auto;
}
form {
width: max-content;
margin: 0 auto;
}
Working Fiddle
body {
background-color: rgb(231, 59, 59);
font-family: "Alata";
font-size: 20px;
margin: 30px;
}
h1 {
margin-top: 100px;
color: #202124;
text-align: center;
}
.box {
max-width: 1000px;
margin: 0 auto;
}
form {
width: max-content;
margin: 0 auto;
}
input {
position: relative;
display: inline-block;
box-sizing: border-box;
}
input[type="text"] {
background: #fff;
width: 600px;
height: 50px;
padding: 0 10px;
border: none;
outline: none;
border-radius: 25px 0 0 25px;
font-size: 15px;
}
button {
left: -5px;
position: relative;
border-radius: 0 25px 25px 0;
width: 110px;
height: 50px;
border: none;
outline: none;
cursor: pointer;
background: #ffc170;
color: #fff;
font-size: 21px;
}
<h1>This is my page title...</h1>
<div class="box">
<form>
<input type="text" name="" placeholder="Search here" />
<button type="button">Search</button>
</form>
</div>
If you are good to go with flexbox implementation, you could wrap your .box in flex and have a justify-content: center; to have an horizontal alignment.
Add the below update in your css for flexbox
.box {
display: flex;
justify-content: center;
}
Working flexbox fiddle
body {
background-color: rgb(231, 59, 59);
font-family: "Alata";
font-size: 20px;
margin: 30px;
}
h1 {
margin-top: 100px;
color: #202124;
text-align: center;
}
.box {
max-width: 1000px;
display: flex;
justify-content: center;
}
input {
position: relative;
display: inline-block;
box-sizing: border-box;
}
input[type="text"] {
background: #fff;
width: 600px;
height: 50px;
padding: 0 10px;
border: none;
outline: none;
border-radius: 25px 0 0 25px;
font-size: 15px;
}
button {
left: -5px;
position: relative;
border-radius: 0 25px 25px 0;
width: 110px;
height: 50px;
border: none;
outline: none;
cursor: pointer;
background: #ffc170;
color: #fff;
font-size: 21px;
}
<h1>This is my page title...</h1>
<div class="box">
<form>
<input type="text" name="" placeholder="Search here" />
<button type="button">Search</button>
</form>
</div>
Please note I have made use of max-width: 1000px; for .box in both examples. This is to make sure that the ui wont fail in the SO fiddle. You can update that as your requirement.
I'm brand new to HTML and CSS. I'm trying to center two form buttons. Here is my code:
* {
font-family: arial, sans-serif;
}
body {
display: flex;
align-items: column;
}
.buttons {
background-color: #f8f9fa;
border: 1px solid #f8f9fa;
border-radius: 4px;
font-size: 14px;
margin: 11px 4px;
padding: 0 16px;
line-height: 27px;
height: 36px;
min-width: 54px;
text-align: center;
cursor: pointer;
user-select: none;
display: inline-block;
}
.search_area {
display: flex;
color: rgba(0, 0, 0, .87);
border: 1px solid #ddd;
width: 100%;
height: 34px;
font-size: 16px;
border-radius: 25px;
}
nav {
display: flex;
margin-right: 30px;
margin-top: 15px;
}
.search_box {
text-align: center;
display: block;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Google</title>
<link rel="stylesheet" href="google.css">
</head>
<body>
<nav>
Image Search
Advanced Search
</nav>
<form class="search" action="https://www.google.com/search">
<img id="logo" src="logo.png" alt="Google logo">
<div>
<input name="q" type="text" class="search_area">
</div>
<input type="submit" value="Search Google" class="buttons">
<input type="submit" value="I'm Feeling Lucky" class="buttons">
</form>
</body>
</html>
As you can see, the two buttons beneath the search bar are justified to the left. I thought that text-align: center is the solution. But, this doesn't seem to work.
How do I get these two buttons to center on the screen?
Thanks in advance!
A sample update:
<html lang="en"><head>
<title>Google</title>
<link rel="stylesheet" href="google.css">
</head>
<body>
<nav>
Image Search
Advanced Search
</nav>
<form class="search" action="https://www.google.com/search">
<div style="
"><img id="logo" src="logo.png" alt="Google logo" style=""></div>
<div style="">
<div style="display: flex;align-content: center;">
<input name="q" type="text" class="search_area">
</div>
<div style="">
<input type="submit" value="Search Google" class="buttons">
<input type="submit" value="I'm Feeling Lucky" class="buttons">
</div>
</div>
</form>
</body></html>
CSS:
*{
font-family: arial, sans-serif;
}
body {
/*display: flex;
align-items: column;*/
}
.buttons {
background-color: #f8f9fa;
border: 1px solid #f8f9fa;
border-radius: 4px;
font-size: 14px;
margin: 11px 4px;
padding: 0 16px;
line-height: 27px;
height: 36px;
min-width: 54px;
text-align: center;
cursor: pointer;
user-select: none;
display: inline-block;
}
.search_area {
display: flex;
color: rgba(0, 0, 0, .87);
border: 1px solid #ddd;
width: 100%;
height: 34px;
font-size: 16px;
border-radius: 25px;
}
nav {
display: flex;
margin-right: 30px;
margin-top: 15px;
}
form{
display: table;
margin-left: auto;
margin-right: auto;
}
.search_box {
text-align: center;
display: block;
}
Use this CSS code:
Just paste it and see the changes.
I have commented the body section and it worked.
*{
font-family: arial, sans-serif;
}
body {
/*display: flex;
align-items: column;*/ /*I have commented the body CSS lines*/
}
.buttons {
background-color: #f8f9fa;
border: 1px solid #f8f9fa;
border-radius: 4px;
font-size: 14px;
margin: 11px 4px;
padding: 0 16px;
line-height: 27px;
height: 36px;
min-width: 54px;
text-align: center;
cursor: pointer;
user-select: none;
display: inline-block;
}
.search_area {
display: flex;
color: rgba(0, 0, 0, .87);
border: 1px solid #ddd;
width: 100%;
height: 34px;
font-size: 16px;
border-radius: 25px;
}
nav {
display: flex;
margin-right: 30px;
margin-top: 15px;
}
form{
display: table;
margin-left: auto;
margin-right: auto;
}
.search_box {
text-align: center;
display: block;
}
In your body tags don't use display: flex because when you used display flex then text-align: center wouldn't work. In your form tag you have a .search class. for centerizing i used .search { margin: 0 auto; width: 50%}
This is HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Google</title>
<link rel="stylesheet" href="google.css">
</head>
<body>
<nav>
Image Search
Advanced Search
</nav>
<form class="search" action="https://www.google.com/search">
<img id="logo" src="logo.png" alt="Google logo">
<div>
<input name="q" type="text" class="search_area">
</div>
<div class="button">
<input type="submit" value="Search Google" class="buttons">
<input type="submit" value="I'm Feeling Lucky" class="buttons">
</div>
</form>
</body>
</html>
And here is Css:
*{
font-family: arial, sans-serif;
}
/* body{display: flex;align-items: column;} */
.buttons {
background-color: #f8f9fa;
border: 1px solid #f8f9fa;
border-radius: 4px;
font-size: 14px;
margin: 11px 4px;
padding: 0 16px;
line-height: 27px;
height: 36px;
min-width: 54px;
text-align: center;
cursor: pointer;
user-select: none;
display: inline-block;
}
.button{
text-align: center;
}
.search_area {
color: rgba(0, 0, 0, .87);
border: 1px solid #ddd;
width: 100%;
height: 34px;
font-size: 16px;
border-radius: 25px;
}
.search{
margin: 0 auto;
width: 50%;
}
nav {
display: flex;
margin-right: 30px;
margin-top: 15px;
}
.search_box {
text-align: center;
display: block;
}
I'm working for the first time with flexbox but I've got an internet explorer problem.
In chrome it looks good. But in internet explorer everything is aligned to the right. How could I fix this?
I already tried to add a default height and min-height described here but not working :(
Any ideas?
.column {
max-width: 1000px;
margin: auto;
}
.row {
display: flex;
}
.panel {
padding: 10px;
width: 100%;
background: #fff;
margin-bottom: 50px;
border: 1px solid #eaeaea;
}
.center {
display: -webkit-box;
display: flex;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: center;
justify-content: center;
}
.column-small {
max-width: 350px;
margin: auto;
}
.brand {
display: -webkit-box;
display: flex;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: center;
justify-content: center;
background: #f5f5f1;
color: #002e5b;
width: 100%;
height: 50px;
}
.form-group-item {
width: 100%;
border-radius: 4px;
border: 1px solid #f2f2f2;
font-size: 15px;
box-shadow: none;
outline: none;
line-height: 1.5em;
margin-top: 10px;
margin-bottom: 10px;
height: 45px;
text-indent: 5px;
}
.btn-main {
border: none;
border-radius: 5px;
font-weight: 500;
font-size: 16px;
background: #002e5b;
color: #fff;
padding: 10px 45px;
}
.full-width {
width: 100%;
}
<div class="column">
<div class="row">
<div class="panel center">
<div class="column-small">
<div class="brand">
Login
</div>
<form>
<input name="email" class="form-group-item" autofocus="autofocus" required="required" type="email" placeholder="Email">
<input name="password" class="form-group-item" required="required" type="password" placeholder="Wachtwoord">
<button class="btn-main full-width" type="submit">Login</button>
</form>
</div>
</div>
</div>
</div>
I fixed it by removing margin: auto on .column-small.