I'm trying to center two input fields side by side together with horizontally centering. I have two problems, the first one is that the two input fields for whatever reason overlap each other a little.
The closest I have been to solving this problem is to use "box-sizing: border-box" but that, unfortunately, removes the padding and thus change the design. The second problem is that I need both of the input fields to be in the center.
.quote-page .contact .box {
width: 70%;
}
.quote-page .contact .box .left {
float: left;
width: 50%;
}
.quote-page .contact .box .right {
float: left;
width: 50%;
}
.quote-page .form-2 {
position: relative;
border-radius: 4px;
background-color: rgba(255, 255, 255, 0.8);
color: rgb(77, 77, 77);
border: none;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
line-height: 1.42857143;
height: 30px;
width: 100%;
margin: 10px 0 10px 0;
padding: 6px 12px;
}
<div class="box">
<div class="left">
<input name="email" type="email" class="form-2">
</div>
<div class="right">
<input name="email" type="email" class="form-2">
</div>
</div>
Here is the complete script so you can see the problem:
https://codepen.io/anon/pen/BdQqeN
You had the right idea but unfortunately you are going to have make additional adjustments to what you're creating whether you use the box-sizing: border-box; or not.
The reason it's acting funny is because without border-box you are going over the total of 100% width.
In order to create what you want, I've adjusted the following:
Changed the width of the .box
Added an overflow: hidden; to .box to prevent it from collapsing with the floated children
Added margin: 0 auto; to center the children to .box
Changed the width of .box .left to width: 49%; and a margin-right: 1%; (assuming you wanted space between the inputs)
Same as the above item but for .box .right
Added box-sizing: border-box to .form-2, and increased the height to 40px and padding to 12px
Here's an updated pen using border-box on just your middle inputs:
https://codepen.io/anon/pen/YxpRVK
CSS
.quote-page .contact .box {
width: 73.5%;
overflow: hidden;
margin: 0 auto;
}
.quote-page .contact .box .left {
float: left;
width: 49%;
margin-right: 1%;
}
.quote-page .contact .box .right {
float: left;
width: 49%;
margin-left: 1%;
}
.quote-page .form-2 {
box-sizing: border-box;
position: relative;
border-radius: 4px;
background-color: rgba(255, 255, 255, 0.8);
color: rgb(77, 77, 77);
/*border: 1px solid #ccc;*/
border: none;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
line-height: 1.42857143;
height: 40px;
width: 100%;
margin: 10px 0 10px 0;
padding: 12px;
}
HTML (No Changes)
<div class="box">
<div class="left">
<input name="email" type="email" class="form-2" placeholder="Enter your email" required="">
</div>
<div class="right">
<input name="email" type="email" class="form-2" placeholder="Enter your email" required="">
</div>
</div>
Hardly visible, but they're in the middle and next to each other.
I added the div with class .quote-page. You were referring to it in your CSS but in the HTML it was missing. Here it is the top element set to a width of 100%.
The div.box element is centered via margin: 0 auto.
.quote-page {
width: 100%;
}
.quote-page .box {
margin: 0 auto;
width: 70%;
display: flex;
}
.quote-page .contact .box .left {
width: 50%;
}
.quote-page .contact .box .right {
width: 50%;
}
.quote-page .form-2 {
border-radius: 4px;
background-color: rgba(255, 255, 255, 0.8);
color: rgb(77, 77, 77);
border: none;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075);
line-height: 1.42857143;
height: 30px;
margin: 10px 0 10px 0;
padding: 6px 12px;
}
<div class="quote-page">
<div class="box">
<div class="left">
<input name="email" type="email" class="form-2">
</div>
<div class="right">
<input name="email" type="email" class="form-2">
</div>
</div>
</div>
Simplest way...
Add css
.box {text-align: center;}
.left, .right {display:inline-block;}
Related
I'm working on a website splash page which should show rows of same height. Each row has a title and further text items and one image.
The text and image items should align at the bottom of each row as shown on following screenshot
On Hover, the image should slide up to max height which fits into the row.
My question is:
Can I access the current value of 1fr from parent row grid-auto-rows: 1fr;to give the image on hover a max height?
This is how my code currently looks like:
html, body {margin:0; padding:0}
.jumbo {
width: 100%;
height: 100vh;
background: yellow;
display: grid;
grid-auto-rows: 1fr;
}
.jumbo__item {
position: relative;
box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.75);
font-size: 20vh;
padding: 0 0 0 10px;
#overflow: hidden;
}
.jumbo__rowtags{
position: absolute;
bottom: 0;
right: 0;
}
.jumbo__tag {
margin-right: 10px;
display: inline-block;
background: white;
vertical-align: bottom;
height: 30px;
padding: 0 10px;
font-size: 20px;
line-height: 30px;
}
.jumbo__tag-high{
height: 30px;
overflow: hidden;
background: none;
cursor: pointer;
}
.jumbo__tag-high:hover{
height: auto;
max-height: 200px;
}
.a {background: lightblue; }
.b {background: lightgreen}
.c {background: lightgrey}
<div class="jumbo">
<div class="jumbo__item a">
Dogs
</div>
<div class="jumbo__item b">
and
<section class="jumbo__rowtags">
<span class="jumbo__tag jumbo__tag-high"><img src="https://placeimg.com/350/200/nature"></span>
<span class="jumbo__tag">Hello</span>
<span class="jumbo__tag">World</span>
</section>
</div>
<div class="jumbo__item c">
cats
</div>
</div>
You can make the image and its container to be height:100% of the row then consider a transform animation
html, body {margin:0; padding:0}
.jumbo {
width: 100%;
height: 100vh;
background: yellow;
display: grid;
grid-auto-rows: 1fr;
}
.jumbo__item {
position: relative;
box-shadow: 0px 1px 5px 0px rgba(0, 0, 0, 0.75);
font-size: 20vh;
padding: 0 0 0 10px;
#overflow: hidden;
}
.jumbo__rowtags{
position: absolute;
bottom: 0;
right: 0;
top:0; /* added */
}
.jumbo__tag {
margin-right: 10px;
display: inline-block;
background: white;
vertical-align: bottom;
height: 30px;
padding: 0 10px;
font-size: 20px;
line-height: 30px;
}
.jumbo__tag-high{
height: 100%; /* added */
overflow: hidden;
background: none;
cursor: pointer;
}
.jumbo__tag-high img {
height:100%; /* added */
transform:translateY(calc(100% - 30px));
transition:1s all;
}
.jumbo__tag-high:hover img{
transform:translateY(0%);
}
.a {background: lightblue; }
.b {background: lightgreen}
.c {background: lightgrey}
<div class="jumbo">
<div class="jumbo__item a">
Dogs
</div>
<div class="jumbo__item b">
and
<section class="jumbo__rowtags">
<span class="jumbo__tag jumbo__tag-high"><img src="https://placeimg.com/350/200/nature"></span>
<span class="jumbo__tag">Hello</span>
<span class="jumbo__tag">World</span>
</section>
</div>
<div class="jumbo__item c">
cats
</div>
</div>
Recently I try to fit textbox for publishing post. Main problem - textbox doesn't want to fit properly, even if it obviously should. Here is the image:
and here is the JSFiddle file I prepared for this question:
https://jsfiddle.net/Ch3shireDev/u0j5rgud/4/
It looks like a textbox is naturally expanded to the right.
body {
margin: 0;
height: 100%;
width: 100%;
}
.post {
display: flex;
background-color: lightgrey;
border-radius: 10px;
/* width: auto; */
height: 300px;
padding: 5px 5% 5px 5%;
margin: 20px;
box-shadow: #888888 1px 1px 1px 1px;
}
.background {
margin: 5px;
border: 1px solid;
padding: 0;
}
textarea {
resize: none;
width: 80%;
margin: 10px;
}
.titlebox {
height: 20px;
}
.message {
height: 100px;
}
.background {
width: 100%;
padding: 10px;
}
textarea {
margin: 0;
height: auto;
width: 100%;
}
.input {
background-color: red;
padding: 5px;
}
.buttons {
float: right;
padding-top: 5px;
padding-left: 5px;
margin-bottom: 0;
margin-right: 0;
padding-right: 0;
}
<div class=post>
<div class=background>
<div class=title>
<h3>
Publish post
</h3>
</div>
<div class=input>
<form>
<textarea class=message cols=50></textarea>
</form>
</div>
<div class=buttons>
<input type="submit" value="Preview" />
<input type="submit" value="Send" />
</div>
</div>
</div>
What should I do to get textbox fitting right?
For your textarea, just add box-sizing: border-box;.
textarea{
resize:none;
width:80%;
margin: 10px;
box-sizing: border-box;
}
https://jsfiddle.net/u0j5rgud/6/
border-box: The width and height properties (and min/max properties) includes content, padding and border
You have 2 textarea rules in your css, try deleting the one with the wodth set to 100%
Remove the padding from your textarea
textarea {
padding: 0;
}
How can I align a div in a wrapper on the right side when the div width is auto?
Example:
$("span").click(function() {
$(".calendarNotificationWrapper").append("<div class='calendarNotification'>New added notification</div>");
});
.calendarNotificationWrapper {
position: fixed;
right: 40px;
bottom: 40px;
display: block;
width: auto;
z-index: 1000000;
text-align: right;
}
.calendarNotification {
width: auto;
line-height: 20px;
z-index: 10000000;
padding: 20px;
font-weight: bold;
color: #FFF;
background: rgba(0, 0, 0, 0.5);
border-radius: 5px;
-webkit-box-shadow: 0 0 5px #999;
box-shadow: 0 0 5px #999;
display: table;
margin-top: 10px;
position: relative;
}
<span>Add a notification</span>
<div class="calendarNotificationWrapper">
<div class="calendarNotification">
This div should be aligned right
</div>
<div class="calendarNotification">
That is a notification message with a very very long text
</div>
<div class="calendarNotification">
This div should also be aligned right
</div>
</div>
Add
margin-left:auto;
to .calendarNotification
Based on the MDN article "Stacking and float",
Stacking and float
For floating blocks the stacking order is a bit different. Floating
blocks are placed between non-positioned blocks and positioned blocks:
Background and borders of the root element
Descendant blocks in the normal flow, in order of appearance (in HTML)
Floating blocks
Descendant positioned elements, in order of appearance (in HTML)
However, when I try the sample code by myself, I find the DIV#1 is behind the DIV#3. Shouldn't the DIV#1 be in the front the DIV#3?
DIV#1 is positioned element, so it should be rendered after/in front of floating block.
Please check below code or jsfiddle.
<body>
<br /><br />
<div id="absdiv1">
<br /><span class="bold">DIV #1</span>
<br />position: absolute;
</div>
<div id="flodiv1">
<br /><span class="bold">DIV #2</span>
<br />float: left;
</div>
<div id="flodiv2">
<br /><span class="bold">DIV #3</span>
<br />float: right;
</div>
<br />
<div id="normdiv">
<br /><span class="bold">DIV #4</span>
<br />no positioning
</div>
<div id="absdiv2">
<br /><span class="bold">DIV #5</span>
<br />position: absolute;
</div>
</body>
div {
font: 12px Arial;
}
span.bold { font-weight: bold; }
#absdiv1 {
opacity: 0.7;
position: absolute;
width: 150px;
height: 200px;
top: 10px;
right: 140px;
border: 1px dashed #990000;
background-color: #ffdddd;
text-align: center;
}
#normdiv {
/* opacity: 0.7; */
height: 100px;
border: 1px dashed #999966;
background-color: #ffffcc;
margin: 0px 10px 0px 10px;
text-align: left;
}
#flodiv1 {
opacity: 0.7;
margin: 0px 10px 0px 20px;
float: left;
width: 150px;
height: 200px;
border: 1px dashed #009900;
background-color: #ccffcc;
text-align: center;
}
#flodiv2 {
opacity: 0.7;
margin: 0px 20px 0px 10px;
float: right;
width: 150px;
height: 200px;
border: 1px dashed #009900;
background-color: #ccffcc;
text-align: center;
}
#absdiv2 {
opacity: 0.7;
position: absolute;
width: 150px;
height: 100px;
top: 130px;
left: 100px;
border: 1px dashed #990000;
background-color: #ffdddd;
text-align: center;
}
That's effect of opacity < 1.0. Just comment it:
#flodiv2 {
/*opacity: 0.7;*/
...
}
and you will see elements in normal order. Elements with opacity < 1.0 establish their own stacking context.
Concept seems to be working fine. You didn't mention browsers and their version. That might matter if nightly builds are involved. Anyway. Here's the code that works.
body{ background-color: rgba(0, 0, 0, .1); }
div { border: thin solid rgba(0, 0, 0, 1); width: 60%; }
#floating{ float: right; background-color: rgba(127, 0, 0, .5);}
#descendent-floating{ position: relative; background-color: rgba(0, 127, 0, .5);}
<body>
<div id="descendent">descendent</div>
<div id="floating">floating</div>
<div id="descendent-floating">descendent-floating</div>
</body>
Here's external link for jsfiddle.
We're coming to the end of a huge site redesign, so I'm testing and checking, cross-browser and all that. I was so proud of my beautiful forms with image hovering and checked it in IE8 only to see that the padding and margin for the text was all messed up.
Here's a link to an image displaying the problem: http://i.imgur.com/F6zPP.jpg
It's not a huge deal, just extremely annoying from a designer's point of view and probably the user's too.
Here's a jsfiddle to see what the form looks like: http://jsfiddle.net/kennyk3/qL96P/
And here's the HTML/CSS for the form:
<div id='account'>
<form id='login' action='signin.php' method='post' accept-charset='UTF-8'>
<fieldset class='topform'>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<div id='front_login_text'>
<label for='email'>Email:</label>
<input type='text' name='email' id='email' class='textInput' maxlength='50' />
<label for='password'>Password:</label>
<input type='password' name='password' id='password' class='textInput' maxlength='50' />
</div>
<input type='submit' name='Submit' value='' class='loginsubmit' />
<p class='remtext'><input type='checkbox' class='rememberme' name='remember' value='remember' />Remember me on this computer</p>
<p class='notamember'><strong>Not a Member?</strong> <a href='/register.php'>Sign Up Today!</a></p>
</fieldset>
</form>
<p class='forgotpw'>Forgot Your Password? <a href=''><strong>Click Here to Reset it.</strong></a></p>
</div>
<div class='break'></div>
<div id='button'>
<a href='' class='toursprite' title='Take the Tour'>Take the Tour</a>
</div>
.topform {
padding: 60px 0 0 20px ;
border: none;
}
.textInput
{
width: 190px;
height: 39px;
background: url(../images/textfield-bg.png) no-repeat;
border: none;
color: #929292;
padding: 0 20px 0 10px;
margin: 5px 0 0 0;
overflow: hidden;
}
.textInput:hover {
background: url(../images/textfield-hover.png) no-repeat;
}
#account label {
float: left;
text-align: right;
width: 60px;
font-size: 14px;
margin: 12px 10px 0 0;
color: #929292;
}
#account fieldset {
width: 300px;
}
#front_login_text input:focus, #front_login_text textarea:focus {
outline: 0;
background: url(../images/textfield-hover.png) no-repeat;
}
#side_login_text input:focus, #side_login_text textarea:focus {
outline: 0;
background: url(../images/textfield-hover-small.png) no-repeat;
}
#side_optin_text input:focus, #side_optin_text textarea:focus {
outline: 0;
background: url(../images/textfield-hover-small.png) no-repeat;
}
.loginsubmit {
float: right;
margin: 10px 5px 0 0;
width: 70px;
height: 35px;
background: url(../images/login-btn.png) center no-repeat;
border: 0 none;
cursor: pointer;
}
.loginsubmit:hover {
float: right;
margin: 10px 5px 0 0;
width: 70px;
height: 35px;
background: url(../images/login-btn-hover.png) center no-repeat;
border: 0 none;
cursor: pointer;
}
.loginsubmit:active {
float: right;
margin: 10px 5px 0 0;
width: 70px;
height: 35px;
background: url(../images/login-btn-active.png) center no-repeat;
border: 0 none;
cursor: pointer;
}
When dealing with cross browser compatible forms. Make sure you define line-height for the fields. It can make all the difference and may fix your inconsistencies.
If you set the line-height to be something like 200% or 250%, it should still display in the center for Chrome and in IE should be much closer to the center. I just tried it on your forms.
It's not as clean as a browser specific CSS fix, but it might serve your needs.
.textInput
{
width: 190px;
height: 39px;
background: url(http://i.imgur.com/sEdWU.png) no-repeat;
border: none;
color: #929292;
padding: 0px 20px 0 10px;
margin: 5px 0 0 0;
overflow: hidden;
line-height:220%;
}
IE8 reads margins funny and sometimes collapses them. Rather than redoing anything do this CSS hack:
.textInput
{
width: 190px;
height: 39px;
background: url(http://i.imgur.com/sEdWU.png) no-repeat;
border: none;
color: #929292;
padding: 0 20px 0 10px;
margin: 5px 0 0 0;
padding: 10px 20px 0 10px\9;
overflow: hidden;
}