Top header: Reduce width of input - html

I'm using this grid as a top navabar and I want to make a few alterations:
How can I reduce the width of the input to 40% but still keep it right next to the logo? And how can I add a sign-in div at the right hand corner. But keep in mind that I want the entire header to remain responsive like it is now. If I do the following it looks good in a full screen but when the width of the screen is smaller the input becomes really small.
.top_nav_menu {
border-bottom: 1px solid #e3e3e3;
box-shadow: 0 0 8px 0 #eeeeee;
position: fixed;
top: 0px;
width: 100%;
height: auto;
background-color: #fafafa;
margin-right: 90px;
padding: 15px;
z-index: 2;
}
.header {
display: flex;
justify-content: flex-start;
align-items: center;
height: 50px;
}
.header > form {
width: 65%;
margin-left: 25px;
}
.header > form > input {
width: 40%;
}
<div class="top_nav_menu">
<div class="header">
<img src="http://i.imgur.com/EFkps0m.png">
<form><input type="text"></form>
<div class="floar-right">Sign-in</div
</div>
</div>

You can either reduce the value of 40% in your CSS.
Or add new CSS for max-width:
.header > form > input {
max-width: 50px;
}
For your sign-in div, you can add this CSS:
.float-right {
float:right;
}
However your current class spells floar and not float, you should change that.

you can use this code
body {
margin: 0;
padding: 0;
}
.top_nav_menu {
border-bottom: 1px solid #e3e3e3;
box-shadow: 0 0 8px 0 #eeeeee;
position: fixed;
top: 0px;
width: 100%;
height: auto;
background-color: #fafafa;
margin-right: 90px;
padding: 15px;
z-index: 2;
}
.header {
display: flex;
justify-content: flex-start;
align-items: center;
height: 50px;
}
.header > form {
width: 65%;
margin-left: 25px;
}
.header > form > input {
width: 24%;
}
<div class="top_nav_menu">
<div class="header">
<img src="http://i.imgur.com/EFkps0m.png">
<form><input type="text"></form>
<div class="floar-right">Sign-in</div>
</div>
</div>

Related

How can I add a footer at the end of this website?

I am trying to create a footer at the end of this website but for some reason it appears above the products :
And when I change the browser size :
But I want a footer like this :
Here is my code :
HTML :
{% load static %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="{% static 'main.css' %}">
</head>
<body style="background-color: #36454F;">
{% for i in p%}
<div class='card'>
<div class="number">{{i.Number}}</div>
<img src="{{i.image}}"></img>
<p id="id">{{i.description}}</p>
<a href="{{i.buy}}" target='_blank' rel='noopener noreferrer'>
<button><span class="price"> ${{i.price}}</span> buy</button>
</a>
</div>
{%endfor%}
<div class="footer">
<h3>hello</h3>
</div>
</body>
</html>
CSS :
.card {
max-width: 400px;
margin: 0auto;
text-align: center;
font-family: arial;
border-style: solid;
border-width: 6px;
position: relative;
top: 611px;
margin-bottom: 33px;
margin-right: 33px;
justify-content: center;
float: left;
}
.footer {
position: relative;
height: 130px;
clear: both;
background-color: red;
}
.card img {
height: 400px;
width: 400px;
vertical-align: middle;
}
.price {
background-color: #f44336;
font-size:22px;
border-radius: 3px;
position: absolute;
bottom: 0px;
right: 0px;
padding: 3px;
}
.card button {
border: none;
color: white;
background-color: #000;
position: relative ;
cursor: pointer;
width: 100%;
height: 100px;
font-size: 44px;
align-items: center;
}
.card button:hover {
opacity: .5;
background-color: #330;
}
#id {
background-color: palevioletred;
color: white;
margin: 0;
font-size: 17px;
}
.number {
width: 50px;
height: 50px;
background-color: #330;
color: yellow;
border-radius: 50%;
position: absolute;
top: -22px;
right: -22px;
justify-content: center;
align-items: center;
display: flex;
font-size: 22px;
}
#media (max-width: 1864px) {
.card {
max-width: 300px;
}
.price {
font-size:20px;
}
.card img {
height: 300px;
width: 300px;
}
}
I tried to set a negative bottom property to push it to the end :
.footer {
position: relative;
bottom: -674px;
height: 130px;
clear: both;
background-color: red;
}
But it didn't help. How can i solve the problem?
To set the footer to the bottom of the page, you need to use this CSS:
.footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf; /* Set your own background */
}
If you want it to stay at the bottom of the page and stretch along the bottom, I'd do something like this with the CSS
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: (whatever you want);
color: (color of the text, whatever you want);
text-align: center; /*unless you want the text aligned differently*/
}
Also look up how to use the grid-container if you want the items of the footer in rows like the example you gave.
You need the footer tag to do its job!
Read more about the footer tag here:
https://www.geeksforgeeks.org/html5-footer-tag/
Reference: https://code-boxx.com/keep-html-footers-at-bottom/
The easy ways to keep a footer at the bottom with modern CSS are:
Use footer { position: fixed} or footer { position: sticky } to
keep the at the bottom.
Use a flexbox layout that "stretches" the body section, keep the
footer at the bottom.
body{ display: flex; flex-direction: column; }
main{ flex-grow: 1; }
Lastly, use a grid layout to achieve the same "stretch body
section".
<header>HEAD</header> <main>MAIN</main> <footer>FOOT</footer>
html, body { height: 100%;}
body { disply: grid; grid-template-rows: auto 1fr auto; }

I need to change the order of my divs based on screen-size. I've used the flex order property but can't figure out why it isn't working on my code

I've been trying to change the order of divs after the screen size changes. Initially, Main Heading should be on the first row on the left and Main description on the first row right, with the menu div on the second row. When the screen is resized, I want all these elements re-ordered in a single column in the order- 1. Main heading 2. menu div 3. main description.
I tried using the order function as pointed out by other answers. But for some reason, it still doesn't change the order of divs.
#main-page {
position: relative;
margin-left: 25vw;
;
}
#main-heading {
margin-left: 0px;
padding: 70px 20px 0px 0px;
font-size: 48px;
font-family: DM Serif Display;
width: 35vw;
height: 33vh;
float: left;
overflow: hidden;
}
#main-description {
overflow: hidden;
padding: 100px 10vw 0 80px;
height: 33vh;
width: 180px;
color: gray;
}
#st-line {
border: none;
width: 50px;
margin-left: 0px;
height: 2px;
background-color: #F34650;
}
#main-menu {
background-color: white;
height: 50vh;
display: flex;
flex-direction: row;
justify-content: space-between;
}
div>.menu-items {
height: 25vh;
padding: 25px 25px 5px 25px;
border-radius: 20px;
box-shadow: -2px 8px 20px 1px rgb(0 0 0/0.2);
}
#media (max-width:1040px) {
#main-page {
position: fixed;
margin-left: 5vw;
display: flex;
flex-flow: column;
z-index: 1;
}
#main-heading {
margin-left: 0px;
margin-right: 0px;
height: 25vh;
padding: 80px 30px 0px 0px;
width: 90vw;
overflow: hidden;
order: 1;
font-size: 44px;
}
#main-menu {
display: flex;
flex-direction: row;
order: 2;
}
#main-description {
overflow: hidden;
padding: 20px 0px 20px 20px;
height: 100%;
width: 180px;
order: 3;
}
#st-line {
border: none;
width: 50px;
margin-left: 0px;
height: 2px;
background-color: #F34650;
order: 4;
}
div>.menu-items {
height: 25vh;
padding: 25px 25px 5px 25px;
border-radius: 20px;
box-shadow: -2px 8px 20px 1px rgb(0 0 0/0.2);
}
}
<div id="main-page">
<div id="main-heading">Main Heading</div>
<div id="main-description">Description
<hr id="st-line">
</div>
<div id="main-menu">
<div id="menu-div1" class="menu-items">item1</div>
<div id="menu-div2" class="menu-items">item2</div>
<div id="menu-div3" class="menu-items">item3</div>
<div id="menu-div4" class="menu-items">item4</div>
<div id="menu-div5" class="menu-items">item5</div>
</div>
</div>
Add this line in your CSS and add the code and style you want in your website when the width get to 1040px and you can do this same for other size screen too
#media only screen and (max-width:1040px){
}
This seem to work properly, or maybe I did not get what you are trying to achieve.
Check this codepen and tell us if this is the desired behaviour.
I just modified your media query like so:
#media only screen and (max-width:1040px)
Screen > 1040 px :
Screen < 1040px

CSS how to keep span element fixed in progresbar

I am using the following CSS to display a progresbar and in it I display the time that is left. For some reason no matter what I try the displayed time wont stay at its place and is moving left as the proress bar width is decreasing. I have tried a lot of ways to keep the text from moving and keep it centered but none seems to work. Please help !
CSS:
.progress {
background: rgba(255,255,255,0.1);
justify-content: flex-start;
border-radius: 100px;
align-items: center;
position: relative;
padding: 0 5px;
display: flex;
height: 20px;
width: 300px;
}
.progress-value {
box-shadow: 0 10px 40px -10px #fff;
border-radius: 100px;
background: red;
height: 15px;
}
The div ( the div with the ID timer needs to be in the middle of the progres bar and it should not move while the progres bar is degreasing !)
<div class="progress">
<div id='progress' class="progress-value"><span id='timer' style="display: inline; width: 300px !important;"></span></div></center></div></center>
I solved this by wrapping the progress bar and the time element in another div, position relative, then I can absolutely position the time element in any position; in this case I centered it in the div.
The time stays put because it's out of the flow of the document but it's div takes up the same space as the progress bar.
.progress {
background: rgba(5,5,5,0.5);
justify-content: flex-start;
border-radius: 100px;
align-items: center;
padding: 0 5px;
display: flex;
height: 20px;
width: 100%;
}
.progress-value {
box-shadow: 0 10px 40px -10px #fff;
border-radius: 100px;
background: red;
height: 15px;
width: 35%;
}
.progress-and-timer {
position: relative;
}
.timer-value {
position: absolute;
text-align: center;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 20px;
color: white;
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 20px;
}
<div class="progress-and-timer">
<div id="timer" class="timer-value">time</div>
<div class="progress">
<div id="progress" class="progress-value">
</div>
</div>
</div>

How can I align the text in the center of the image

I'm trying to center a text inside a div, this div contains an image + another div which contains the text that needs to be centered.
See image the following image:
The problem I'm facing is that the image which is also in the div doesn't allow me to outline the text in the center.
I tried to apply padding and margins(even negatives ones) however with no results
So right now this is the code I have in my HTML & CSS files:
.destinations {
padding: 5px 15px;
}
.destinations img {
max-width: 100%;
max-height: 100%;
border-radius: 10px;
}
.flex-item {
width: 290px;
height: auto;
border-radius: 10px;
margin: auto;
}
.flex-item-title {
text-align: center;
color: white;
background-color: black;
opacity: 0.8;
}
<div class="destinations">
<div class="flex-item">
<img src="assets/img/wassenaar.jpg">
<div class="flex-item-title">Wassenaar</div>
</div>
</div>
I hope you can help me out
Here is one approach to vertically and horizontally center the text over the image:
.destinations {
padding: 5px 15px;
}
.destination {
width: 290px;
height: 290px;
display: flex;
border-radius: 10px;
margin: auto;
background-image: url("https://placekitten.com/500/500");
justify-content: center;
align-items: center;
}
.title {
text-align: center;
color: white;
background-color: black;
opacity: 0.8;
}
<div class="destinations">
<div class="destination">
<div class="title">Wassenaar</div>
</div>
</div>
You can get your porblem solve using following css .
.flex-item{
width:300px;
height:200px;
position: relative;
padding: 0;
margin: 0;
text-align: center;
}
.flex-item-title{
position: absolute;
top: 0; right: 0;
bottom: 0; left: 0;
width: 300px;
height: 200px;
text-align: center;
color: white;
display: inline-table;
vertical-align:middle;
line-height:100%;
}
Try changing your css to this css , it will work .

How can I make DIV 100% height of browser without vertical scrolling of header

Both the left and right panels have a height of 100%, but since the Header div takes up X amount of space, there is some vertical scrolling in the window that I want to get rid of.
How can I remove that vertical scrolling?
JSFiddle: http://jsfiddle.net/G7unG/1/
CSS and HTML
html, body{
height: 100%;
margin: 0;
}
.header{
background: #333;
padding: 15px;
text-align:center;
font-size: 18px;
font-family: sans-serif;
color: #FFF;
}
.leftpanel, .rightpanel{
height: 100%;
}
.leftpanel{
float: left;
width: 70%;
background: #CCC;
}
.rightpanel{
float: left;
width: 30%;
background: #666;
}
<div class="header">Header</div>
<div class="leftpanel">Left Panel</div>
<div class="rightpanel">Right Panel</div>
<div class="clearfix"></div>
Here's a modern solution using flexbox. Regardless of the height of the header the rest of the elements will stretch vertically to fill the remaining space. Here's the fiddle: http://jsfiddle.net/mggLY/1/.
HTML:
<div id = "wrapper">
<div class="header">Header</div>
<div>
<div class="leftpanel">Left Panel</div>
<div class="rightpanel">Right Panel</div>
</div>
</div>
CSS:
* {
margin: 0;
padding: 0;
border: 0;
}
html, body {
height: 100%;
}
.header{
background: #333;
padding: 15px;
text-align:center;
font-size: 18px;
font-family: sans-serif;
color: #fff;
}
.leftpanel{
background: #CCC;
}
.rightpanel{
background: #666;
}
#wrapper {
height: 100%;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
outline: 1px solid red;
}
#wrapper > .header {
-webkit-flex: 0 0 auto;
flex: 0 0 auto;
}
#wrapper > .header + div {
-webkit-flex: 1 1 auto;
flex: 1 1 auto;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
flex-direction: row;
}
#wrapper > .header + div > div:first-of-type {
-webkit-flex: 7 0 0;
flex: 7 0 0;
}
#wrapper > .header + div > div:last-of-type {
-webkit-flex: 3 0 0;
flex: 3 0 0;
}
You can use absolute positioning if you want to have it 100% height always. And then use scroll bars if required inside the leftpanel or the rightpanel.
Example: http://jsfiddle.net/G7unG/2/
html, body{
height: 100%;
margin: 0;
}
.header{
background: #333;
padding: 15px;
text-align:center;
font-size: 18px;
font-family: sans-serif;
color: #FFF;
height: 22px;
}
.leftpanel, .rightpanel{
top: 52px;
bottom: 0;
position: absolute;
}
.leftpanel{
width: 70%;
left: 0;
background: #CCC;
}
.rightpanel{
width: 30%;
right: 0;
background: #666;
}
Solution 2 - use fixed percentages for height: http://jsfiddle.net/G7unG/4/
html, body{
height: 100%;
margin: 0;
}
.header{
background: #333;
padding: 15px;
text-align:center;
font-size: 18px;
font-family: sans-serif;
color: #FFF;
height: 30%;
box-sizing: border-box;
}
.leftpanel, .rightpanel{
height: 70%;
float: left;
}
.leftpanel{
width: 70%;
left: 0;
background: #CCC;
}
.rightpanel{
width: 30%;
float: right;
background: #666;
}
You could use overflow: hidden; to protect the body to be scrollable.
according to your comment: http://jsfiddle.net/G7unG/9/
Like this: http://jsfiddle.net/G7unG/3/
html, body{
height: 100%;
margin: 0;
overflow:hidden;
}
You could use a "faux columns" type of structure -- adding the background color of your columns as "fixed" elements (they wont scroll with the page) behind your real columns.
<div id="left_faux"></div>
<div id="right_faux"></div>
div#left_faux {
position: fixed;
top:0;
left:0;
right:30%;
bottom:0;
background-color:#CCC;
}
div#right_faux {
position: fixed;
top:0;
left:70%;
right:0;
bottom:0;
background-color:#666;
}
.leftpanel{
float: left;
width: 70%;
}
.rightpanel{
float: left;
width: 30%;
}
This quick example is perhaps overly verbose, for demonstration purposes. I'm sure you can streamline the CSS so there aren't so many redundant definitions.
WORKING EXAMPLE
Use viewports. Browsers now support giving height a percentage of page height. Drop the 100 down to 80 if you've got a header taking up space.
div {
height:100vh;
}