This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
How can I vertically center a div element for all browsers using CSS?
(48 answers)
Closed 2 years ago.
I have a position:fixed container (div#popup)
#popup {
height: 60vh;
width: 60vw;
/* visibility: hidden; */
position: fixed;
left: 20vw;
top: 20vh;
border-radius: 8%;
background-color: rgb(241, 237, 231);
}
#popup form {
position: static;
margin: auto;
}
<div id='popup'>
<form action='emailform.php' method="POST">
<input type="text" name='name' placeholder="Name: "/>
<input type="text" name='mail' placeholder="Your Email: "/>
<input type="text" name='subject' placeholder="Subject: "/>
<textarea name='message' placeholder="Message: "></textarea>
<button type='submit' name="submit">Submit</button>
</form>
</div>
that contains a form that isnt fixed. Right now the form is just sticking to the top of the container. How do I center it? I've tried margin: auto and it doesn't work.
I'm guessing this should be a simple fix, but can't think of it.
Thanks!
You can make the container display :flex, flex-direction:column and use justify-content: center;
#popup {
height: 60vh;
width: 60vw;
/* visibility: hidden; */
position: fixed;
left: 20vw;
top: 20vh;
border-radius: 8%;
background-color: rgb(241, 237, 231);
display :flex;
flex-direction:column;
justify-content: center;
}
#popup form {
position: static;
margin: auto;
}
<div id='popup'>
<form action='emailform.php' method="POST">
<input type="text" name='name' placeholder="Name: "/>
<input type="text" name='mail' placeholder="Your Email: "/>
<input type="text" name='subject' placeholder="Subject: "/>
<textarea name='message' placeholder="Message: "></textarea>
<button type='submit' name="submit">Submit</button>
</form>
</div>
If you want horizontally center too you can do the same to the form but use row direction on the container:
#popup {
height: 60vh;
width: 60vw;
/* visibility: hidden; */
position: fixed;
left: 20vw;
top: 20vh;
border-radius: 8%;
background-color: rgb(241, 237, 231);
display :flex;
flex-direction:row;
justify-content: center;
}
#popup form {
position: static;
margin: auto;
display :flex;
flex-direction:column;
justify-content: center;
}
<div id='popup'>
<form action='emailform.php' method="POST">
<input type="text" name='name' placeholder="Name: "/>
<input type="text" name='mail' placeholder="Your Email: "/>
<input type="text" name='subject' placeholder="Subject: "/>
<textarea name='message' placeholder="Message: "></textarea>
<button type='submit' name="submit">Submit</button>
</form>
<form action='emailform.php' method="POST">
<input type="text" name='name' placeholder="Name: "/>
<input type="text" name='mail' placeholder="Your Email: "/>
<input type="text" name='subject' placeholder="Subject: "/>
<textarea name='message' placeholder="Message: "></textarea>
<button type='submit' name="submit">Submit</button>
</form>
</div>
Related
I just wonder is here is any easy way to make search button like this:There is a search form I want to make
For now I have smth like this:This is what I have for now
And there is HTML and CSS:
.path1{
max-width: 18px;
max-height: 18px;
}
.search-button{
border-bottom: #0A093D;
width: 30%;
height: 100%;
display: flex;
flex-direction: row;
justify-content: center;
}
<div class="search-button">
<form id="form">
<button><img class="path1" src="C:\Users\przem\Projekty\strona-task\img\1024px-Search_Icon.svg.png"></img></button>
<input type="search" id="query" name="q" placeholder="Search...">
</form>
</div>
you can also put a unicode inside the placeholder.
.path1{
max-width: 18px;
max-height: 18px;
}
.search-button{
border-bottom: #0A093D;
width: 30%;
height: 100%;
display: flex;
flex-direction: row;
justify-content: center;
}
<div class="search-button">
<form id="form">
<input type="search" id="query" name="q" placeholder=" 🔍︎ Search...">
</form>
</div>
Here you go...
input {
border: none;
}
.search-button {
width: 250px;
border-bottom: 2px solid lightgrey;
padding-bottom: 10px;
}
<div class="search-button">
<form id="form">
<button><img class="path1" src="C:\Users\przem\Projekty\strona-task\img\1024px-Search_Icon.svg.png"></button>
<input type="search" id="query" name="q" placeholder="Search...">
</form>
</div>
Here's a fiddle with my HTMl and CSS:
https://jsfiddle.net/e06btr2w/2/
This is a sample of a simple UI for categorising images. The user should be shown an overview of the image (i.e. the entire image) but be able to zoom in and pan for closer inspection if necessary.
I would like to allow the user to pan and pinch zoom the image only, without affecting the other UI elements.
Is this possible with CSS only? I'm not a day to day web dev any more, but I see there's a touch-action CSS rule now which I thought would do what I want, but it doesn't seem to:
touch-action: pinch-zoom pan-x pan-y;
Maybe I'm using it wrong? I know this is possible with some JS but thought it would be much simpler if it could be CSS only.
HTML:
<div class="target fill">
<img class="classification" src="https://c4.wallpaperflare.com/wallpaper/528/806/409/1920x1080-beach-desktop-background-wallpaper-preview.jpg" />
</div>
<div class="destinations">
<form method="post" action="/SortClassifications/">
<input type="hidden" name="target" value="ForRemoval" />
<input type="hidden" name="filename" value="2022-01-17-223050.png" />
<input name="destination" type="submit" class="btn btn-danger" value="Remove" />
</form>
<form method="post" action="/SortClassifications/">
<input type="hidden" name="target" value="Attack" />
<input type="hidden" name="filename" value="2022-01-17-223050.png" />
<input name="destination" type="submit" class="btn btn-primary" value="Attack" />
</form>
<form method="post" action="/SortClassifications/">
<input type="hidden" name="target" value="Back" />
<input type="hidden" name="filename" value="2022-01-17-223050.png" />
<input name="destination" type="submit" class="btn btn-primary" value="Back" />
</form>
<form class="undo" style="float: right;" method="post" action="/SortClassifications/Home/Undo?undoFile=2022-01-17-223039.png&undoTarget=Claim">
<input name="destination" type="submit" class="btn btn-warning" value="Undo" />
</form>
</div>
CSS
body {
background-color: black;
position: relative;
}
.container {
height: 100%;
width: 100%;
}
.classification {
width: 100%;
top: 50%;
margin-bottom: 20px;
}
div.destinations {
position: fixed;
bottom: 0px;
left: 0px;
max-width: 80%;
}
.destinations form {
float: left;
margin: 0 20px 10px 0;
}
.destinations .undo {
margin-right: 20px;
position: fixed;
right: 0px;
}
.fill {
display: flex;
justify-content: center;
align-items: center;
overflow: hidden
}
.fill img {
flex-shrink: 0;
min-width: 100%;
min-height: 100%
}
.target {
width: 100%;
height: 100%;
touch-action: pinch-zoom pan-x pan-y;
}
html {
position: relative;
min-height: 100%;
}
I want to create this form in css
HTML
<div class="contact__right">
<form action="" class="contact__form">
<div>
<label for="name" class="contact__form-label">Name</label>
<input type="text" id="name" class="contact__form-input">
</div>
<div>
<label for="email" class="contact__form-label">Email</label>
<input type="text" id="email" class="contact__form-input">
</div>
<div>
<label for="phone" class="contact__form-label">Phone</label>
<input type="text" id="phone" class="contact__form-input">
</div>
<div>
<label for="message" class="contact__form-label">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class="contact__form-textarea"></textarea>
</div>
</form>
</div>
CSS
.contact {
&__form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 105px 95px;
color: $white;
}
&__form-input,
&__form-textarea {
width: 300px;
height: 40px;
background: transparent;
border: 1px solid white;
border-radius: 2px;
margin-bottom: 25px;
}
&__form-textarea {
height: 150px;
}
&__form-label {
padding-right: 70px;
}
}
What I'm struggling with is alignment of inputs with labels and of textarea at the same line vertically.
textarea always sticks out at the side, because of its label which has longer text than the rest.
All the help will be appreciated.
I would not use a flexbox for the form, but for each <div> inside the form. The labels are vertically centered for each input field, except for the textarea. There the label is vertically aligned at the top. You can play with top padding there when desired.
* {
box-sizing: border-box;
}
.contact__right {
background-color: gray;
}
.contact__form {
padding: 105px 95px;
width: 100%;
color: white;
}
.contact__form>div {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 25px;
}
.contact__form-input,
.contact__form-textarea {
width: 300px;
height: 40px;
background: transparent;
border: 1px solid white;
border-radius: 2px;
}
.contact__form-textarea {
height: 150px;
}
label[for="message"].contact__form-label {
align-self: flex-start;
}
<div class="contact__right">
<form action="" class="contact__form">
<div>
<label for="name" class="contact__form-label">Name</label>
<input type="text" id="name" class="contact__form-input">
</div>
<div>
<label for="email" class="contact__form-label">Email</label>
<input type="text" id="email" class="contact__form-input">
</div>
<div>
<label for="phone" class="contact__form-label">Phone</label>
<input type="text" id="phone" class="contact__form-input">
</div>
<div>
<label for="message" class="contact__form-label">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class="contact__form-textarea"></textarea>
</div>
</form>
</div>
Add following css code and your problem will be solved.
.contact__form-label {
vertical-align: top;}
Add this CSS rule for label:
label {
width: 100px;
display: inline-block;
vertical-align: top;
}
(otherwise label will be treated as an inline-element. This way you give it a fixed width and align it to the top)
If you don't like the alignment at the very top, you can add a padding-top ike in the following snippet:
form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 105px 95px;
color: $white;
}
input,
textarea {
width: 300px;
height: 40px;
background: transparent;
border: 1px solid white;
border-radius: 2px;
margin-bottom: 25px;
}
textarea {
height: 150px;
}
label {
width: 100px;
display: inline-block;
vertical-align: top;
padding-top: 14px;
}
.contact__right {
background: #ccc;
}
<div class="contact__right">
<form action="" class="contact__form">
<div>
<label for="name" class="contact__form-label">Name</label>
<input type="text" id="name" class="contact__form-input">
</div>
<div>
<label for="email" class="contact__form-label">Email</label>
<input type="text" id="email" class="contact__form-input">
</div>
<div>
<label for="phone" class="contact__form-label">Phone</label>
<input type="text" id="phone" class="contact__form-input">
</div>
<div>
<label for="message" class="contact__form-label">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class="contact__form-textarea"></textarea>
</div>
</form>
</div>
´
You are gonna have to do that manually I guess. Normally websites tend to break line after the labels and bring the input fields to the next line.
I created an overlay with div over top of it, right now I am trying to center the div over top of the overlay, I tried messing around the left and right but nothing worked.
.request-estimate {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
background-color: rgba(0,0,0,0.8);
display: none;
}
.request-estimate-box {
display: none;
height: 400px;
width: 40%;
margin: 0 auto;
background-color: #FFF;
z-index: 99999;
position: fixed;
top: 15%;
padding: 20px;
border-radius: 5px;
}
And here is the CSS
<div class="request-estimate"></div>
<div class="request-estimate-box">
<h1>Request Free Estimate</h1>
<form action="" method="post">
<p>
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control" />
</p>
<p>
<label for="email">Email</label>
<input type="email" name="email" id="email" class="form-control" />
</p>
<p>
<label for="phone">Phone</label>
<input type="phone" name="phone" id="phone" class="form-control" />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-default" />
</p>
</form>
</div>
.request-estimate {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
background-color: rgba(0,0,0,0.8);
/*display: none;*/
}
.request-estimate-box {
/*display: none;*/
height: 400px;
width: 40%;
margin-left:-20%; /*add this = width/2*/
background-color: #FFF;
z-index: 99999;
position: fixed;
top: 15%;
left:50%; /*add this*/
padding: 20px;
border-radius: 5px;
}
<div class="request-estimate"></div>
<div class="request-estimate-box">
<h1>Request Free Estimate</h1>
<form action="" method="post">
<p>
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control" />
</p>
<p>
<label for="email">Email</label>
<input type="email" name="email" id="email" class="form-control" />
</p>
<p>
<label for="phone">Phone</label>
<input type="phone" name="phone" id="phone" class="form-control" />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-default" />
</p>
</form>
</div>
Solution: https://jsfiddle.net/gqqqeLfL/
request-estimate-box was not being contained by request-estimate.
Originally:
<div class="request-estimate"></div>
<div class="request-estimate-box"></div>
Changed to:
<div class="request-estimate">
<div class="request-estimate-box"></div>
</div>
Furthermore, removed position:fixed since that glues the element to an exact position thus nullifing your margin-auto. Now the position default is position:relative and the margin:auto is properly executed.
I see two alternatives :
.request-estimate-box {
height: 400px;
width: 40%;
background-color: #FFF;
z-index: 99999;
position: fixed;
top: 15%;
left: 0;
right: 0;
margin: auto;
padding: 20px;
border-radius: 5px;
}
http://codepen.io/anon/pen/dPLxPJ?editors=110
And :
.request-estimate-box {
height: 400px;
width: 40%;
background-color: #FFF;
z-index: 99999;
position: fixed;
top: 15%;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
padding: 20px;
border-radius: 5px;
}
http://codepen.io/anon/pen/ByEXyM?editors=110
And a margin half it's width from the center of course, like Tambo is suggesting.
I'm trying to change the div #header-search when focus the input #search. so when people focus the search field get bigger!
<div id="header-search">
<form >
<div class="input-box">
<input id="search" type="search" name="q" value="" class="input-text required-entry" maxlength="128" placeholder="Search" autocomplete="off">
<button type="submit" title="Search" class="button search-button"></button>
</div>
<div id="search_autocomplete" class="search-autocomplete" style="display: none;"></div>
</form>
</div>
Style:
#header-search{
display: block;
position: absolute;
top: 0px;
left: 200px;
width: 40%;
height: 80px;}
#search{
width: 100%;
height: 80px;
}
#search:focus #header-search{
left: 0px;
width: 100%;
}