I want to have something like this
instead I
My html code is this
`
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<form class="quote" action="javascript:void(0);">
<span class="close">×</span>
<article class="goright">
<input type="name" name="Name" placeholder="" style="width: 140px"><br>
<input type="lastname" name="lastname" placeholder="" style="width: 140px"><br>
<input type="Place" name="Place" placeholder="" style="width: 140px"><br>
</article>
<aside id="sidebar">
<textarea type="name" name="Name" placeholder="" style="height: 80px"></textarea> <br>
</aside>
</form>
</div>
</div>
</div>
And this is my CSS
.modal {
display: none;
position: relative;
z-index: 1;
padding-top: 100px;
left: 0;
top: -300px;
float: right;
width: 40%;
height: 40%;
overflow: auto;
}
.modal-content {
position: relative;
background-color: #fefefe;
margin:auto;
padding: 0;
border: 1px solid #888;
width: 80%;
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4;
overflow: hidden;
}
article#goright
{
float: right;
}
aside#sidebar
{
float: left;
}
aside#sidebar .quote input, aside#sidebar .quote textarea
{
width: 90%;
padding: 5px;
}
so I tried to look up this thing here but I could not find an answer that works for me, I tried a lot of variations but nothing really works and I can not get the result, I only managed to get one side that is floated right and aside bar that is left but aside is under previous bar.
So, can you give me a hint or code that can help me achieve the desired result ?
You don't need to use <aside> and other CSS tweaks to achieve the structure.
Just move the <textarea> above the <input> tags and add a float:left class and float:right class to them respectively.
The width of the form is inherited from the .modal class.
Also <input> tags type attribute used are invalid. Supporting type attributes are as mentioned in: https://www.w3schools.com/tags/att_input_type.asp
Also <textarea> does not have a type attribute by default.
.modal {
width: 40%;
height: 40%;
overflow: auto;
}
.align-right {
float: right;
}
.align-left {
float: left;
}
.modal-content {
background-color: #fefefe;
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4;
}
input {
margin-bottom: 5px;
}
<div id="myModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<form class="quote" action="javascript:void(0);">
<textarea name="Name" placeholder="Textarea" style="height: 80px" class="align-left"></textarea>
<input type="text" name="Name" placeholder="Input A" style="width: 140px" class="align-right" />
<input type="text" name="lastname" placeholder="Input B" style="width: 140px" class="align-right" />
<input type="text" name="Place" placeholder="Input C" style="width: 140px" class="align-right" />
</form>
</div>
</div>
</div>
Here's an example of what you're trying to achieve -
.wrapper {
max-width: 500px;
}
.textarea-wrapper,
.input-wrapper {
float: left;
width: calc(50% - 10px);
}
.textarea-wrapper {
margin-right: 20px;
}
.textarea {
width: 100%;
height: 90px;
}
.input {
margin-bottom: 16px;
}
<div class="wrapper">
<div class="textarea-wrapper">
<textarea class="textarea"></textarea>
</div>
<div class="input-wrapper">
<input type="text" class="input" placeholder="Text 1">
<input type="text" class="input" placeholder="Text 2">
<input type="text" class="input" placeholder="Text 2">
</div>
</div>
Here's a link.
https://codepen.io/aphextwix/pen/MmZxjR
Take a look at this fiddle: https://jsfiddle.net/5xw7ssa4/
But you have some mistakes in your css:
Height should not be in %.
Both container must float to right.
Do not forget to clear:both after last floating element.
article#goright must be article.goright
In your html you have type="name" for example. It must be type="text".
Hi there you should review both your html markup and css as well bellow are my suggestions
css
.modal {
position: relative;
z-index: 1;
padding-top: inherit;
width: 50%;
height: 123px;
margin: 0 auto;
margin-top: 20px;
}
.modal-content {
position: relative;
background-color: #fefefe;
margin:auto;
padding: 0;
border: 1px solid #888;
width: 80%;
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4;
}
form {
width: 100%;
padding: 10px 0px;
}
.close{
position: absolute;
right: 0;
color: #fff;
background: #000;
padding: 5px;
z-index: 3;
}
/*a classis identified by a "." an id is identified by an "#" so article#goright is wrong you should have wrote article.goright*/
article.goright {
float: left;
width: 50%;
}
aside#sidebar {
float: left;
width: 50%;
}
/* .quote is the form class aside is inside the form so instead of aside#sidebar .quote textarea you should write .quote aside#sidebar textarea */
.quote aside#sidebar input, .quote aside#sidebar textarea
{
width: 90%;
padding: 5px;
}
article.goright input {
width: 80%;
margin-bottom: 5px;
height: 20px;
}
/*very important to solve the issue*/
.clear{
width: 100%;
height: 0;
clear: both;
float: none;
}
html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<title>Testing Page</title>
</head>
<body style="width:100%; margin: 0 auto; padding: 0; text-align: center;">
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<form class="quote" action="javascript:void(0);">
<span class="close">×</span>
<aside id="sidebar">
<textarea type="name" name="Name" placeholder="" style="height: 80px"></textarea> <br>
</aside>
<article class="goright">
<input type="name" name="Name" placeholder=""><br>
<input type="lastname" name="lastname" placeholder=""><br>
<input type="Place" name="Place" placeholder=""><br>
</article>
<!-- this is the div you need to have myModal div cover the div inside it since they are floating left -->
<div class="clear"></div>
</form>
</div>
</div>
</div>
</body>
</html>
Related
This question already has answers here:
Center image using text-align center?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 1 year ago.
For a long time, I am trying to resolve this issue but I was not able to find a good solution for this. I need to align this image on the center of the form but I am totally unsuccessful in it. You may feel like I am elaborating too much, but this is because StackOverflow is not letting me post this question because it thinks that this question needs deep elaboration. I don't know why.
This is my HTML:
<body>
<div class="wrapper">
<div class="form-container">
<h2>Login Form</h2>
<br>
<form action="" class="login-form">
<div class="imagecontainer">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg"
alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
</div>
</form>
</div>
</div>
</body>
This is my CSS:
* {
padding: 0;
margin: 0;
box-sizing: 0;
}
.wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
background-color: orange;
}
.form-container {
display: block;
width: 70vw;
height: 70vh;
padding-bottom: 150px;
}
form {
border: 3px solid #f1f1f1;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
padding: 14px 20px;
margin: 8px 0;
width: 100%;
}
button:hover {
opacity: 0.8;
}
img.avatar {
width: 20%;
}
.container {
padding: 16px;
}
How can I align the image in the center? I have tried many ways. But I am not able to do it. I have tried aligning using display flex property and tried aligning it in the center and tried to justify the content in the center!
.imagecontainer {
text-align: center;
}
Will do the job.
Adding text-align:center should solve your problem -
<div class="wrapper">
<div class="form-container">
<h2>Login Form</h2>
<br>
<form action="" class="login-form">
<div class="imagecontainer" style="text-align:center">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg"
alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
</div>
</form>
</div>
</div>
* {
padding: 0;
margin: 0;
box-sizing: 0;
}
.wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
background-color: orange;
}
.form-container {
display: block;
width: 70vw;
height: 70vh;
padding-bottom: 150px;
}
form {
border: 3px solid #f1f1f1;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
padding: 14px 20px;
margin: 8px 0;
width: 100%;
}
button:hover {
opacity: 0.8;
}
.imagecontainer {
display: flex;
justify-content: center;
}
img.avatar {
width: 20%;
}
.container {
padding: 16px;
}
<body>
<div class="wrapper">
<div class="form-container">
<h2>Login Form</h2>
<br>
<form action="" class="login-form">
<div class="imagecontainer">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg" alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
</div>
</form>
</div>
</div>
</body>
You need to use the flex property on the parent.
Add this to your css
.imagecontainer {
display: flex;
justify-content: center;
}
Just use margin
html, body {
margin: 0;
}
.wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
background-color: orange;
}
.form-container {
display: block;
width: 70vw;
height: 70vh;
padding-bottom: 150px;
}
form {
border: 3px solid #f1f1f1;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
padding: 14px 20px;
margin: 8px 0;
width: 100%;
}
button:hover {
opacity: 0.8;
}
.imagecontainer {
text-align: center;
}
img.avatar {
width: 20%;
}
.container {
padding: 16px;
}
<body>
<div class="wrapper">
<div class="form-container">
<h2>Login Form</h2>
<br>
<form action="" class="login-form">
<div class="imagecontainer">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg"
alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
</div>
</form>
</div>
</div>
</body>
Try to use margin:auto on imagecontainer div.
You can make use of <center> tag.
<center>
<div class="imagecontainer">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg" alt="Avatar" class="avatar">
</div>
</center>
Just place the above code in place of imagecontainer div. You need to wrap the div in center tag.
I've been struggling to have my login box to the right of my header near the top right of the page. I would like the header and everything in blue to be next to each other with the login box in the top right still in the blue, with the rest of the page in white. Through my CSS using the .left and .right div tags I was not able to accomplish that.
* {
color: #000000;
}
body {
margin: 0px 150px 0px 150px;
color: #ffffff;
}
div.header {
background-color: #b3d9ff;
width: 100%;
margin: 10px auto 10px auto;
}
div.page {
color: #e6f2ff;
}
img {
padding: 10px;
}
.left {
width: 200px;
float: left;
}
.right {
margin-left: 2200px;
}
<div id="page">
<div class="header">
<div id="left">
<h1>Welcome to the best blog in the world!</h1>
<h6>I know you're jealous...</h6>
</div>
<div id="right">
<fieldset>
<legend>
<h4>Already a member? Login here:</h4>
</legend>
<form method="GET" action="http://csis.svsu.edu/~cmdewey/thankyou.html">
Login name:
<input type="text" id="uname" name="uname"><br><br> Password:
<input type="password" id="secretpass" name="secretpass"><br><br>
<input type="submit" value="Submit">
</form>
</fieldset>
</div>
</div>
I refactored the html snd css because you were using class selectors in html instead of id selectors.
* {
color: #000000;
}
body {
color: #ffffff;
}
.header {
overflow: hidden;
background-color: #b3d9ff;
width: 100%;
margin: 10px auto 10px auto;
}
div.page {
color: #e6f2ff;
}
img {
padding: 10px;
}
.left {
width: 50%;
float: left;
}
.right {
width: 50%;
float: right;
}
<div id="page">
<div class="header">
<div class="left">
<h1>Welcome to the best blog in the world!</h1>
<h6>I know you're jealous...</h6></div>
<div class="right">
<fieldset><legend>
<h4>Already a member? Login here:</h4></legend>
<form method="GET" action="http://csis.svsu.edu/~cmdewey/thankyou.html">
Login name:
<input type="text" id="uname" name="uname"><br><br>
Password:
<input type="password" id="secretpass" name="secretpass"><br><br>
<input type="submit" value="Submit">
</form></fieldset></div></div>
enter image description here
Just add this to your header class : display:inline-flex
so change it like this :
div.header {
background-color: #b3d9ff;
width: 100%;
margin: 10px auto 10px auto;
display:inline-flex;
}
https://jsfiddle.net/emilvr/rpqzvgwq/1/
Your code is Well,Just you have a few wrong :
1)you use ID in tag html but use . selector in css.
2)you dont need to margin-left: 2200px; in #right.
3)use overflow: auto; in .header.
4)use box-sizing: border-box; in #left and #right.
I Fix them ,I hope help you,
Full Code:
* {
color: #000000;
}
body {
color: #ffffff;
}
div.header {
background-color: #b3d9ff;
width: 100%;
overflow: auto;
}
#page {
color: #e6f2ff;
}
img {
padding: 10px;
}
#left {
width: 50%;
float: left;
box-sizing: border-box;
}
#right{
width: 50%;
float: right;
box-sizing: border-box;
}
<div id="page">
<div class="header">
<div id="left">
<h1>Welcome to the best blog in the world!</h1>
<h6>I know you're jealous...</h6>
</div>
<div id="right">
<fieldset>
<legend>
<h4>Already a member? Login here:</h4>
</legend>
<form method="GET" action="http://csis.svsu.edu/~cmdewey/thankyou.html">
Login name:
<input type="text" id="uname" name="uname"><br><br>
Password:
<input type="password" id="secretpass" name="secretpass"><br><br>
<input type="submit" value="Submit">
</form>
</fieldset>
</div>
</div>
</div>
I have a header containing an image and search box. Both header area and results area are separate divs .
Search box is in header area. In left side of results div there are some menu items. I need to align my search box with results start area.
In .tk-bl-header I have added margin-left=5em to work. But when I move to different screen resolution it gets misaligned.
.tk-bl-header .tk-header-search-area {
display: inline-block;
float: left;
width: 43.75%;
padding-left: 1.5625%;
padding-right: 1.5625%;
position: relative;
color: black;
margin-left: 5em;
}
.searchform-container .searchform {
margin-bottom: 1em;
}
header .tk-bl-header h1 #logo a {
text-decoration: none;
}
a.library-logo {
background: url("../abc.jpg") no-repeat scroll left top transparent;
width: 110px;
height: 100px;
}
a.logo-name {
margin-top: 10px;
font-size: 20px;
}
div#second-header {
display: inline-block;
height: 65px;
position: relative;
width: 100%;
/* overflow: hidden; */
}
<header class="tk-bl-header">
<div id="second-header">
<h1 id="logo">
ABCD
</h1>
<div class="tk-header-search-area">
<div class="tk-header-search-form">
<div class="searchform-container ">
<form id="" class="searchform" action="" method="get" data-filters="">
<fieldset>
<legend>Search</legend>
<input type="text" name="q" class="query" value='${query.value.display}' placeholder="Search documents.." autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" required>
<input type="submit" class="submit" value="Search">
</fieldset>
</form>
</div>
</div>
</div>
<div id="col-right-top" class="sidebar col"></div>
</div>
</header>
I would like to create a div that contains a text input and a button input on the same line.
The width of the div will be set by me. These two inputs have to fill the div in the way that the button input's width is to be set by it's value, and the rest of the space to be filled by the text input.
I want something like:
<div style="width: 300px; background-color: orange">
<input type="text" />
<input type="button" value="Save" />
</div>
Sorry for my bad English.
Demo: http://jsfiddle.net/abhitalks/Y64ny/
You need to wrap your text input in another div. Apply display:table to the container div and display:table-cell and width:100% to the wrapper div.
HTML:
<div style="width: 300px; background-color: orange">
<div class="t"> <!-- This is the wrapper div around the text input -->
<input type="text" />
</div>
<input type="button" value="Save" />
</div>
CSS:
div { display: table; }
div.t {
display: table-cell;
width: 100%;
}
div.t > input {
width: 100%;
}
Update:
As the Op (#ChocapicSz) states in the comment below, adding box-sizing:border-box will fix the paddings.
Updated fiddle: http://jsfiddle.net/abhitalks/Y64ny/1/
http://jsfiddle.net/8FC2t/
<div>
<input type="text" class='save'/>
<input type="button" value="Save" />
</div>
<br>
<div>
<input type="text" class='dns' />
<input type="button" value="Do not Save" />
</div>
div{
width:200px;
background-color:orange;
}
.dns{
width:calc(100% - 105px)
}
.save{
width:calc(100% - 65px)
}
div>input[type='button']{
float:right;
}
Using position absolute and slightly restructuring the css might work better for you.
Also using <button> instead of <input type="button"> makes life a little easier to style.
I've created an example at codepen for you to see.
HTML:
<div class="container" style="width: 300px">
<input type="text" class="text_input" />
<button value="Save" class="btn">CLICK</button>
</div>
<div class="container" style="width: 500px">
<input type="text" class="text_input" />
<button value="Save" class="btn">CLICK</button>
</div>
<div class="container" style="width: 200px">
<input type="text" class="text_input" />
<button value="Save" class="btn">CLICK</button>
</div>
CSS:
.container {
position: relative;
border: 3px solid orange;
height: 50px;
overflow: hidden;
margin-bottom: 10px;
}
.text_input {
height: 44px;
width: 60%;
padding: 0;
line-height: 30px;
font-size: 20px;
padding: 0;
margin: 3px;
margin-left: 20px;
border: none;
}
.text_input:focus {
outline: none;
}
.btn {
position: absolute;
height: 50px;
line-height: 50px;
right: 0;
top: 0;
margin: 0;
padding: 0;
background: orange;
color: white;
border: none;
width: 30%;
font-weight: bold;
}
.btn:hover {
color: black;
cursor: pointer;
}
Gives you this:
See it working on codepen
<style>
.f-lft {
float:left;
border:2px solid orange;
}
</style>
<body>
<div style="width: 300px;">
<div>
<input class="f-lft"type="text" style="width:80%"/>
<input class="f-lft" type="button" value="Save"/>
</div>
</div>
</body>
I have attached a fiddle for you http://jsfiddle.net/GLAee/
I have done a single one. Remaining you better practice.
Edited :
add width of text field in percent
Another way is to use display flex on their parent.
<div class="parent" style="width: 300px; background-color: orange">
<input type="text" />
<input type="button" value="Save" />
</div>
CSS
.parent{
display: flex;
width: 100%;
height: 50px;
}
input[type="text"] {
height: 50px;
width: 90%;
border: none;
outline: none;
padding: 10px;
font-size: 14px;
}
input[type="button"] {
width: 10%;
height: 50px;
border: none;
outline: none;
background-color: orange;
}
Note, you can play around with the font-size and height to have the desired height and font-size that you want.
I am trying to center the text and form field inputs in the #registration-code-entry .registration-code-entry-content div
Not sure what I am doing wrong.
http://jsfiddle.net/yLX4F/
<div id="registration-code-entry">
<div class="registration-code-entry-header"></div>
<div class="registration-code-entry-middle">
<div class="registration-code-entry-content">
<form class="registration-form">
<div class="field">
<input type="text" name="first_name" placeholder="*First Name" class="required" />
</div>
<div class="field">
<input type="text" name="last_name" placeholder="*Last Name" class="required" />
</div>
<div class="field">
<input type="email" name="email" placeholder="*Email Address" class="required" />
</div>
<div class="field">
<input type="text" name="phone" placeholder="Phone Number" />
</div>
<div class="field">
<input type="checkbox" name="optin">
<label for="optin" />Yes, I would like to receive more information</label>
</div>
<div class="field">
<input type="checkbox" name="accept" class="required" />
<label for="accept">*I accept the Official Rules.</label>
</div>
<input type="submit" class="submit-btn" value="">
</form>
</div>
</div>
<div class="registration-code-entry-footer"></div>
</div>
css
#registration-code-entry {
height: 100px;
width: 359px;
position: absolute;
top: 100px;
right: 20px;
background: transparent;
.registration-code-entry-header {
top: 0;
background: transparent url('../images/form-header.png') no-repeat;
width: 359px;
height: 17px;
}
.registration-code-entry-middle {
background: #713487;
.registration-code-entry-content {
border: 1px solid red;
width: 350px;
margin: 0 auto;
color: #fff;
form {
display: inline-block;
margin: 0 auto;
.field {
margin: 10px 0;
input[type="email"], input[type="text"] {
padding: 5px;
}
}
input.submit-btn {
background: transparent url('../images/submit-btn.png') no-repeat;
width: 168px;
height: 59px;
display: block;
border: 0;
}
}
}
}
.registration-code-entry-footer {
display: block;
bottom: 0;
background: transparent url('../images/form-footer.png') no-repeat;
width: 359px;
height: 11px;
}
}
You can add text-align: centerto .field. You can also change to display: block for form to make the form expand to the full width of the parent.
jsfiddle
Centering the input ?
This will centering it :
.field input[type="text"], .field input[type="email"] {
display:block;
margin: auto;
}
Check This
Just change youre less :
...
.field {
margin: 10px 0;
input[type="email"], input[type="text"] {
padding: 5px;
display:block;
margin:0 auto;
}
}
...