I am making a login page and I would to position a custom image border to the center underneath the form.
The image is not positioning to the margin-left properly.
Can anyone suggest a solution?
Below is the code:
#import url(http://fonts.googleapis.com/css?family=Droid+Sans);
#import url(http://fonts.googleapis.com/css?family=Roboto);
* {
text-align: center;
}
img {
z-index: -1;
width: 350px;
height: 200px;
margin-top: 200px;
background-size: cover;
position: absolute;
}
body {
background-color: #ecf0f1;
}
#username {
margin-top: 250px;
margin-bottom: inherit;
margin-right: inherit;
width: 250px;
height: 35px;
font-size: 20px;
font-family: 'Droid Sans', serif;
border: 0px solid;
background-color: transparent;
}
#username:focus {
outline: none;
}
#password {
margin-top: 5px;
margin-bottom: inherit;
margin-right: inherit;
width: 250px;
height: 35px;
font-size: 20px;
font-family: 'Droid Sans', serif;
border: 0px solid;
background-color: transparent;
}
#password:focus {
outline: none;
}
#submit {
margin-top: 35px;
border: 0;
background: url(submit1.png);
background-repeat: no-repeat;
width: 200px;
height: 50px;
border: 0;
}
#submit:focus {
outline: none;
}
#submit:hover {
background-image: url(submit2.png);
}
#footer {
clear: both;
position: relative;
z-index: 5;
margin-top: 17em;
background-color: transparent;
font-family: 'Roboto', serif;
color: #bdc3c7;
height: 20px;
font-size: 10px;
}
<div id="main">
<div id="login">
<form action="Scripts/xxx.php">
<img src="border_transparent.png">
<input id="username" type="text" name="username" placeholder="Enter Username" />
<br>
<input id="password" type="password" name="password" placeholder="Enter Secret Password" />
<br>
<button id="submit" value="" />
</form>
</div>
</div>
<div id="container">
<div id="content"></div>
</div>
<div id="footer">© Project Blackhat Operatives 2015</div>
This is currently how my page looks: http://s7.postimg.org/vvfi8m1uj/Screen_Shot_2015_01_11_at_7_07_21_PM.png
This is what I am trying for the page to look like: http://s11.postimg.org/avy2caylv/Screen_Shot_2015_01_11_at_7_09_01_PM.png
It is centered, the issue is the background image behind it that you are absolute positioning. That isn't centered, you can add left: 50% and a negative margin to bring it back to the center (left positions it from the corner not the center):
img {
z-index: -1;
width: 350px;
height: 200px;
background-size: cover;
position:absolute;
left: 50%; //add
margin: 200px 0 0 -175px; //add
}
FIDDLE
What you should be doing though is adding that image as a background-image to either your form or #login containers. Positioning an img tag is not a great way of handling this.
Try
#submit:hover {
background-image: url("submit2.png");
}
Need quotes/double quotes.
Related
I'm currently trying to use HTML together with CSS and my current problem is that I am not able to connect the input beside the arrow button:
I'm here asking how I am able to make the >> button as a "submit" button and that its beside the input?
--------------
| | >>
--------------
body {
padding: 5px 15px 30px 15px;
width: 500px;
height: 250px;
background-image: url('../images/bg2.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
}
.text-center {
text-align: center;
}
.form-control {
margin: 600;
}
label {
display: block;
}
select,
input {
min-width: 100px;
border: 1px solid #fff;
background: #292942;
color: #fff;
border-radius: 25px;
padding: 5px 10px;
}
.mt10 {
margin-top: 20px;
}
.submit {
background-image: url('../images/arrow.png');
background-repeat: no-repeat;
background-position: center center;
width: 23px;
height: 23px;
margin-left: 350px;
}
<body>
<div class="text-center">
<div class="form-control">
<input type="text" id="discord-id-input" name="discord-id-input" placeholder="Discord ID" class="mt10">
<div id="discord-id-button" type="submit" class="submit">
</div>
</body>
Some simple flexbox properties get things into shape.
Other tips:
Use a button for submit. If you don't want button styling, take it off. Semantic use of elements is critical for consistent, familiar usage and for accessibility.
Whenever you find yourself using huge margins for layout, take a step back. That's not a good approach. Use flexbox or CSS grid to create a structure in which your content resides, and use margin or padding only to crate a bit of space between elements, or between grid containers and content.
Don't put hard widths on the body. That should almost always remain flexible to fit the screen.
body {
padding: 5px 15px 30px 15px;
/* width: 500px; */
height: 250px;
background-image: url('../images/bg2.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
}
.text-center {
text-align: center;
}
.form-control {
margin: 600; /* invalid value */
display: flex;
align-items: center;
justify-content: center;
}
label {
display: block;
}
select,
input {
min-width: 100px;
border: 1px solid #fff;
background: #292942;
color: #fff;
border-radius: 25px;
padding: 5px 10px;
}
.mt10 {
margin-top: 20px;
}
.submit-btn {
background-image: url('https://via.placeholder.com/30');
background-repeat: no-repeat;
background-position: center center;
width: 23px;
height: 23px;
margin-left: 12px;
/* margin-left: 350px; */
}
<body>
<div class="text-center">
<div class="form-control mt10">
<input type="text" id="discord-id-input" name="discord-id-input" placeholder="Discord ID">
<button id="discord-id-button" type="submit" class="submit-btn" />
</div>
</div>
</body>
You could use flexbox, like so (Notice I changed the submit button to an HTML button):
.form-control {
display: flex;
align-items: center;
gap:10px;
}
input {
min-width: 100px;
border: 1px solid #fff;
background: #292942;
color: #fff;
border-radius: 25px;
padding: 5px 10px;
}
.submit {
background-image: url("https://img.icons8.com/material-two-tone/24/000000/arrow.png");
background-repeat: no-repeat;
background-position: center center;
background-color: transparent;
outline: none;
border: none;
width: 23px;
height: 23px;
}
<div class="form-control">
<input type="text" id="discord-id-input" name="discord-id-input" placeholder="Discord ID">
<button id="discord-id-button" type="submit" class="submit">
</button>
</div>
backface-visibility not working in Firefox (works in Chrome)
I'm trying to make a form for a credit card that flips over to show the cvc number.
But in Firefox the backside doesn't show at all and the front side shows on both sides, but it works properly in Chrome.
I've tried adding prefixes but it still doesn't work.
Thanks for any help you can give😊
CodePen
HTML:
<div id="on-card-content">
<div id="on-card">
<div id="on-card-inner">
<div id="on-card-front">
<div id="icon-box">
</div>
<div id="number-box">
<label for="on-card-number">Card Number</label>
<input type="text" name="on-card-number" id="on-card-number" placeholder="•••• •••• •••• ••••">
</div>
<div id="name-box">
<label for="on-card-name">Cardholder Name</label>
<input type="text" name="on-card-name" id="on-card-name" placeholder="Your Name">
</div>
<div id="exp-box">
<label for="on-card-exp">Expiry Date</label>
<input type="text" name="on-card-exp" id="on-card-exp" placeholder="MM/YY">
</div>
</div>
<div id="on-card-back">
<div id="swipe-bar"></div>
<input type="text" name="on-card-cvc" id="on-card-cvc" placeholder="123">
<label for="on-card-cvc">CVC</label>
<p id="card-agree">Use of this card is subject to the credit card agreement.</p>
</div>
</div>
</div>
<button type="button" id="card-button"></button>
</div>
CSS:
#on-card-content {
width: fit-content;
width: -moz-fit-content;
}
#on-card {
font-family: 'Source Sans Pro', sans-serif;
width: 320px;
height: 190px;
background: linear-gradient(410deg, #808080 60%, #000000 60%);
margin: 0 auto;
border-radius: 15px;
color: white;
box-shadow: 0 0 15px #0707074d;
transition: transform 0.8s;
transform-style: preserve-3d;
}
#on-card.is-active {
transform: rotateY(-180deg);
box-shadow: 0 0 15px #0707074d;
}
#card-button{
border-radius: 15px;
text-align: center;
margin: 5% 40%;
background: #1a1f71;
color: #ffffff;
border: none;
padding: 10px 10px;
}
#card-button.is-active {
background: #e60404;
}
#card-button::after {
content: 'Next';
}
#card-button.is-active::after {
content: 'Back';
}
#on-card-back {
transform: rotateY(-180deg);
}
#swipe-bar {
background: #000000;
height: 20%;
width: inherit;
margin-top: 5%;
}
#swipe-bar {
background: #000000;
height: 20%;
width: inherit;
margin-top: 5%;
}
#on-card-inner {
background-color: #b3a4a4b3;
border-radius: 15px;
height: inherit;
transition: all 1s ease;
}
#on-card-number {
background: transparent;
border: none;
color: white;
}
#on-card-name {
background: transparent;
border: none;
color: white;
}
#on-card-exp {
background: transparent;
border: none;
color: white;
}
#on-card-front{
transform:rotateY(0deg);
}
#on-card-front,
#on-card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
#on-card-name {
text-transform: uppercase;
}
#on-card-number {
font-size: 145%;
width: 100%;
}
#icon-box {
height: 5rem;
}
#number-box {
margin-left: 5%;
margin-bottom: 3%;
}
#name-box {
width: 50%;
float: left;
margin-left: 5%;
}
#on-card-name {
width: 100%;
}
#exp-box {
width: 40%;
float: right;
margin-right: 3%;
}
#on-card-exp {
width: 100%;
}
#on-card-cvc {
text-align: right;
margin-top: 5%;
height: 15%;
}
#card-agree {
font-size: 70%;
margin: 5%;
}
JS:
const cardButton = document.getElementById('card-button')
const card = document.getElementById("on-card");
cardButton.addEventListener('click', () => {
card.classList.toggle('is-active')
cardButton.classList.toggle('is-active')
})
The Solution from the "duplicate" Question doesn't solve the issue
I need to remove <div id="on-card-inner"> and rework the colour transition I have on that to the front and back.
Firefox seems to not work when child elements that have child elements that have backface-visibility set to hidden.
I have a simple website with 3 controls, yet somehow they are shown in a really weird way.
I've added the red background to show the gap. So far I've tried setting margin/padding to 0, also tried box-sizing but it changed only the width of these elements, didnt make the gaps go away.
#font-face {
font-family: KongText;
src: url('kongtext.ttf');
}
body {
background-color: Highlight;
font-family: KongText
}
h1 {
font-size: 4em;
text-align: center;
}
/*default.cshtml*/
#creator {
width: 350px;
margin: auto;
margin-top: 10%;
display: flex;
}
#joinRoom {
background-color: coral;
height: 50px;
width: 346px;
font-size: 30px;
display: none;
}
#creatorButtons {
width: 350px;
margin: auto;
}
#join {
background-color: coral;
width: 350px;
height: 50px;
font-family: KongText;
font-size: 1.4em;
}
#create {
background-color: coral;
width: 350px;
height: 50px;
font-family: KongText;
font-size: 1.3em;
margin-top: 1px;
}
#footer {
font-size: 13px;
position: fixed;
bottom: 0;
right: 0;
}
/*room.cshtml*/
#chat {
width: 300px;
margin: 0 auto;
}
#chatBox {
resize: none;
width: inherit;
}
#message {
width: inherit;
}
#msgSend {
width: inherit;
}
<body>
<div id="container">
<div id="header">
<h1>Chat Together 826</h1>
</div>
<div id="main">
<div id="chat">
<textarea id="chatBox" rows="40" cols="50" readonly="readonly"></textarea>
<input type="text" id="message" placeholder="Your message" />
<input type="button" id="msgSend" value="Send" />
</div>
</div>
<div id="footer">
© 2016 Chat Together
</div>
</div>
</body>
</html>
Padding has nothing to do with it. You need to change how the browser displays the textarea.
Try updating your CSS for your chatBox element to this:
#chatBox {
display: block; /* Add this line */
resize: none;
width: inherit;
}
So, upon attempting to move one of the images on the site by changing the "margin-top", instead of just that image moving all of them do.
Can mess around with the site here.
http://spoon.fluxdev.nl/
Also if you believe I should do anything else to improve it, please say. The background is setup that way for a reason though.
This is the HTML code.
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<div id="header">
<img id="logo" src="/images/hymn-logo.png" style="width:476px;height:174px;">
</div>
<div id="content">
<img id="username" style="width:247px;height:43px;">
<img id="password" style="width:247px;height:43px;">
<input type="image" id="request-password" src="/images/request-password.png" style="width:248px;height:36px;">
<form id="form" action="login.php" method="post" enctype="multipart/form-data">
<input type="image" id="login" name="login" src="/images/login.png" style="width:248px;height:36px;">
<input type="text" id="username-text" name="username" placeholder="Username" style="width:150px;height:45px;">
<input type="password" id="password-text" name="password" placeholder="********" style="width:150px;height:45px;">
</form>
</div>
</html>
This is the CSS code.
body {
background-image: url("/images/background.png");
background-position: center top;
background-repeat: no-repeat;
background-color: #1B1D1F;
}
#logo {
text-align:center;
display:block;
margin-top: 35px;
margin: 0 auto;
overflow: scroll;
outline: none;
}
#login {
margin-top: -73px;
margin-left: auto;
margin-right: auto;
display: block;
outline: none;
padding: 1px;
}
#request-password {
margin-top: 49px;
margin-left: auto;
margin-right: auto;
display: block;
outline: none;
padding: 1px;
}
#username {
background-image: url("/images/text-input.png");
margin-top: 194px;
margin-left: auto;
margin-right: auto;
display: block;
outline: none;
content: '';
}
#password {
background-image: url("/images/text-input.png");
margin-top: 4px;
margin-left: auto;
margin-right: auto;
display: block;
outline: none;
content: '';
}
#username-text {
margin-top: -147px;
margin-left: auto;
margin-right: auto;
display: block;
background: transparent;
border: transparent;
outline: none;
background-repeat: no-repeat;
color: #FFF;
text-align:center;
position: relative;
padding: 1px;
}
#password-text {
margin-top: 5px;
margin-left: auto;
margin-right: auto;
display: block;
background: transparent;
border: transparent;
outline: none;
background-repeat: no-repeat;
color: #FFF;
text-align:center;
position: relative;
padding: 1px;
}
I've tried a bunch of stuff, but nothing has worked. Thanks.
I'm trying to implement some designs in CSS, but having a bit of trouble figuring out how to align this <span> correctly.
I am trying to achieve the <input> and <button> elements being centrally aligned, but the <span> element being absolutely to the right of the <input>, example:
It's important to make sure that the <span> does not affect the alignment of the other elements. The <input> and <button> should always be exactly in the middle of the parent.
Would be great if I could do this in CSS only. This is what I have so far:
div {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
}
.verify {
display: block;
width: 20px;
height: 20px;
background: red;
position: absolute;
top: 0; /* Not sure how to calculate these? */
right: 0; /* Input.X + Input.Width + 15px ?? */
}
<div>
<input placeholder="Enter code" maxlength="8" size="8"/><br />
<span class="verify"></span>
<button>Register</button>
</div>
Additional Info:
It only has to work in Chrome
I can make all elements a fixed width if required
I can make DOM changes if required
I would prefer not to hardcode X/Y co-ordinates for the <span>...I might want to change the input/button dimensions later
Wrap the input and the span inside a div with position: relative and display:inline
The span .verify will get absolutely positioned, leaving the input element to it's original position (centered aligned)
By giving a top:50% and then margin-top: -10px (half of its height), it will get in the middle of it's parent height.
.wrp {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
.inpWrp {
display: inline;
position:relative;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
}
.verify {
display: block;
width: 20px;
height: 20px;
background: red;
position: absolute;
margin-top: -10px;
top: 50%; /* Not sure how to calculate these? */
right: -20px; /* Input.X + Input.Width + 15px ?? */
}
<div class="wrp">
<div class="inpWrp">
<input placeholder="Enter code" maxlength="8" size="8"/>
<span class="verify"></span>
</div>
<br />
<button>Register</button>
</div>
You can wrap your input element in span and using pseudo-element :after to create the square. No need of position absolute:
div {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
vertical-align: middle;
}
.verify:after {
content: "";
width: 20px;
height: 20px;
background: red;
display: inline-block;
vertical-align: middle;
}
<div>
<span class="verify">
<input placeholder="Enter code" maxlength="8" size="8"/>
</span>
<br />
<button>Register</button>
</div>
After #kapantzak comment you can use position absolute like:
div {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
}
.verify:after {
content: "";
width: 20px;
height: 20px;
background: red;
display: inline-block;
position: absolute;
top: 17px;
}
<div>
<span class="verify">
<input placeholder="Enter code" maxlength="8" size="8"/>
</span>
<br />
<button>Register</button>
</div>
Try this...
.main_container {
position: relative;
text-align: center;
background: #B7B7B7;
width: 400px;
}
input {
padding: 5px;
margin: 10px 0;
text-align: center;
font-size: 1.2em;
width: auto;
}
.verify {
display: inline-block;
width: 20px;
height: 20px;
background: red;
position: relative;
top: 2px;
left: 10px;
}
<div class="main_container">
<div><input placeholder="Enter code" maxlength="8" size="8"/>
<span class="verify"></span></div>
<button>Register</button>
</div>