I'm trying to aligne an input field with a button at the bottom of a tchat.
Here is the result on normal screen size +15"
and here is the result on -15"
Html :
<div class="col footer">
<div class="divider"></div>
<div class="row footer-input input-container form-group">
<div class="input-field inline col s10 m10">
<input #messageInput type="text">
<label for="message">Tapez votre message</label>
</div>
<div class="col button-col s2 m2">
<a class="waves-effect btn blue"">
<i class="material-icons">send</i></a>
<app-loading-panel [visible]="isSending"></app-loading-panel>
</div>
</div>
</div>
Css :
div.divider {
margin-top: 2px;
}
div.footer {
position: absolute;
bottom: 0;
margin: 0;
width: 100%;
}
div.input-container {
vertical-align: middle;
padding-top: 10px;
}
input[type=text]:focus:not([readonly]) {
border-bottom: 1px solid #2196F3;
box-shadow: 0 1px 0 0 #2196F3;
}
input[type=text]:focus:not([readonly]) + label {
color: #2196F3;
}
div.footer-input {
margin-bottom: 0;
}
div.button-col {
height: 100%;
}
I'm not good with css, how can I have the input take all the place it can, the button be at the right and centered vertically and nothing going out of bound ?
this might help you from a basic perspective:
Have a container that's a flex box
Assign a flex-grow of 1 to the input
This will ensure the input takes up most of the space whilst the button remains on the right.
.container {
width: auto;
background: #ebebeb;
display: flex;
flex-direction: row;
}
.container input {
flex-grow: 1;
}
<div class="container">
<input type="text" placeholder="Some Stuff"/>
<button> Button </button>
</div>
Related
I am trying to create a responsive strip in my Wordpress and I am rather struggling. I have provided two screenshots to help:
For Desktop, it's looking ok but I am having the following issues:
1: When I increase the padding of the button to make it same height as the input field, it shifts the input field, meaning they're never aligned and I don't know how to fix that?
2: Apply extra width to the input field, when I try to add width, the width increases from left to right, overlapping the button
3: When I attempt to move the container containing the input field and button more to the left (see class .lnviXl.lnviXl) in css, the input field shrinks. Not shown on screenshot
Device:
In devices it looks bad. Simply, I want the gif and text to be next each other and below is an input field and below that the button. Here is what it looks like on a shruken desktop screen to try and replicate a device. Also what's weird, I can't see this text field and button in my mobile device (only can see the image and text) but yer when I shrink browser screen on desktop to replicate device preview, I can see the input field and button. Really bizzare
Here is the current code:
/*newsletter section */
#custom_html-4 {
width: 100% !important;
padding-bottom: 70px;
}
.eVEmvD.eVEmvD.eVEmvD.eVEmvD.eVEmvD.eVEmvD {
border-radius: 0 !important;
}
.newsletter_section {
width: 100% !important;
background: #f2f2f2;
overflow: hidden;
padding-top: 25px;
padding-bottom: 25px;
display: flex;
align-items: center;
color: black;
}
.newsletter_text_section {
width: 50%;
float: left;
font-size: 24px;
padding-left: 30px;
margin-left: auto;
display: flex;
align-items: center;
}
.newsletter_text_section p {
font-size: 24px !important;
margin: 0;
color: black !important;
}
.newsletter_gif {
float: left;
margin-left: 20px;
}
.newsletter_input_section {
width: 50%;
display: flex;
justify-content: flex-end;
margin-right: 30px;
}
.klaviyo-form-Rrsqsh {
margin-left: auto;
}
.kvTDNe.kvTDNe {
width: 400px;
}
.lnviXl.lnviXl {
display: flex;
flex-direction: row;
-webkit-box-align: stretch;
align-items: stretch;
position: relative;
margin-right: 200px;
}
#media(max-width: 855px) {
.newsletter_section {
display: block;
}
.newsletter_input_section {
margin-left: 0 !important;
margin-right: auto !important;
clear: both;
width: 100% !important;
display: block !important;
}
.newsletter_text_section {
margin-left: auto;
margin-right: auto;
padding-left: 0px;
width: 100%;
}
.fGCWnQ.fGCWnQ {
padding: 0px !important;
}
.ctaEzx.ctaEzx {
max-width: none !important;
}
}
<aside id="custom_html-4" class="widget_text widget_number_8 column-1_5 widget widget_custom_html">
<div class="textwidget custom-html-widget">
<div class="newsletter_section">
<div class="newsletter_text_section">
<img src="..." class="newsletter_gif">
<p>Join Balance and get 20% off your first order</p>
</div>
<div class="newsletter_input_section">
<div class="klaviyo-form-Rrsqsh klaviyo-form form-version-cid-3">
<div>
<form class="needsclick View__FormView-sc-1ou3cq2-0 ctaEzx klaviyo-form-version-cid_3 kl-private-reset-css-Xuajs1" novalidate="" isembed="true" tabindex="-1">
<div class="needsclick Column__FormColumn-z5j99u-0 hVFNhP kl-private-reset-css-Xuajs1">
<div data-testid="form-row" class="needsclick Row__FormRow-sc-17nghml-0 lnviXl kl-private-reset-css-Xuajs1">
<div component="[object Object]" formcomponentstyling="[object Object]" data-testid="form-component" class="needsclick FormComponent__StyledFormComponentWrapper-e0xun6-0 CWZcV notranslate kl-private-reset-css-Xuajs1" formcomponenttheme="[object Object]">
<div class="needsclick TextInput__StyledInputContainer-sc-1o6de9f-1 kvTDNe kl-private-reset-css-Xuajs1">
<input type="email" name="email" tabindex="0" styling="[object Object]" placeholder="enter email" aria-label="enter email" aria-invalid="true" valid="0" options="[object Object]" class="notranslate needsclick TextInput__FormStyledTextInput-sc-1o6de9f-0 eFCYcA kl-private-reset-css-Xuajs1"
aria-describedby="klaviyo_ariaid_6">
</div>
</div>
<div component="[object Object]" fullwidth="true" formcomponentstyling="[object Object]" data-testid="form-component" class="needsclick FormComponent__StyledFormComponentWrapper-e0xun6-0 fGCWnQ notranslate kl-private-reset-css-Xuajs1" formcomponenttheme="[object Object]"><button type="button" tabindex="0" class="needsclick Button__FormStyledButton-p2mbjt-0 eVEmvD kl-private-reset-css-Xuajs1">JOIN NOW</button></div>
</div>
</div>
<input type="submit" tabindex="-1" class="notranslate needsclick View__HiddenSubmit-sc-1ou3cq2-1 StXTa kl-private-reset-css-Xuajs1" value="Submit">
</form>
</div>
</div>
</div>
</div>
</aside>
This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 2 years ago.
So, I am new at coding. I was trying to make a very basic static webpage of a calculator using html and css and js.
This is the html
#input {
margin: 0 auto;
}
#num {
border-radius: 25px;
background: #73AD21;
display: inline-block;
padding: 15px;
width: 200px;
height: 100px;
}
<body>
<div id="input">
<div id="num">
<label for="num1">Enter the first number</label>
<input type="number" name="num1" id="num1">
</div>
<div id="num">
<label for="num2">Enter the second number</label>
<input type="number" name="num2" id="num1">
</div>
</div>
<div id="op">
<div id="opadd"><input type="submit" name="add" class="add" value="Add" onclick="add()"></div>
<div id="opsbtrct"><input type="submit" name="subtract" class="sbtrct" value="Subtract" onclick="sbtrct()"></div>
<div id="opmult"><input type="submit" name="multiply" class="mult" value="Multiply" onclick="mult()"></div>
<div id="opdvde"><input type="submit" name="divide" class="add" value="Divide" onclick="dvde()"></div>
</div>
</body>
I want that the #num be centered horizontally.
I tried using
margin: auto;
and
margin: 0 auto;
but nothing works. Please help.
I've been at it for hours.
Here is the complicated way of doing this.
You should create a container div, so you can center the object in.
#container {
display: flex; /* establish flex container */
flex-direction: row; /* default value; can be omitted */
flex-wrap: nowrap; /* default value; can be omitted */
justify-content: space-between; /* switched from default (flex-start, see below) */
background-color: lightyellow;
}
#container > div {
width: 100px;
height: 100px;
border: 2px dashed red;
}
<div id="container">
<div></div>
<div></div>
<div></div>
</div>
when you add margin: 0 auto be sure the html tag not inline or inline-block it should be 'block' css with specific width.
#num {
border-radius: 25px;
background: #73AD21;
display: block;
padding: 15px;
width: 200px;
height: 100px;
margin: 1em auto;
}
label{
white-space: nowrap;
}
just replace this code hope your problem will fix.
add white-space:nowrap for the label to use one line text. #num should be 'block' css with specific width like 200px and display block. thanks
I have two block elements that I would like to be on the same horizontal line. One is a FORM and the other is a DIV.
<div id="miningArea">
<form id="curWorkForm">...</form>
<div id="buttonDescription">
To begin, click thde "Start" button.
</div>
</div>
I thought adding display:inline-block was the key to keeping the elements on the same line. But when I add
#buttonDescription {
display: inline-block;
}
My text element still appears beneath my FORM element -- https://jsfiddle.net/5j57hkLr/6/ . How can I get that other DIV element to appear on the same line?
When there is a lot of text, you have to limit the width of inline-block elements by applying width settings to them which allow both elements to fit into one line, for example width: 50% and width: 45%
Otherwise they will by default expand according to the text, which will result in 100% width when there's enough text to fill a full line.
These are the the 3 ways ways I would think about approaching this:
(Here is a your JSFiddle back with some changes.)
1:
.wrapper {
overflow: hidden;
border: red dashed 1px;
/* For Testing*/
}
.style {
margin: 0;
padding: 10px;
float: left;
}
<div class="wrapper">
<form>
<input class="style" placeholder="Enter Value" />
</form>
<button class="style">Submit</button>
</div>
2: Responsive
* {
box-sizing: border-box;
margin: 0;
}
input, button {padding:10px;}
input {width: 100%;} /* replace "input" with "input , button" if you want the button to take up full with*/
.column {
float: left;
width: 50%;
border: red dashed 1px; /*For Testing*/
}
.row:after {
content: "";
display: table;
clear: both;
}
#media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<div class="row">
<div class="column">
<form>
<input class="style" placeholder="Enter Value" />
</form>
</div>
<div class="column">
<button class="style">Submit</button>
</div>
</div>
3:
* {
box-sizing: border-box;
margin: 0;
}
#mainWrapper {
overflow: hidden;
display: inline-block;
}
button,
input {
width: 100%;
padding: 10px;
}
.formWrap {
float: left;
width: 300px;
}
.btnWrap {
float: left;
width: 100px;
}
<div id="mainWrapper">
<div class="formWrap">
<form>
<input placeholder="Enter Value" />
</form>
</div>
<div class="btnWrap">
<button>Submit</button>
</div>
</div>
add this to your css
#buttonDescription,form {
display: inline-block;
vertical-align:middle;
}
Inorder for two or more elements to be on same line, all the elements should be made display: inline or inline blocks
Here is a working example: https://jsfiddle.net/6wjftgf2/2/
#buttonDescription,form {
display: inline-block;
}
<div id="miningArea">
<form id="curWorkForm"><input placeholder="My Form"/></form>
<div id="buttonDescription">
<button>My Button</button>
</div>
</div>
You can also use flex for this work the code is as follows
.miningArea
{
display: flex;
justify-content: center;
flex-wrap: wrap;
align-items: center;
}
form
{
width: 60%;
}
div
{
width: 40%;
}
.miningArea {
display: flex;
flex-wrap: wrap;
}
form { width: 60%; }
div { width: 40%; }
I don't understand why the three different rows are appearing on the same line. Don't rows usually appear on different lines? I even tried setting a fixed height for the rows and/or columns.
Here is the fiddle: https://jsfiddle.net/qvuo4bqw/
<div class="container-fluid">
<div id="bubble">
<div class="row">
<div class="col-md-12">
<h3 id="question">Question Here</h3>
</div>
</div>
<div class="row">
<div class="col-md-12">
<ul class="list-inline">
<li>Disagree</li>
<label class="disagree" id="disagree-btn" val="0"></label>
<label class="disagree" val="0.5"></label>
<label id="neutral" val="1"></label>
<label class="agree" val="2"></label>
<label class="agree" id="agree-btn" val="3"></label>
<li>Agree</li>
</ul>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-warning" id="back-btn">Back</button>
<button class="btn btn-primary" id="next-btn">Next</button>
</div>
</div>
<br><br>
</div>
.container-fluid {
padding-top: 5%;
display: flex;
justify-content: center;
align-items: center;
}
#bubble {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
border-radius: 100%;
height: 800px;
width: 800px;
border-color: black;
border-style: solid;
border-width: 5px;
background: linear-gradient(0deg, #AA3939 0%, #55AA55 0%);
color: white;
}
.row {
height: 150px;
}
ul>label {
width: 50px;
height: 50px;
border-radius: 100%;
border-style: solid;
cursor: pointer;
text-align: center;
}
.agree {
border-color: #226666;
}
.disagree {
border-color: #AA6C39;
}
#disagree-btn, #agree-btn {
height: 60px;
width: 60px;
}
#next-btn, #back-btn {
height: 50px;
width: 100px;
}
#neutral {
height: 40px;
width: 40px;
border-color: gray;
}
I don't understand why the three different rows are appearing on the same line.
Because your elements are in a flex container (#bubble has display: flex).
And two initial settings of a flex container are flex-direction: row and flex-wrap: nowrap, meaning child elements will align horizontally in a single line and not wrap.
If you want the children of #bubble to appear on different rows, here are a few options you can start with:
Switch to flex-direction: column, or
Enable flex-wrap: wrap, or
Switch to display: block
You are repeating the class = "row"
Try this instead:
<div class="container-fluid">
<div id="bubble">
<div class="row">
<div class="col-md-12">
<h3 id="question">Question Here</h3>
</div>
<div class="col-md-12">
<ul class="list-inline">
<li>Disagree</li>
<label class="disagree" id="disagree-btn" val="0"></label>
<label class="disagree" val="0.5"></label>
<label id="neutral" val="1"></label>
<label class="agree" val="2"></label>
<label class="agree" id="agree-btn" val="3"></label>
<li>Agree</li>
</ul>
</div>
<div class="col-md-12">
<button class="btn btn-warning" id="back-btn">Back</button>
<button class="btn btn-primary" id="next-btn">Next</button>
</div>
</div>
<br><br>
</div>
Well you have a couple issues, A) you have the .list-inline>li set to display: inline-block. So that's why there inline. B) Another issue I saw was that you have only 1 li inside your ul, everything else is labels. Which would probably make it appear inline to. If you want the labels not inside of an li element, then put them inside of a div of another li, either way this is not correct HTML formatting.
I am developing a web app with meteor and material design lite.
Here is what I want to do :
Here is the result with a too small window :
And here is the result with a bigger window :
The HTML code :
<template name="myRefrigerator_header">
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<!-- Title -->
<span class="mdl-layout-title">My Refrigerator</span>
<!-- Add spacer, to align navigation to the right -->
<div class="mdl-layout-spacer"></div>
</div>
<!-- Simple Textfield -->
<div id="msg-layout">
<form action="#">
<div class="mdl-textfield mdl-js-textfield" id="msg-layout-content">
<input class="mdl-textfield__input" type="text" name="content">
<label class="mdl-textfield__label" for="sample1">Text...</label>
</div>
<button class="mdl-button mdl-js-button mdl-button--primary"
id="msg-layout-add-button">
Enregistrer
</button>
</form>
</div>
</header>
</template>
And the CSS applied to it :
#msg-layout {
background-color: #F5F5F5;
margin: 0px 25px 15px 25px;
padding-left: 10px;
padding-right: 10px;
display: flex;
flex-direction: row-reverse;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
}
#msg-layout-content {
color: #3F51B5;
flex: 1 1 0;
}
#msg-layout-add-button {
}
I don't understand why I don't have the right behavior, I have specified that I only want one row and that my input should resize.
What am I getting wrong ?
First, you need to give the id="msg-layout" to the <form>. Only direct children of a display:flex layout will get the special attributes of flexible containers. You are negating flexbox by nesting a <form> where the flexible children would be. Your flexible layout only has one child, the <form>.
This is the best resource I have found for learning flex-box https://css-tricks.com/snippets/css/a-guide-to-flexbox/
I would suggest trimming things down. Flex-box isn't the problem, and more that libraries of style rules make a lot of assumptions - that you may not be able to see from the top.
Here is a stripped down version / http://codepen.io/sheriffderek/pen/MKzMgp
HTML
<form class='this-form' action='#'>
<label class='input-w' for='sample1'>
<input type='text' id='sample1'>
<span>Text...</span>
</label>
<button>Enregistrer</button>
</form>
SCSS
* { // reset box model
box-sizing: border-box;
}
.this-form {
display: flex; // a
flex-direction: row; // b
align-items: center; // d
max-width: 24rem;
padding: .5rem;
border: 1px solid blue;
.input-w {
position: relative;
flex-grow: 1; // c
input {
width: 100%;
border: 0;
border-bottom: 1px solid gray;
&:focus {
outline: none;
+ span {
transform: translate(0, -50px);
opacity: 0;
}
}
}
span {
position: absolute;
bottom: 3px;
left: 0;
color: gray;
font-size: 12px;
transition: 1s;
}
}
button {
height: 30px;
background: transparent;
border: 0;
color: blue;
margin-left: .5rem;
}
}
The mdl-textfield__input class has a set width of 300px due to animation limitations. You need to override this (say width: 100%) to get an expandable textfield. However, this may have adverse affects on the animations since CSS animations don't like unknown lengths.