How to Make Navigation Buttons Mobile-Responsive and Collapse in Order? - html

I have been trying for hours with different methods to get my navigation buttons to be mobile-responsive and collapse in a specified vertical order. I want the nav buttons to collapse in a vertical column below the two logos, once the screen size is shrunken (to around 500px). How do I fix my code to achieve this?
.container-fluid {
border: 1px solid #000000;
max-width: 1600px;
overflow: hidden;
}
.wrap {
/*background-color: yellow;*/
/*overflow: hidden;*/
}
.Logos {
width: 312px;
display: inline-block;
/*background-color: blue;*/
}
/*
.Logos img{
max-width: 300px;
height: auto;
}
*/
.nav.wrap.one {
display: inline-block;
/*background-color: green;*/
float: right;
margin-top: 25px;
}
ul.navigation {
font: bold 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
/*text-align center;*/
/*border: 1px solid green;*/
/*overflow: hidden;*/
}
.navigation li {
display: inline-block;
}
.navigation a {
background: #395870;
background: linear-gradient(#49708f, #293f50);
border-right: 1px solid rgba(0, 0, 0, .3);
color: #fff;
padding: 12px 20px;
text-decoration: none;
}
.navigation a:hover {
background: #314b0;
box-shadow: inset 0 0 10px 1px rgba(0, 0, 0, .3);
}
.navigation li:first-child a {
border-radius: 4px 0 0 4px;
}
.navigation li:last-child a {
border-right: 0;
border-radius: 0 4px 4px 0;
}
.row.two {
background-image: url(https://s1.postimg.org/5gvbly4hin/East_Hyde_Park_Chicago_aerial_0470.jpg);
background-position: absolute;
background-size: cover;
background-repeat: no-repeat;
max-width: 100%;
height: 550px;
margin: auto;
}
.floater.box {
background-color: rgba(255, 255, 255, .40);
border-radius: 10px;
/*opacity: .45;*/
max-width: 75%;
height: 200px;
position: absolute;
top: 50%;
left: 0;
right: 0;
margin: auto;
overflow: hidden;
}
.form-search {
margin: 0 auto;
text-align: center;
font: bold 13px sans-serif;
max-width: 325px;
position: relative;
}
.form-search input {
width: 230px;
box-sizing: border-box;
border-bottom-left-radius: 2px;
border-top-left-radius: 2px;
background-color: #ffffff;
box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.08);
padding: 14px 15px 14px 40px;
border: 1px solid #b6c3cd;
;
border-right: 0;
color: #4E565C;
outline: none;
margin-top: 70px;
-webkit-appearance: none;
}
.form-search button {
border-bottom-right-radius: 2px;
border-top-right-radius: 2px;
background-color: #6caee0;
box-shadow: 1px 2px 4px 0 rgba(0, 0, 0, 0.08);
color: #ffffff;
padding: 15px 22px;
margin-left: -4px;
cursor: pointer;
border: none;
outline: none;
}
.form-search i {
position: absolute;
top: 15px;
left: 20px;
font-size: 16px;
color: #80A3BD;
}
/* Placeholder color */
.form-search input::-webkit-input-placeholder {
color: #879097;
}
.form-search input::-moz-placeholder {
color: #879097;
opacity: 1;
}
.form-search input:-ms-input-placeholder {
color: #879097;
}
.nav.wrap.two {
display: inline-block;
text-align: center;
width: 100%;
margin-top: 10px;
}
<div class="container-fluid">
<!-- Top Box -->
<div class="wrap">
<div class="Logos">
<img src="https://s26.postimg.org/iqkxecqnd/Coldwell_Banker-_Logo_RS1.jpg" width="150" height="82" class="img-responsive" />
<img src="https://s26.postimg.org/iqkxecqnd/Coldwell_Banker-_Logo_RS1.jpg" width="150" height="82" class="img-responsive" /> </div>
<div class="nav wrap one">
<!--navigation buttons-->
<ul class="navigation">
<li id="NAV-ONE">LOG IN</li>
<li id="NAV-TWO">BUY A HOME</li>
<li id="NAV-THREE">SELL A HOME</li>
<li id="NAV-FOUR">CONTACT US</li>
</ul>
</div>
</div>
<!-- Middle Box -->
<div class="row two">
<div>
<div class="floater box">
<form class="form-search" method="get" action="#">
<input type="search" name="search" placeholder="I am looking for..">
<button type="submit">Search</button>
<i class="fa fa-search"></i>
</form>
</div>
</div>
</div>
</div>
<!-- Bottom Box -->
<div class="row three">
<div class="nav wrap two">
<!--navigation buttons-->
<ul class="navigation">
<li id="NAV-A">MY LISTINGS</li>
<li id="NAV-B">COMMUNITIES SERVED</li>
<li id="NAV-C">PROPERTIES</li>
</ul>
</div>
</div>
</div>
Here is a link to my CodePen: https://codepen.io/IDCoder/full/rGWeEE/

CSS is all about be natural order, natural position, natural styles... what I means is that your code isn't being natural, you can see here:
.navigation li {
display: inline-block;
}
.navigation a {
padding: 12px 20px;
}
I want to focus me in those properties because here we are saying:
You <a> element that are inside this man -> <li> (<li id="NAV-ONE">LOG IN</li>), yes you! You will be bigger even if you're inside him!
Well, in real life, we can't put bigger things into smaller spaces. What happens in real life and CSS is: smaller things into bigger things.
So if we make this change:
.navigation li {
display: inline-block;
padding: 12px 20px;
}
.navigation a {
/* We changed who is bigger than who */
}
It takes a natural order (because now the spaces where .navigation a will be is bigger than him). The final code is something like this (this will wrap when you use phone):
.navigation li {
display: inline-block;
padding: 12px 20px;
background: linear-gradient(#49708f, #293f50);
background: #395870;
border-right: 1px solid rgba(0, 0, 0, .3);
}
.navigation a {
color: #fff;
text-decoration: none;
}
More
I was playing and I found this cool way to wrap when screen is small, I think it's cool:
#media all and (max-width: 500px){
ul.navigation{
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
}
}
Also, remember that when you want to make responsive design you need meta:viewport into your html's head:
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

Related

How to make search bar responsive?

I want to make my html/css search bar responsive for example iphone 11.
Search button drops down after hovering over it, when i open it from my phone.
Here's the link: https://irinachikviladze.github.io/
How can I make it responsive using CSS?
<div class="search-box">
<input class="search-txt" type="text" name="" placeholder="Type to search">
<a class="search-btn" href="#">
<i class="fa-solid fa-magnifying-glass"></i>
</a>
</div>
Every HTML element has a default display value depending on what type of element it is. The default display value for most elements is block or inline.
So just overwrite the default display for your search box and set it to flex with flex-direction: row;
that's it.
body{
margin: 0;
padding: 0;
background:#e74c3c;
}
.search-box{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #34495e;
height: 40px;
border-radius: 40px;
padding: 10px;
display: flex;
flex-direction: row;
}
.search-box:hover > .search-txt{
width: 240px;
padding: 0 6px;
}
.search-box:hover > .search-btn{
background : white ;
}
.search-btn{
color: #e74c3c;
float: right;
width: 40px;
height: 40px;
border-radius: 50%;
background:#34495e;
display: flex;
justify-content: center;
align-items: center;
text-decoration: none;
overflow: hidden;
}
.search-txt{
border:none;
background: none;
outline: none;
float: left;
padding: 0;
color: white;
font-size: 16px;
transition: 0.4s;
line-height: 40px;
width: 0px;
}
/* responsive*/
#media only screen and (max-width: 828px){
.search-box:hover > .search-txt{
width: 125px;
}
}
<body>
<div class="search-box">
<input class="search-txt" type="text" name="" placeholder="Type to search">
<a class="search-btn" href="#">
<i class="fa-solid fa-magnifying-glass"></i>
</a>
</div>
</body>
Html element
<div class="Card">
<div class="CardInner">
<label>Search for your stack :)</label>
<div class="container">
<div class="Icon">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#657789" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
</div>
<div class="InputContainer">
<input placeholder="search here...."/>
</div>
</div>
</div>
</div>
CSS Element
#import url('https://fonts.googleapis.com/css?family=Orbitron&display=swap');
#import url('https://fonts.googleapis.com/css?family=Hind&display=swap');
* {
-webkit-font-smoothing: antialiased;
color: #acbdce;
}
:root {
--border-radius: 10px;
}
body, html {
background: #e2e9f4;
display: grid;
height: 100%;
grid-template: 1fr/100%;
place-items: center;
}
.Card {
padding: 1px;
border-radius: var(--border-radius);
background: linear-gradient(-67deg, rgba(#c8d8e7, .7), rgba(255,255,255,.8));
overflow: hidden;
box-shadow:
-2px -2px 6px rgba(#fff, .6),
2px 2px 12px #c8d8e7;
width: 380px;
}
.CardInner {
padding: 16px 16px;
background-color: #e2e9f4;
border-radius: var(--border-radius);
}
.container {
display: flex;
}
.Icon {
min-width: 46px;
min-height: 46px;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--border-radius);
margin-right: 12px;
box-shadow:
-2px -2px 6px rgba(#fff, .6),
2px 2px 12px #c8d8e7;
svg {
transform: translate(-1px, -1px);
}
}
label {
font-family: "Hind", sans-serif;
display: block;
color: #3c4b66;
margin-bottom: 12px;
background: linear-gradient(45deg, rgba(#6b7b8f, 1), #3c4b66);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.InputContainer {
width: 100%;
}
input {
background-color: #e3edf7;
padding: 16px 32px;
border: none;
display: block;
font-family: 'Orbitron', sans-serif;
font-weight: 600;
color: #a9b8c9;
-webkit-appearance: none;
transition: all 240ms ease-out;
width: 100%;
&::placeholder {
color: #6d7f8f;
}
&:focus {
outline: none;
color: #6d7f8f;
background-color: lighten(#e3edf7, 3%);
}
};
.InputContainer {
--top-shadow: inset 1px 1px 3px #c5d4e3, inset 2px 2px 6px #c5d4e3;
--bottom-shadow: inset -2px -2px 4px rgba(255,255,255, .7);
position: relative;
border-radius: var(--border-radius);
overflow: hidden;
&:before,
&:after {
left: 0;
top: 0;
display: block;
content: "";
pointer-events: none;
width: 100%;
height: 100%;
position: absolute;
}
&:before {
box-shadow: var(--bottom-shadow);
}
&:after {
box-shadow: var(--top-shadow);
}
}

How to avoid jumping html elements over each others

I'm new to CSS and web development and trying to build my own and first website. I've read a few articles related to displaying and positioning elements however I still unable to get elements positioned perfectly while resizing the browser window!.
What I am trying to accomplish is in the codepen link in the first comment below
https://codepen.io/letsimoo/pen/XWNGoGa
HTML CODE
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="UTF-8">
</head>
<body class="mainBody">
<header class="mainHeader">
<div class="headerStuff">
<div class="social-list">
<div class="fb">
FB
</div>
<div class="twitter">
Twitter
</div>
<div class="instagram">
Instagram
</div>
</div>
<ul class="navigation">
<li> <b>My Projects</b> </li>
<li> <b>Gallery</b> </li>
<li> <b> About </b> </li>
<li> <b>Contact</b> </li>
</ul>
<div class="logoDiv">
<h2>Logo</h2>
</div>
</div>
<div class="HeaderLine"></div> <!-- Header Separator Line -->
</header>
</body>
CSS CODE
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.mainBody {
background-color: gray;
background-size: cover;
background-repeat: no-repeat;
color: white;
margin: 0px 0px 0px 20px;
/*width: 100%;*/
}
.mainHeader {
height: 80px;
}
.headerStuff {
height: auto;
display: flex;
position: relative;
align-items: bottom;
vertical-align: baseline;
width: 100%;
}
.social-list {
display: inline-flex;
position: absolute;
margin-top: 20px;
left: -10px;
}
.social-list div {
margin-left: 12px;
}
.navigation {
position: absolute;
right: 175px;
text-align: right;
height: 30px;
padding: 0px;
margin: 0px;
margin-top: 30px;
display: flex;
}
.navigation li {
background-color: #22385b;
display: inline-block;
margin-left: 5px;
padding: 7px 5px 7px 5px;
border-radius: 7px;
font-size: 20px;
width: 90px;
color: white;
}
.navigation li:hover {
background-color: #446291;
}
.navigation li a {
color: white;
font-size: 14px;
font-family: "Chakra Petch", sans-serif;
text-align: center;
text-decoration: none;
display: block;
}
ul li .prayer-window {
background-color: rgba(237, 239, 242, 0.9);
margin-top: 20px;
width: 400px;
height: 400px;
position: relative;
z-index: 1;
opacity: 0;
box-shadow: 0px 0px 100px black;
transition: 1s opacity, 5s width, 5s height;
}
.prayer-time:hover {
color: hotpink;
}
.prayer-time:active ~ .prayer-window {
opacity: 1;
}
.logoDiv {
position: absolute;
right: 0px;
}
.logoDiv img {
width: 150px;
}
.HeaderLine {
box-sizing: border-box;
height: 2px;
margin-top: 68px;
margin-right: 175px;
text-align: center;
background-color: pink;
box-shadow: 2px 2px 4px black, 0 0 30px red, 0 0 5px darkblue;
}
Please have a look to my code in the above link and try to resize the browser window to the minimum size
What the problem I'm facing?
Definitely you've notices how is the navigation elements jumped over the social media dev after resizing the browser window
So how can avoid this ugly act from the headerStuff div!??
Also please help me to improve my question if there are something wrong in my description or in the mentioned tags
Your .navigation .sosial-list are positioned absolute. That means they are out of the order of the other elements and does not take space by the other content.
As absolute positioned element .navigation is allways relative to the next parent element which is not positioned static. In your project it is .header-stuff. At the same time the margin-top moves it down from the top edge of header-stuff ...
So, if the screen becomes narrow your .header-stuff becomes narrow also. And your navigation keeps still in place: 175px from right edge of .header stuff and 30pxmargin from top ... that make it layered above your socials.
If you want to keep your structure enlarge the margin-top for .navigation so the navigation has still place enough to move below the social information.
But if you are open to change your sturcture you don't need an absolute positioning. Use a structure with block elements so socials and navigations are still beneath and don't layer over each other.
Just easy DEMO code structure example to explain the idea:
// css structure DEMO
nav {
display: block;
}
ul {
/* align ul to right */
margin-right: 0;
margin-left: auto;
}
li {
/* align li's into a line */
display: inline-block;
}
header hr {
... style your subheader line ...
}
// html structure DEMO
<header>
<div class="top-header>
... your socials ...
</div>
<nav>
<ul>
<li></li>
...
</ul>
</nav>
<hr>
</header>
Here's your updated updated CSS:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.mainBody {
background-color: gray;
background-size: cover;
background-repeat: no-repeat;
color: white;
/* margin: 0px 0px 0px 20px; */
}
.headerStuff {
height: 80px;
display: flex;
position: relative;
vertical-align: baseline;
width: 100%;
justify-content: space-between;
align-items: center;
}
.social-list {
display: inline-flex;
}
.social-list div {
margin-left: 12px;
}
.navigation {
margin: 0;
}
.navigation li {
background-color: #22385b;
display: inline-block;
padding: 7px 5px 7px 5px;
border-radius: 7px;
font-size: 20px;
width: 90px;
color: white;
}
.navigation li:hover {
background-color: #446291;
}
.navigation li a {
color: white;
font-size: 14px;
font-family: 'Chakra Petch', sans-serif;
text-align: center;
text-decoration: none;
display: block;
}
ul li .prayer-window {
background-color: rgba(237, 239, 242, 0.9);
margin-top: 20px;
width: 400px;
height: 400px;
position: relative;
z-index: 1;
opacity: 0;
box-shadow: 0px 0px 100px black;
transition: 1s opacity, 5s width, 5s height;
}
.prayer-time:hover {
color: hotpink;
}
.prayer-time:active ~ .prayer-window {
opacity: 1;
}
.logoDiv h2 {
margin: 0;
}
.logoDiv img {
width: 150px;
}
.HeaderLine {
box-sizing: border-box;
height: 2px;
margin: 0 auto;
text-align: center;
background-color: pink;
box-shadow: 2px 2px 4px black, 0 0 30px red, 0 0 5px darkblue;
}
You can adjust css properties for specific screen sizes via media queries.
#media only screen and (max-width: 796px) {
//
}
PS. align-items:bottom is not really a thing. Probably you meant align-items:baseline

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>

Div keeps overflowing onto other elements when zoomed in

I'm trying to make a small web page with a search bar and an accounts menu (currently just a circle), but I've noticed, when I zoom in, or resize the page, the accounts menu overflows onto the search bar. I've tried changing from absolute positioning, to relative and adjusting the right: 30px accordingly, but this didn't work. I'm incredibly stuck, can anyone offer any advice/code?
body {
font-family: "PT-Sans", sans-serif;
background-color: #bbb;
}
input:focus {
outline: none;
}
.search-btn {
border: none;
padding: 12px;
font-size: 18px;
background-color: #009AFF;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
color: white;
width: 70px;
position: relative;
right: 5px;
cursor: pointer;
}
.input {
width: 500px;
padding: 11px;
font-size: 18px;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
border: 1px solid #777;
}
.search {
width: 600px;
position: absolute;
left: 200px;
top: 15px;
}
.logo a {
color: #009AFF;
font-size: 38px;
text-decoration: none;
}
.logo {
position: absolute;
left: 0;
top: 12px;
width: 200px;
}
.content {
width: 300px;
border: 2px solid #eee;
background-color: #fff;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
top: 65px;
padding: 5px;
}
#account-items {
display: none;
background-color: #fff;
width: 300px;
border: 2px solid #eee;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
position: absolute;
right: 0px;
top: 72px;
padding: 5px;
}
/*.accounts:hover #account-items {
display: inline;
}*/
#account-items a {
color: #009AFF;
text-decoration: none;
display: block;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
}
#account-items a:hover {
background-color: #eee;
}
.accounts {
cursor: pointer;
position: absolute;
right: 30px;
width: 66px;
height: 66px;
top: 4px;
padding: 0px;
border-radius: 100%;
}
.accounts .image {
background-image: url("/email/scripts/profile.png");
background-size: 100%;
background-repeat: no-repeat;
border: 1px solid #777;
border-radius: 100%;
width: 63px;
height: 63px;
}
a {
color: #009AFF;
text-decoration: none;
}
.js-is-hidden {
display: none;
}
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="body">
<div class="header">
<div class="logo">
<center>Unnamed</center>
</div>
<div class="search">
<form action="search.php" method="GET">
<input type="text" name="q" class="input" autocomplete="off" />
<button type="submit" class="search-btn">Go</button>
</form>
</div>
<div class="accounts">
<div class="image">
</div>
</div>
</div>
</div>
If you remove the absolute positioning and stick with the default relative, then use a display of inline-block (Read up on what it does here: https://www.w3schools.com/css/css_inline-block.asp) and use dynamic widths instead of static ones, you should get your desired result.
See the updated code below;
body {
font-family: "PT-Sans", sans-serif;
background-color: #bbb;
}
input:focus {
outline: none;
}
.search-btn {
border: none;
padding: 12px;
font-size: 18px;
background-color: #009AFF;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
color: white;
width: 70px;
position: relative;
right: 5px;
cursor: pointer;
}
.input {
width: calc(100% - 100px); /* CHANGED */
padding: 11px;
font-size: 18px;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
border: 1px solid #777;
}
.search {
max-width: 600px; /* CHANGED */
width: calc(100% - 300px); /* ADDED */
/* position: absolute; REMOVED */
/* left: 200px; REMOVED */
/*top: 15px; REMOVED */
display: inline-block; /* ADDED */
vertical-align: middle; /* ADDED */
}
.logo a {
color: #009AFF;
font-size: 38px;
text-decoration: none;
}
.logo {
/*position: absolute; //REMOVED */
/*left: 0; //REMOVED */
display: inline-block; /* ADDED */
vertical-align: middle; /* ADDED */
top: 12px;
width: 200px;
}
.content {
width: 300px;
border: 2px solid #eee;
background-color: #fff;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
top: 65px;
padding: 5px;
}
#account-items {
display: none;
background-color: #fff;
width: 300px;
border: 2px solid #eee;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
position: absolute;
right: 0px;
top: 72px;
padding: 5px;
}
/*.accounts:hover #account-items {
display: inline;
}*/
#account-items a {
color: #009AFF;
text-decoration: none;
display: block;
padding: 5px;
padding-left: 10px;
padding-right: 10px;
}
#account-items a:hover {
background-color: #eee;
}
.accounts {
cursor: pointer;
/* position: absolute; REMOVED */
/* right: 30px; REMOVED */
width: calc(100% - 809px); /* CHANGED */
height: 66px;
/* top: 4px; REMOVED */
padding: 0px;
border-radius: 100%;
display: inline-block; /* ADDED */
vertical-align: middle; /* ADDED */
text-align: right; /* ADDED */
}
.accounts .image {
background-image: url("/email/scripts/profile.png");
background-size: 100%;
background-repeat: no-repeat;
border: 1px solid #777;
border-radius: 100%;
width: 63px;
height: 63px;
display: inline-block; /* ADDED */
}
a {
color: #009AFF;
text-decoration: none;
}
.js-is-hidden {
display: none;
}
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="body">
<div class="header">
<div class="logo">
<center>Unnamed</center>
</div>
<div class="search">
<form action="search.php" method="GET">
<input type="text" name="q" class="input" autocomplete="off" />
<button type="submit" class="search-btn">Go</button>
</form>
</div>
<div class="accounts">
<div class="image">
</div>
</div>
</div>
</div>
try this
.header {
position: relative;
min-width: 900px;
}
https://jsfiddle.net/59ncte3m/1/
It will avoid the issue where your menu gets drawn on top of the search by making the header a positioned element, the menu absolute position will be relative to the header. giving it a min-width will make sure all elements fit within.
This is still not a good responsive design, as it should avoid pixel dimentions, but it is enough to fix the overflowing issue.

<div> doesn't take the full height of the page

I am trying to make the 4 colums with the class .column to be 100% of the page's height, but can't do it and I have no idea why.
body,
html {
margin: 0px;
padding: 0px;
font-family: Helvetica, sans-serif;
height: 100%;
width: 100%;
}
#header {
height: 40px;
width: 100%;
background-color: grey;
display: block;
}
#logo {
float: left;
font-size: 30px;
font-weight: bold;
padding-left: 15;
padding-top: 3px;
margin: 0 auto;
width: 10%;
}
#menu {
margin: 0 auto;
width: 50%;
height: 50%;
padding: 10px;
text-align: center;
}
#menu li {
display: inline;
border: 1px solid black;
border-radius: 15%;
background-color: red;
color: white;
}
#menu a {
text-decoration: none;
padding: 0 10px;
/* variable width */
}
a:hover {
background-color: black;
}
a:link,
a:visited,
a:active {
color: white;
}
.column {
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 25%;
height: 100%;
float: left;
-webkit-box-shadow: inset 0px 0px 0px 1px black;
-moz-box-shadow: inset 0px 0px 0px 1px black;
box-shadow: inset 0px 0px 0px 1px black;
}
.clear-div {
clear: both;
}
<div id="header">
<div id="logo">
CodePlayer
</div>
<div id="menu">
<li>HTML
</li>
<li>CSS
</li>
<li>JAVASCRIPT
</li>
<li>OUTPUT
</li>
</div>
<div class="clear-div">
</div>
<div class="column" id="html">
This column needs to be 100% of the page's height
</div>
<div class="column" id="css">
This column needs to be 100% of the page's height
</div>
<div class="column" id="javascript">
This column needs to be 100% of the page's height
</div>
<div class="column" id="output">
This column needs to be 100% of the page's height
</div>
</div>
I am a beginner and every advice on good web developement practices will be very valuable to me so if there's something that I could've have done better please let me know.
Add the following CSS to each of your divs,for which you want the height to be 100% of page height:
height: 100vh;
example:
<div class="column" id="html" style="height: 100vh;">
This column needs to be 100% of the page's height
</div>
percentages are with respect to parents and parent of column is .header which have 40px height
thats why you have 40px height for you column
the problem you are solving is a bit difficult but you can do this
.column {
height: 100vh;
}
see if that helps you
read about vh here https://developer.mozilla.org/en/docs/Web/CSS/length
You can use CSS Flexbox. You also need to change your HTML structure a little.
Wrap all your 4 columns inside a parent div (in my case it is named as .column-holder) and give it a height using CSS calc() function. Like:
.column-holder {
display: flex;
height: calc(100vh - 45px); /* Total Viewport Height - Header Height */
}
Have a look at the working snippet below (use full screen mode):
body, html {
margin: 0px;
padding: 0px;
font-family: Helvetica, sans-serif;
height: 100%;
width: 100%;
}
#header {
height: 45px;
width: 100%;
background-color: grey;
display: block;
}
#logo {
float:left;
font-size: 30px;
font-weight: bold;
padding-left: 15;
padding-top: 3px;
margin: 0 auto;
width: 10%;
}
#menu {
margin: 0 auto;
width: 50%;
padding: 10px;
text-align:center;
}
#menu li {
display:inline;
border: 1px solid black;
border-radius: 15%;
background-color: red;
color: white;
}
#menu a {
text-decoration:none;
padding:0 10px; /* variable width */
}
a:hover {
background-color: black;
}
a:link, a:visited, a:active {
color: white;
}
.column {
top: 0;
left:0;
margin: 0;
padding: 0;
width: 25%;
height: 100%;
float: left;
-webkit-box-shadow:inset 0px 0px 0px 1px black;
-moz-box-shadow:inset 0px 0px 0px 1px black;
box-shadow:inset 0px 0px 0px 1px black;
}
.clear-div {
clear:both;
}
.column-holder {
display: flex;
height: calc(100vh - 45px);
}
<html>
<head>
<title>CodePlayer</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="header">
<div id="logo">
CodePlayer
</div>
<div id="menu">
<li>HTML</li>
<li>CSS</li>
<li>JAVASCRIPT</li>
<li>OUTPUT</li>
</div>
<div class="clear-div"></div>
</div>
<div class="column-holder">
<div class="column" id="html">
This column needs to be 100% of the page's height
</div>
<div class="column" id="css">
This column needs to be 100% of the page's height
</div>
<div class="column" id="javascript">
This column needs to be 100% of the page's height
</div>
<div class="column" id="output">
This column needs to be 100% of the page's height
</div>
</div>
</body>
</html>
Hope this helps!
Your HTML structure is Wrong . if you wish to make Column take full page Height you will need to put columns out of header which is set to height:40px;
body,
html {
margin: 0px;
padding: 0px;
font-family: Helvetica, sans-serif;
height: 100%;
width: 100%;
}
#header {
height: 40px;
width: 100%;
background-color: grey;
display: block;
}
#logo {
float: left;
font-size: 30px;
font-weight: bold;
padding-left: 15;
padding-top: 3px;
margin: 0 auto;
width: 10%;
}
#menu {
margin: 0 auto;
width: 50%;
height: 50%;
padding: 10px;
text-align: center;
}
#menu li {
display: inline;
border: 1px solid black;
border-radius: 15%;
background-color: red;
color: white;
}
#menu a {
text-decoration: none;
padding: 0 10px;
/* variable width */
}
a:hover {
background-color: black;
}
a:link,
a:visited,
a:active {
color: white;
}
.column {
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 25%;
height: 100%;
float: left;
-webkit-box-shadow: inset 0px 0px 0px 1px black;
-moz-box-shadow: inset 0px 0px 0px 1px black;
box-shadow: inset 0px 0px 0px 1px black;
}
.clear-div {
clear: both;
}
<div id="header">
<div id="logo">
CodePlayer
</div>
<div id="menu">
<li>HTML
</li>
<li>CSS
</li>
<li>JAVASCRIPT
</li>
<li>OUTPUT
</li>
</div>
</div>
<div class="clear-div">
</div>
<div class="column" id="html">
This column needs to be 100% of the page's height
</div>
<div class="column" id="css">
This column needs to be 100% of the page's heigh
</div>
<div class="column" id="javascript">
This column needs to be 100% of the page's height
</div>
<div class="column" id="output">
This column needs to be 100% of the page's height
</div>
You can use HEIGHT calc Tricks to get the height for column class. For this calc you need to header height and close the header div before the clear div and after the menu close div. Then you just write the column height something like this height: calc(100% - 40px) . 40px is your header height.
Additional suggestions: remove the width and height you set for menu. So you will get better view on small screen. Also you don't need the column top:0 left:0; you can use this when you use position element. If you have any Question ask me in comment
body,
html {
margin: 0px;
padding: 0px;
font-family: Helvetica, sans-serif;
height: 100%;
width: 100%;
}
#header {
height: 40px;
width: 100%;
background-color: grey;
display: block;
}
#logo {
float: left;
font-size: 30px;
font-weight: bold;
padding-left: 15;
padding-top: 3px;
margin: 0 auto;
width: 10%;
}
#menu {
margin: 0 auto;
padding: 10px;
text-align: center;
}
#menu li {
display: inline;
border: 1px solid black;
border-radius: 15%;
background-color: red;
color: white;
}
#menu a {
text-decoration: none;
padding: 0 10px;
/* variable width */
}
a:hover {
background-color: black;
}
a:link,
a:visited,
a:active {
color: white;
}
.column {
margin: 0;
padding: 0;
width: 25%;
height: calc(100% - 40px);
float:left;
-webkit-box-shadow: inset 0px 0px 0px 1px black;
-moz-box-shadow: inset 0px 0px 0px 1px black;
box-shadow: inset 0px 0px 0px 1px black;
}
.clear-div {
clear: both;
}
<div id="header" class="clear-div">
<div id="logo">
CodePlayer
</div>
<div id="menu">
<li>HTML
</li>
<li>CSS
</li>
<li>JAVASCRIPT
</li>
<li>OUTPUT
</li>
</div>
</div>
<div class="clear-div"></div>
<div class="column" id="html">
This column needs to be 100% of the page's height
</div>
<div class="column" id="css">
This column needs to be 100% of the page's height
</div>
<div class="column" id="javascript">
This column needs to be 100% of the page's height
</div>
<div class="column" id="output">
This column needs to be 100% of the page's height
</div>
EDITED ANSWER AFTER COMMENT (html structure in question was wrong)
You would probably want to restrict the overall height to 100%, so use height: calc(100% - 40px); on .column as in the following snippet:
body,
html {
margin: 0px;
padding: 0px;
font-family: Helvetica, sans-serif;
height: 100%;
width: 100%;
}
#header {
height: 40px;
width: 100%;
height: 40px;
background-color: grey;
display: block;
}
#logo {
float: left;
font-size: 30px;
font-weight: bold;
padding-left: 15;
padding-top: 3px;
margin: 0 auto;
width: 10%;
}
#menu {
margin: 0 auto;
width: 50%;
padding: 10px;
text-align: center;
}
#menu li {
display: inline;
border: 1px solid black;
border-radius: 15%;
background-color: red;
color: white;
}
#menu a {
text-decoration: none;
padding: 0 10px;
/* variable width */
}
a:hover {
background-color: black;
}
a:link,
a:visited,
a:active {
color: white;
}
.column {
margin: 0;
padding: 0;
width: 25%;
height: calc(100% - 40px);
float: left;
-webkit-box-shadow: inset 0px 0px 0px 1px black;
-moz-box-shadow: inset 0px 0px 0px 1px black;
box-shadow: inset 0px 0px 0px 1px black;
}
.clear-div {
clear: both;
}
<div id="header">
<div id="logo">
CodePlayer
</div>
<div id="menu">
<li>HTML
</li>
<li>CSS
</li>
<li>JAVASCRIPT
</li>
<li>OUTPUT
</li>
</div>
<div class="clear-div">
</div>
</div>
<div class="column" id="html">
This column needs to be 100% of the page's height
</div>
<div class="column" id="css">
This column needs to be 100% of the page's height
</div>
<div class="column" id="javascript">
This column needs to be 100% of the page's height
</div>
<div class="column" id="output">
This column needs to be 100% of the page's height
</div>
You can use a flex-layout and achieve this with min-height property. For more info on flex layout read this ->https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.fill-height-or-more {
min-height: 100%;
display: flex;
flex-direction: row;
> div {
border-style: solid;
display: flex;
flex-direction: column;
}
}
http://codepen.io/anon/pen/OboJdP