Wrapper not aligning to the top of the page - html

I get a space between my wrapper and the top of the page. I've tried a lot of fixes, but none that works.
The background image covers the background and is aligned to the top, but the wrapper, which has another background, seems to have a margin..
body {
height: 100vh;
background: url("https://i.imgur.com/HgflTDf.jpg") 50% fixed;
background-size: cover;
}
.wrap {
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
width: 100%;
min-height: 100%;
padding: 20px;
background: rgba(17, 71, 114, 0.85);
top: 0;
}
.login {
border-radius: 2px 2px 5px 5px;
padding: 10px 20px 20px 20px;
width: 90%;
max-width: 320px;
background: #ffffff;
position: relative;
padding-bottom: 80px;
}
input {
display: block;
padding: 15px 10px;
margin-bottom: 10px;
width: 100%;
border: 1px solid #ddd;
transition: border-width 0.2s ease;
border-radius: 2px;
}
input:focus {
outline: none;
color: #444;
border-color: 2196F3;
border-left-width: 35px;
}
.fa {
color: #fff;
font-size: 1em;
position: absolute;
margin-top: -47px;
opacity: 0;
left: 0;
transition: all 0.1s ease-in;
}
.fa:focus {
opacity: 1;
left: 30px;
transition: all 0.25s ease-out;
}
.tittel {
color: #444;
font-size: 1.2em;
font-weight: bold;
margin: 10px 0 30px 0;
border-bottom: 1px solid #eee;
padding-bottom: 20px;
}
.sub {
width: 100%;
height: 100%;
padding: 10px 10px;
background: #2196F3;
color: #444;
display: block;
border: none;
margin-top: 20px;
margin-bottom: 0px;
position: absolute;
left: 0;
bottom: 0;
max-height: 60px;
border: 0px solid rgba(0, 0, 0, 0.1);
border-radius: 0 0 2px 2px;
transform: rotateZ(0deg);
transition: all 0.1s ease-out;
border-bottom-width: 7px;
}
footer {
display: block;
padding-top: 50px;
text-align: center;
color: #fff;
font-weight: normal;
text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.2);
font-size: 0.8em;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<div class="wrap">
<form action="" method="post" class="login needs-validation" novalidate>
<h4 class="tittel">Login</h4>
<input type="text" name="username" value="" placeholder="Username" required autofocus/>
<i class="fa fa-user"></i>
<input type="password" name="password" placeholder="Password" required>
<i class="fa fa-key"></i>
<input type="submit" class="sub" value="Login">
</form>
<footer>Company name</footer>
</div>
EDIT: The wrapper seems to be placed 30-40px below the top. The page can be scrolled down this exact length. Tried removing the padding in the .wrap, comment out the background for the body and played around in site inspector for Chrome, disabling and enabling css to see if any of it makes a difference, which it doesn't.

In most major browsers, the default margin is 8px on all sides. It is defined in pixels by the user-agent-stylesheet your browser provides.
Some browsers allow you to create and use your own user-agent-stylesheet, but if you are developing a website, I would recommend staying away from changing this, since your users most likely will not have a modified stylesheet and would then see a different page than you do.
If you want to change it, you can just do this:
body {
margin: 0;
padding: 0;
...
}
But if you have a large project and want to be more complete, use normalize.css. It resets a lot of default values to be consistent across browsers.
Credits to Jon Egeland

You have 20px padding in your wrap class, removing it will probably solve your issue -
Hope this is what you're looking for!

This works for me just fine, no padding needed:
.page-wrap {
max-width: 1200px;
display: flex;
flex-direction: column;
align-items: left;
overflow: hidden;
margin: 0 auto;
}

Related

Issue when creating an expanding search bar using :focus-within

I want to make a search bar as this website's search bar: https://www.arrivalguides.com/en.
I tried with this code: (Here's a codepen)
HTML:
<div class="col-md-4 d-flex justify-content-end all-buttons">
<div class="col-md-4 d-flex justify-content-end search-bar">
<a nbButton outline class="text-decoration-none add-btn" id="add-btn-hide" >
<i class="nb-plus fa-1x"> </i> Add User
</a>
<button nbButton class=" multi-delete-btn" id="delete-btn-hide" >
<i class="nb-trash fa-2x"></i>
Delete All
</button>
<input type="text" class="search-input" id="search-input" fullWidth nbInput placeholder="Enter Search" (keyup)="onKey($event)" />
<button nbButton class="search-btn" nbTooltip="Quick Search " nbTooltipPlacement="top" status="primary">
<!-- <nb-icon icon="search-outline"></nb-icon> -->icon
</button>
</div>
</div>
CSS:
body{
margin:40px;
}
.all-buttons {
height: 30px;
padding-right: 0;
}
.info-btn {
padding: 0.4rem;
border-radius: 0.25rem;
margin-right: 3px;
background-color: blue;
border-color: blue;
}
.advanced-filters {
background-color: green;
padding: 0.6rem 0 0 0;
border-radius: 0.5rem;
margin-left: 1px;
}
.multi-delete-btn {
margin: 0 8px 0 3px;
color:white;
background-color: orange;
border-color:orange;
border-radius: 0.25rem ;
padding: 0 5px 0 0 ;
opacity: 1 !important;
transition: width 0.5s ease-out;
}
.add-btn {
border-color:blue ;
background-color: blue ;
color: white;
padding: 0.5rem;
border-radius: 0.25rem;
margin: 0 ;
opacity: 1 !important;
transition: width 0.5s ease-out;
}
.search-bar {
border: none !important;
margin-right: 2px !important;
border-radius: 100px ;
min-width: 33px !important;
position: relative;
transition: width 0.5s ease-out;
}
.search-input {
background: transparent;
border: 0;
background-color: lightblue;
opacity: 0;
width:40px !important;
transition: width 0.5s ease-out;
&:focus {
outline: 0;
}
}
.search-btn {
cursor: pointer;
border: 2px solid blue;
border-radius: 0.25rem !important;
background: transparent;
margin: 0 !important;
position: absolute ;
top:0 ;
bottom:0;
right: 0;
}
.search-bar:focus-within{
width:50% !important;
border: 2px solid brown !important;
.search-input{
width: 100% !important ;
background-color: rgba(196, 158, 233, 0.205);
color: black !important;
cursor: initial ;
opacity: 1;
}
.add-btn{
display: none !important;
}
.multi-delete-btn{
display: none!important;
}
}
The issue:
When I click outside of the search icon, the "Add" button and "Delete-all" button should appear. But in my case they are just moving. (When I click the search icon, the add-button and delete-all button disappear– this is okay)
Here is an approach isolating only the search input and a search input container. The input is absolutely positioned inside a relative container so that I could grow the input from right to left. I did this by anchoring it to the right side of the parent container using right: 0.
I'm combining focus-within and placeholder-shown to grow/shrink the input. Using placeholder-shown is needed to prevent the input from shrinking if the user has typed something in the input. To hide the placeholder text and only show the search icon when the input is shrunk, I'm making the placeholder text color transparent.
.search-input-container {
position: relative;
}
.search-input {
--search-icon-width: 24px;
--search-max-width-expanded: 20rem;
--search-max-width-collapsed: 2.3rem;
--search-color: #ccc;
background-color: var(--search-color);
max-width: var(--search-max-width-collapsed);
padding: .5rem 0.75rem;
overflow: hidden;
transition: 0.3s max-width, 0.3s margin;
border: none;
background-image: url(https://image.flaticon.com/icons/png/512/93/93642.png);
background-size: 18px;
background-repeat: no-repeat;
background-position: calc(100% - 10px) 50%;
position: absolute;
right: 0;
font-size: 16px;
border-radius: 15px;
}
.search-input:focus-within,
.search-input:not(:placeholder-shown) {
max-width: var(--search-max-width-expanded);
padding-right: var(--search-icon-width);
}
.search-input:not(:focus-within)::placeholder {
color: transparent;
}
/* Ignore */
body {
display: grid;
place-items: center;
}
<div class="search-input-container">
<input placeholder="search" type="search" class="search-input">
</div>

How To Get Responsiveness In Self Made HTML & CSS WebPage

I've made a Register template with HTML & CSS. But It isn't responsive at all.
It gets very weird when I try to decrease the browser width, like this.
This Gets Turned into That:
My HTML Code:
<link rel= "stylesheet" type= "text/css" href = "register.css">
<div id="login-box">
<div class="left-box">
<h1>Register</h1>
<form action="#" method="post">
<input type="text" class="txtb" placeholder="Username">
<input type="text" class="txtb" placeholder="Email">
<input type="text" class="txtb" placeholder="Password">
<input type="text" class="txtb" placeholder="Confirm Password">
<input type="submit" value="Sign Up" name="signup-button" class="signup-btn">
</form>
<small class="text-muted ">Already Have An Account?Login</small>
</div>
<div class="right-box">
</div>
</div>
My CSS Code:
body
{
margin: 0;
padding: 0;
font-size: 16px;
color: #777;
font-family: sans-serif;
font-weight: 300;
background-image: url(images/image.jpg);
background-size: cover;
background-position: center;
}
#login-box
{
position: relative;
height: 430px;
width: 630px;
background: #fff;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
transform: translate(45%, 14%);
}
.left-box
{
position: absolute;
top: 0;
right: 0;
box-sizing: border-box;
padding: 40px;
width: 300px;
height: 430px;
}
h1
{
margin: -10px 0 20px 0;
font-weight: 300;
font-size: 28px;
}
input.txtb
{
display: block;
box-sizing: border-box;
margin-bottom: 26px;
padding: 4px;
width: 220px;
height: 34px;
border: none;
outline: none;
border-bottom: 1px solid #aaa;
font-family: sans-serif;
font-weight: 400;
font-size: 15px;
transition: 0.2s ease;
}
input[type="submit"]
{
height: 32px;
width: 47%;
margin-top: 10px;
margin-bottom: 20px;
background: transparent;
border-radius: 44px;
cursor: pointer;
transition: 0.6s;
border-style: none;
background-image: linear-gradient(-20deg, #fc6076 0%, #ff9a44 100%);
color: white;
}
input[type="submit"]:hover,
input[type="submit"]:focus
{
transform: scale(1.04);
}
.right-box
{
position: absolute;
top: 0;
left: 0;
box-sizing: border-box;
padding: 40px;
width: 315px;
height: 430px;
background-image: url(images/bg.png);
background-size: cover;
background-position: center;
}
small a
{
margin-left: 4px;
}
small a:hover
{
text-decoration: none;
}
#-webkit-keyframes autofill {
to {
color: black;
background: transparent;
}
}
.txtb:-webkit-autofill {
-webkit-animation-name: autofill;
-webkit-animation-fill-mode: both;
}
How Can I Avoid this and set a limit to screen minimize or just show something else when the browser width is decreased?
Thanks In Advance!
You will want to put a media query within your css declaration.
#media only screen and (max-width: 600px) {
body {
background-color: lightblue;
}
}
This example will give any device, that is 600px wide or less, a lightblue background.
Have you tried using Bootstrap? it's not that hard, it works great and theres a lot of documentation online and people on SO that can help you too. Here's a link to get you started: https://getbootstrap.com/
In a nutshell, bootstrap is a tool that helps you make simple websites responsive so they can scale between devices. In actuality it's a little more complcated than this but nothing to worry about.

Centering flex item content

I have the following flex item (#globalSearchContLi) inside a flex-container. The container is an unordered list.
My problem is that I'm creating a fun looking search bar with a half-sphere submit button. The button is pretty much attached to the search bar with inline-block and margin properties.
This bundle (the search bar and button) won't center in the div any way I try to.
I tried setting #globalSearchCont with a specific width and auto side margins, but the whole flexbox presentation won't display correctly on mobile.
Any suggestions/advice? Thanks in advance.
#globalSearchContLi {
flex-grow: 7;
margin: 0px 15px;
flex-basis: 100px;
}
#globalSearchContLi {
flex-grow: 7;
margin: 0px 15px;
flex-basis: 100px;
}
#munchGlobalSearchbar {
width: 240px;
height: 50px;
/* box-shadow: 0 0 0 1px#000,0 0 0 3px #FFF, 0 0 0 5px #333; */
font-weight: 300;
font-size: 1.6rem;
border-radius: 10px;
display: inline-block;
margin-top: 20px;
text-align: center;
background-color: #edad0c;
border-bottom: 2px solid #333;
border-top: 2px solid #333;
border-left: 2px solid #333;
}
#munchGlobalSearchbar::placeholder {
color: #000;
}
#globalSearchBtn {
background-image: url(../imgs/addOn/panEmoji.png);
width: 50px;
height: 51px;
margin: 0px 0px -17px -12px !important;
border-bottom-right-radius: 50%;
border-top-right-radius: 50%;
display: inline-block;
border: 2px solid #333;
background-color: #38b32b;
transition: .2s all ease;
}
.backImageCon {
background-repeat: no-repeat;
background-size: contain;
background-position: center;
}
<li id="globalSearchContLi">
<div id="globalSearchCont">
<input placeholder="Search..." type="textbox" name="globalSearch" id="munchGlobalSearchbar">
<div id="globalSearchBtn" class="backImageCon"></div>
</div>
</li>
Use justify-content: center on the parent to horizontally center the button elements.
#globalSearchContLi {
list-style-type: none;
margin-left: 0;
}
#globalSearchCont {
display: flex;
justify-content: center;
height: 50px;
}
#munchGlobalSearchbar {
width: 240px;
font-weight: 300;
font-size: 1.6rem;
border-radius: 10px;
text-align: center;
background-color: #edad0c;
border-bottom: 2px solid #333;
border-top: 2px solid #333;
border-left: 2px solid #333;
}
#munchGlobalSearchbar::placeholder {
color: #000;
}
#globalSearchBtn {
background-image: url(../imgs/addOn/panEmoji.png);
width: 50px;
border-bottom-right-radius: 50%;
border-top-right-radius: 50%;
border: 2px solid #333;
background-color: #38b32b;
transition: .2s all ease;
margin-left: -10px;
}
.backImageCon {
background-repeat: no-repeat;
background-size: contain;
background-position: center;
}
ul {
margin: 0;
padding: 0;
}
* {
box-sizing: border-box;
}
<ul>
<li id="globalSearchContLi">
<div id="globalSearchCont">
<input placeholder="Search..." type="textbox" name="globalSearch" id="munchGlobalSearchbar">
<div id="globalSearchBtn" class="backImageCon"></div>
</div>
</li>
</ul>

Unable to move elements around after centering div

Recently I made a post to see if anyone was able to help me horizontally align my div to the center of my page. After some tweaking I was able to vertically align my LoginBox to where I needed it to be but sadly, I dont seem to be able to move the Username section and Password section to where I would like this to go, I would appreciate any support given and I understand this is probably very simple to achieve but as someone who is pretty new to coding I love to see the help and support if I don't understand something, I've provided the source code below, and I have also provided a jsfiddle incase it is needed. https://jsfiddle.net/BeastFox/36vet66q/
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="main.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:100" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
</head>
<body>
<div class="LoginBox" style="">
<a class="Login">Login</a>
<input type="text" name="" class="username" placeholder="Username">
<input type="password" name="" class="password" placeholder="Password">
</div>
</body>
</html>
And here is the css.
body,html {
background: repeating-linear-gradient(
to right,
#141517,
#141517 30px,
#1d1f21 30px,
#1d1f21 40px
);
background-size: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
.username {
display: block;
margin: 0 auto;
background: #333;
color: #ccc;
width: 150px;
padding: 6px 15px 6px 5px;
transition: 500ms all ease;
border: 1px solid #333;
margin-bottom: 10px;
text-align: center;
vertical-align: middle;
}
.username:hover {
box-shadow: 0px 0px 4px #000;
}
.password {
padding-top: 30;
text-align: center;
display: block;
margin: 0 auto;
background: #333;
color: #ccc;
width: 150px;
padding: 6px 15px 6px 5px;
transition: 500ms all ease;
border: 1px solid #333;
}
.password:hover {
box-shadow: 0px 0px 4px #000;
}
.LoginBox {
left: 40%;
top: 30%;
position: fixed;
padding-top: 50 auto;
width: 300px;
height: 300px;
margin: 0 auto;
padding: 25px;
background-color: firebrick;
z-index: -3;
box-shadow: 0px 0px 5px #000;
}
.Login {
display: block;
width: 100%;
text-align: center;
font-size: 30px;
font-family: 'Roboto Condensed', sans-serif;
color: #FFF;
}
Thank you for any help that you can provide me with,
Your's most sincerely,
David.
You can align the LoginBox content by...
Wrapping the content in new div.
Adding flexbox properties to LoginBox, which will position the new div.
fiddle
body,
html {
background: repeating-linear-gradient( to right, #141517, #141517 30px, #1d1f21 30px, #1d1f21 40px);
background-size: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
.username {
display: block;
margin: 0 auto;
background: #333;
color: #ccc;
width: 150px;
padding: 6px 15px 6px 5px;
transition: 500ms all ease;
border: 1px solid #333;
margin-bottom: 10px;
text-align: center;
vertical-align: middle;
}
.username:hover {
box-shadow: 0px 0px 4px #000;
}
.password {
padding-top: 30;
text-align: center;
display: block;
margin: 0 auto;
background: #333;
color: #ccc;
width: 150px;
padding: 6px 15px 6px 5px;
transition: 500ms all ease;
border: 1px solid #333;
}
.password:hover {
box-shadow: 0px 0px 4px #000;
}
.LoginBox {
left: 40%;
top: 30%;
position: fixed;
padding-top: 50 auto;
width: 300px;
height: 300px;
margin: 0 auto;
padding: 25px;
background-color: firebrick;
z-index: -3;
box-shadow: 0px 0px 5px #000;
display: flex;
align-items: center;
justify-content: center;
}
.Login {
display: block;
width: 100%;
text-align: center;
font-size: 30px;
font-family: 'Roboto Condensed', sans-serif;
color: #FFF;
margin-bottom: 1em; /* create space between 'Login' and inputs */
}
<div class="LoginBox" style="">
<div class="LoginBox-inner">
<a class="Login">Login</a>
<input type="text" name="" class="username" placeholder="Username">
<input type="password" name="" class="password" placeholder="Password">
</div>
</div>
Changed your css a bit. Added a wrapper element to the fields. Set the parent element(LoginBox) to display:table and element_wrapper to display:table-cell;. Then vertically align the element_wrapper.
<div class="element_wrapper">
<a class="Login">Login</a>
<input type="text" name="" class="username" placeholder="Username">
<input type="password" name="" class="password" placeholder="Password">
</div>
Refer this fiddle https://jsfiddle.net/07753vwx/

Why aren't all 100% of the DIV is used?

I have the following HTML code:
<div class="dispLoginSearch"> <!-- LOGIN AND SEARCH -->
<div class="loginBox">
<p>Log in to <span>My</span> <span>M</span> | Sign Up</p>
<div style="width: 100%; padding: 0; margin: 0; overflow: hidden; height: 38px;" class="brClear">
<input type="text" placeholder="Username" id="txtUsername" class="txtUsername styledTB floatLeft" />
<input type="password" placeholder="Password" id="pwPassword" class="txtPassword styledTB floatLeft" />
Login
</div>
Forgot login/password
</div>
</div>
CSS:
.dispLoginSearch
{
width: 40%;
height: 180px;
vertical-align: middle;
float: right;
padding-right: 3%;
background: #FFFFFF;
overflow: hidden;
text-align: center;
margin: 0 auto;
}
.loginBox {
margin-top: 3%;
border: 1px solid #d4d4d4;
display: block;
width: 100%;
font: 16px sans-serif;
padding: 0 0 0 15px;
border-radius: 5px;
-webkit-font-smoothing: antialiased;
text-align: left;
overflow: auto;
}
.loginBox p {
margin: 5px 0 0;
font-size: 20px;
line-height: 35px;
}
.txtUsername{
width: 38%;
margin-right: 2%;
height: 30px;
}
.txtPassword {
width: 38%;
margin-right: 2%;
height: 30px;
}
.floatLeft
{
float: left;
}
.logBtn
{
width: 10%;
height: 30px;
line-height: 30px;
}
.styledBtn
{
background: #d75813;
display: block;
box-shadow:
0px 5px #BC490A,
0px 8px 10px rgba(148, 148, 148, 0.5);
text-align: center;
vertical-align: middle;
}
.styledTB {
padding-left: 5px;
background: #E8E8E8;
opacity: 1;
border: none;
outline: none;
right: 35px;
box-shadow:
0px 5px #BBB,
0px 8px 10px rgba(148, 148, 148, 0.5);
}
If I keep the logBtn at 10% it stays in the same line but the letter gets cut off almost:
If I increase the percentage to 12%, instead of expanding on the same line to fill up the DIV, it goes to the next line:
For some reason I am not able to use the 100% of the width from the parent DIV. I used float: right on the forgot login/password link and that's how far it goes. For some reason the right side of the DIV is completely not accessible.
How do I resolve the issue?
The inline style will be removed when I have resolved the issue.
Your problem comes from the horizontal paddings you are adding onto the inputs. Those are added to the percentage width and percentage margin you have put on the inputs.
try using the box-sizing: border-box; property on the inputs so the paddings won't get added to the specified width and margins
Some explaination about box-sizing can be found here