turn div into link on mobile screen size - html

I have a navbar with some links. When I open the page with a small screen size a mobile menu replaces the default navbar.
When I open this mobile menu I want to turn the parent divs of the links into links too. Means when I click on this div I want to call the links route.
I provide a full working example of the mobile menu
$(document).ready(() => {
$("#btnMenu").click(() => {
toggleMenu();
});
$(".navbarLink").click(() => {
if ($("#navbarItems").hasClass("activeNavbar")) {
toggleMenu();
}
});
});
function toggleMenu() {
$("#navbarItems").toggleClass("activeNavbar");
toggleMenuBtn();
}
function toggleMenuBtn() {
$("#btnMenu").toggleClass("activeMenuBtn");
}
.link {
text-decoration: none;
}
body {
margin: 0;
}
#navbar {
height: 60px;
top: 0;
padding-left: 200px;
padding-right: 200px;
position: sticky;
background: #1e222a;
}
#navbarItems {
height: 100%;
display: flex;
align-items: center;
}
#logoLink {
display: flex;
align-items: center;
}
#navbarItems .navbarItemContainer:not(:first-child) {
margin-left: 30px;
}
.navbarItemContainer {
background: #1e222a;
}
.navbarLink {
font-weight: bold;
color: #ffffff;
}
.navbarLink:hover {
color: #3abcf3;
}
#btnMenuContainer {
height: 100%;
display: none;
}
#btnMenu {
cursor: pointer;
}
.menuBtnBar {
width: 35px;
height: 5px;
margin: 6px 0;
background-color: #ffffff;
transition: 0.4s;
}
.activeMenuBtn #barTop {
transform: rotate(-45deg) translate(-9px, 6px);
}
.activeMenuBtn #barCenter {
opacity: 0;
}
.activeMenuBtn #barBottom {
transform: rotate(45deg) translate(-8px, -8px);
}
#media(max-width: 1200px) {
#navbar {
padding-left: 150px;
padding-right: 150px;
}
}
#media(max-width: 1100px) {
#navbar {
padding-left: 0;
padding-right: 0;
}
#navbarItems .navbarItemContainer:not(:first-child) {
margin-left: 0;
}
#navbarItems .navbarItemContainer:not(:last-child) {
border-bottom: 1px solid #676767;
}
#btnMenuContainer {
display: flex;
align-items: center;
}
#btnMenu {
margin-left: 20px;
}
#navbarItems {
margin-left: 0;
display: none;
}
#logoLink {
display: inline-block;
}
.navbarItem {
width: 100%;
text-align: center;
padding: 30px 0;
}
#navbarItems.activeNavbar {
display: block;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="navbar">
<div id="btnMenuContainer">
<div id="btnMenu">
<div id="barTop" class="menuBtnBar"></div>
<div id="barCenter" class="menuBtnBar"></div>
<div id="barBottom" class="menuBtnBar"></div>
</div>
</div>
<div id="navbarItems">
<div class="navbarItemContainer">
<div class="navbarItem">
<a id="logoLink" class="link navbarLink" href="#">
<img class="img" src="http://icons.iconarchive.com/icons/ph03nyx/super-mario/128/Hat-Mario-icon.png">
</a>
</div>
</div>
<div class="navbarItemContainer">
<div class="navbarItem">
<a class="link navbarLink" href="#sectionTwo">
Link 2
</a>
</div>
</div>
<div class="navbarItemContainer">
<div class="navbarItem">
<a class="link navbarLink" href="#sectionThree">
Link 3
</a>
</div>
</div>
</div>
</div>
How can I expand the link in the center on its whole parent div when opening the mobile menu?

try simply replacing your mobile styles for
.navbarItem {
width: 100%;
text-align: center;
padding: 30px 0;
}
with
#navbarItems:first-child .navbarItem, .navbarLink {
width: 100%;
text-align: center;
padding: 30px 0;
}
this should apply those styles to the logo item as it currently does, and then apply the padding and width to the links themselves for the actual navbar links.

Moving the div into the <A> tag makes the whole space clickable on mobile.
<a class="link navbarLink" href="#sectionTwo">
<div class="navbarItem">
Link 2
</div>
</a>

Related

Body content covers navbar drop down

Im creating a responsive website so that when the website is used as a mobile they can check the box which will display a drop down menu of the navbar. This is currently working except when the box is clicked the drop down nav bar goes behind my banner content. Does anyone know why this is? Very stuck currently.
HTML CODE:
<div class = "wrapper">
<header>
<div class = "header">
<h2 class = "logo">Haukai Restaurant</h2>
<input type = "checkbox" id = "chk">
<label for = "chk" class = "show-menu-btn">
<i class = "fas fa-ellipsis-h"></i>
</label>
<ul class = "menu-nav">
Home
Menu
Reservations
Hours
Contact
<label for = "chk" class = "hide-menu-btn">
<i class = "fas fa-times"></i>
</label>
</ul>
<section class="banner">
<div class="img-container">
<div class="inner-container">
<h1>Haukai Restaurant</h1>
<h2>Bringing Maori culture and kai to you</h2>
<a class="btn" href="menu.html">Menu</a>
<a class="btn" href="reservations.html">Reservations</a>
<a class="btn" href="privacy.html">Privacy</a>
<div class = "about-us">
<br> <br> <br> <br> <br>
<div class = "about-us-content">
<h2>About us</h2>
<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
</p>
</div>
</div>
</div>
</div>
</section>
</div>
</body>
CSS CODE:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
/* Home Page */
body {
background: #000;
min-height: 200vh;
position: relative;
}
.wrapper {
width: 100%;
}
/* Header */
.header {
height: 100px;
background: #000;
padding: 0 20px;
color: #fff;
}
.logo {
line-height: 100px;
float: left;
text-transform: uppercase;
}
.menu-nav {
float: right;
line-height: 100px;
}
.menu-nav a {
color: #fff;
text-transform: uppercase;
text-decoration: none;
padding: 0 10px;
transition: 0.4s;
}
.show-menu-btn,
.hide-menu-btn {
transition: 0.4s;
font-size: 30px;
cursor: pointer;
display: none;
}
.show-menu-btn {
float: right;
}
.show-menu-btn i {
line-height: 100px;
}
.menu a:hover,
.show-menu-btn:hover,
.hide-menu-btn:hover {
color: #feca1d;
}
#chk {
position: absolute;
visibility: hidden;
z-index: -1111;
}
.menu-content {
padding: 0 20px;
}
.banner {
position: relative;
width: 100%;
height: 100vh;
background: url(insiderest.jpg);
background-size: cover;
}
#media screen and (max-width: 600px) {
.show-menu-btn,
.hide-menu-btn {
display: block;
}
.menu-nav {
position: fixed;
width: 100%;
height: 100vh;
background: #333;
right: -100%;
top: 0;
text-align: center;
padding: 80px 0;
line-height: normal;
transition: 0.7s;
}
.menu-nav a {
display: block;
padding: 20px;
}
.hide-menu-btn {
position: absolute;
top: 40px;
right: 40px;
}
#chk:checked ~ .menu-nav {
right: 0;
}
}
Your using media queries. You have one .menu-nav above the query and one inside of the media query #media screen and (max-width: 600px) {
z-indexes are only counted if the position is fixed, relative, absolute, sticky, etc. The first css class will dismiss the z-index because it has no position property. Replacing the float with position relative could work.
.menu-nav {
float: right;
line-height: 100px;
}
or, alternatively it should work to add the z-index to the media query .menu-nav class.
#media screen and (max-width: 600px) {
.menu-nav {
position: fixed;
z-index:2;
width: 100%;
height: 100vh;
background: #333;
right: -100%;
top: 0;
text-align: center;
padding: 80px 0;
line-height: normal;
transition: 0.7s;
}
}
I think it will work.
.menu-nav {
z-index: 1000;
}

Icons with Text located beside it

I am trying to use custom icons (3 of them) be located in their own cell in a table with the cell directly beside them being the text that goes along with them. I want the text to be close to the image. The image is to enlarge slightly when hovered over as it will also be a hyperlink. I can't seem to get code to ensure it is aligned center of the page and formatted correctly. Also the scale isn't working when I set it to enlarge on hover.
I have already tried multiple codes but none seem to be working within sharepoint.
.demo-problem,
.demo-solution {
font-size: 1.5em;
}
body {
padding: 30px;
}
.outer-div {
padding: 30px;
}
.inner-div {
margin: 0 auto;
width: 100%;
height: 100%;
}
.demo-solution--flexbox {
display: flex;
align-items: center;
}
img3 {
width: 25%;
height: auto;
display: block;
}
img3:hover {
transform: scale(3);
}
a:hover {
text-decoration: none;
color: black;
font-weight: bold;
}
<div class="demo-solution demo-solution--flexbox">
<div class="outer-div">
<img src="https://ontariopowergeneration.sharepoint.com/:i:/r/sites/powernet/support/res/PublishingImages/Pages/Real%20Estate/Icons/ICON_Real-Estate.png?csf=1&e=acVaiZ" alt="" class="img3">
</div>
<div class="inner-div"><span><blockquote>Corporate Real Estate & Workplace</blockquote></span></div>
</div>
The img3 is a class so u need to specify
.img3 whereas you have done just img3.
If you change it to .img3 scale works
.demo-problem,
.demo-solution {
font-size: 1.5em;
}
body {
padding: 30px;
}
.outer-div {
padding: 30px;
}
.inner-div {
margin: 0 auto;
width: 100%;
height: 100%;
}
.demo-solution--flexbox {
display: flex;
align-items: center;
}
.img3 {
width: 25%;
height: auto;
display: block;
}
.img3:hover {
transform: scale(3);
}
a:hover {
text-decoration: none;
color: black;
font-weight: bold;
}
<div class="demo-solution demo-solution--flexbox">
<div class="outer-div">
<img src="https://www.slipperelectrical.co.nz/wp-content/uploads/2015/12/dummy-image.jpg" alt="" class="img3">
</div>
<div class="inner-div"><span><blockquote>Corporate Real Estate & Workplace</blockquote></span></div>
</div>

how can I align these arrows vertically center?

I have a bourgeoning website http://rushycreekfarm.com.au/ with a central image that has two arrows either side to change slides. However, I'm not sure how to align the arrows vertically centre. The arrows have a container (in red) and the entire slideshow has a container (in blue). I would like the arrows to be half way up the blue container.
<!DOCTYPE html>
<html>
<head>
<title>Rushy Creek Farm</title>
<link href="style.css" type="text/css" rel="stylesheet">
</head>
<body>
<div id="details" class="header">765 Brockman Highway | 0438695434 |
tracyrob#wallworks.com.au
</div>
<div class="title">
<h1>RUSHY CREEK FARM</h1>
</div>
<div class="nav-bar">
HOME
ABOUT
<a href="https://www.stayz.com.au/accommodation/wa/south-
west/augusta/9189326">BOOK</a>
CONTACT
</div>
<div class="slideshow">
<div class="arrow-container">
<img id="arrow-left" class="arrow" src="./arrow-left.jpg">
</div>
<img id="main-image" src="./images/droneshot.jpg">
<div class="arrow-container">
<img id="arrow-right" class="arrow" src="./arrow-right.jpg">
</div>
</div>
<script src="script.js" type="text/javascript"></script>
</body>
<html>
And here is the CSS:
.header {
font-family: garamond;
text-align: center;
height: 10px;
border-bottom: 1px solid rgb(220,220,220);
padding-bottom: 12px;
}
.title {
text-align: center;
letter-spacing: 2px;
}
body {
font-family: Georgia;
}
.nav-bar {
background-color: skyblue;
}
.nav-bar a {
cursor: pointer;
display: inline-block;
background-color: skyblue;
color: white;
text-decoration: none;
font-size: 25px;
padding: 16px 40px;
border-radius: 3px;
transition: 0.3s;
letter-spacing: 2px;
}
.nav-bar a:hover {
background-color: rgb(57,97,140);
}
.slideshow {
background-color: blue;
text-align: center;*/
}
#main-image {
display:inline-block;
width: 60%;
}
.arrow {
cursor: pointer;
display: inline-block;
background-color: gray;
transition: 0.3s;
}
#arrow-left {
float: right;
}
#arrow-right {
float: left;
}
.arrow-container {
background-color: red;
display: inline-block;
width: 19%;
}
.arrow:hover {
background-color: rgb(220,220,220);
}
You can use flexbox:
.slideshow {
display: flex;
align-items: center;
}
Since flexbox removes the space between the elements that display: inline-block adds, you can now use width: 20% for the arrow containers:
.arrow-container {
width: 20%;
}
You can use absolute positioning and a translation transform.
.slideshow {
background-color: blue;
position: relative; // new
text-align: center;
}
.arrow-container {
background-color: red;
display: inline-block;
position: absolute; // new
top: 50%; // new
transform: translateY(-50%); // new
width: 19%;
}
.arrow-container.left {
left: 0; // new
}
.arrow-container.right {
right: 0; // new
}
You can use absolute positioning to position the arrows vertically:
.arrow-container {
position: absolute;
top: 50%;
transform: translateY(-50%);
}

Text and image half half, aligned next to each other

Example: https://gyazo.com/8d717ee1a21ed49033deece5a105239d (Photoshop).
Black = Slider, Grey = Image, White = Textarea with changeable background color.
I also want to make this responsive to phone devices and such, but that doesn't work either, if I just take an image that is half's the page widht and a height.
I am trying to align an image to the left and the text exactly in a container next to it with the background of the text changeable. I tried using the properties left: ; Right: ;, margins and paddings but that doesn't work.
The image and text should be underneath the div called A3L_Slogan and A3L_Catchphrase. I hope anyone can point me out in the good direction.
Below you can find a JS fiddle without any of that code in it
body {
width: 100%;
margin: 0;
font-family: 'open sans', sans-serif;
zoom: 1;
overflow-x: hidden;
}
header {
padding: 20px 0;
background-color: #ffffff;
box-shadow: 0 4px 6px rgba(0,0,0,.2);
}
.container {
padding: 0 20px;
margin: 0 auto;
}
.logo-box {
float: left;
margin-right: 20px;
}
.logo-box a {
outline: none;
display: block;
}
.logo-box img {display: block;}
nav {
overflow: hidden;
}
ul {
list-style: none;
margin: 0;
padding: 0px 10px 0px 0px;
float: right;
}
nav li {
display: inline-block;
margin-left: 25px;
height: 70px;
line-height: 70px;
transition: .5s linear;
}
nav a {
text-decoration: none;
display: block;
position: relative;
color: #868686;
text-transform: uppercase;
}
nav a:after {
content: "";
width: 0;
height: 2px;
position: absolute;
left: 0;
bottom: 15px;
background: #868686;
transition: width .5s linear;
}
nav a:hover:after {width: 100%;}
#media screen and (max-width: 660px) {
header {text-align: center;}
.logo-box {
float: none;
display: inline-block;
margin: 0 0 16px 0;
}
ul {float: none;}
nav li:first-of-type {margin-left: 0;}
}
#media screen and (max-width: 550px) {
nav {overflow: visible;}
nav li {
display: block;
margin: 0;
height: 40px;
line-height: 40px;
}
nav li:hover {background: rgba(0,0,0,.1);}
nav a:after {content: none;}
}
.A3L_Slogan, .slideshow{
position: relative;
}
.slideshow{
height: 600px;
}
.fadein img {
width: 100%;
position: absolute;
max-height: 600px;
left:0;
top:0;
}
.A3L_Slogan {
margin-top: 20px;
margin-bottom: 20px;
text-align: center;
}
.slogan_title {
font-size: 46px;
font-weight: 700;
padding: 15px;
text-transform: uppercase;
}
.slogan_catchphrase {
font-size: 30px;
font-weight: 500;
text-transform: uppercase;
}
#media only screen and (max-width: 640px) {
.slideshow{
height: 300px;
}
.fadein img {
width: 100%;
position: absolute;
max-height: 300px;
left:0;
top:0;
}
}
#media only screen and (max-width: 600px) {
.slideshow{
height: 200px;
}
.fadein img {
width: 100%;
position: absolute;
max-height: 200px;
left:0;
top:0;
}
}
#media only screen and (max-width: 480px) {
.logo {
max-width: 270px;
}
}
}
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function () {
$('.fadein img:gt(0)').hide();
setInterval(function () {
$('.fadein :first-child').fadeOut().next('img').fadeIn().end().appendTo('.fadein');
}, 4000);
});
</script>
</head>
<body>
<header>
<div class="container">
<div class="logo-box">
<a href="/">
<img class="logo" src="images/logo.png">
</a>
</div>
<nav>
<ul>
<li>Forums</li>
<li>Rules</li>
<li>Monetization</li>
<li>Sign-up</li>
<li>Staff</li>
</ul>
</nav>
</div>
</header>
<div class="slideshow">
<div class="fadein">
<img src="http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-159465.jpg" alt="">
<img src="http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-160434.png" alt="">
<img src="http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-150988.jpg" alt="">
</div>
</div>
<div class="A3L_Slogan">
<div class="slogan_title">
Hardcore Roleplay Community
</div>
<div class="slogan_catchphrase">
The next level roleplay experience
</div>
</div>
</body>
</html>
Put your image and text in a container such as:
<div class="container-row">
<div class="hero-image">
<img src="http://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-159465.jpg" alt="">
</div>
<div class="A3L_Slogan">
<div class="slogan_title">
Hardcore Roleplay Community
</div>
<div class="slogan_catchphrase">
The next level roleplay experience
</div>
</div>
</div>
and you can use flexbox to align the items
.container-row{
display: flex;
}
.container-row .hero-image{
flex: 1;
}
.container-row .A3L_Slogan {
flex: 2;
}

Unable to make a circle with border-radius and align it vertically with next element

Here is the outcome
What I want to achieve are
A gray circle surrounding the '<' with the letter in the center
It and 'untitled' aligns vertically to the center
However despite setting the width and height to the same size, the 'circle' still ends up in an oval shape.
The use of flex's align-items: center; also fails to achieve the alignment.
How can I fix the css? Here is a link to the sample code
html
<div class='flex-container'>
<div class='arrow-container'>
<a class='btn-icon' href='#'>
<span class='square-btn icon icon-back'></span>
</a>
</div>
<div class=title>
<a href='#'>Untitled
</a>
</div>
</div>
css
.flex-container {
display: flex;
align-items: center;
}
.icon {
font-size: 50px;
}
.icon-back::before {
content: '<';
}
.title {
margin-left: 5px;
font-size: 50px;
}
.square-btn {
height: 50px;
width: 50px;
}
.btn-icon {
padding: 5px;
border-radius: 50%;
background-color: gray;
text-decoration: none;
}
This seems to work. No changes to HTML.
.flex-container {
display: flex;
align-items: center;
}
.icon {
font-size: 50px;
}
.icon-back::before {
content: '<';
}
.title {
margin-left: 5px;
font-size: 50px;
}
.square-btn {
height: 50px;
width: 50px;
border-radius: 50%; /* new */
background-color: gray; /* new */
display: flex; /* new */
align-items: center; /* new; align arrow vertically */
justify-content: center; /* new; align arrow horizontally */
}
.btn-icon {
/* padding: 5px; <-- remove */
/* border-radius: 50%; <-- remove */
/* background-color: gray; <-- remove */
text-decoration: none;
}
<div class='flex-container'>
<div class='arrow-container'>
<a class='btn-icon' href='#'>
<span class='square-btn icon icon-back'></span>
</a>
</div>
<div class=title>
<a href='#'>Untitled
</a>
</div>
</div>
jsFiddle
This can be done with a single html element and pseude-elements. One neat advantage of making everything depend on the font-size is, that the icon scales proportionally with the font size of the link.
.link {
font-size: 50px;
margin-left: 1.1em;
}
.icon {
position: relative;
}
.icon-back::before {
content: '<';
position: absolute;
left: -.9em;
display: inline-block;
z-index: 2;
}
.icon-back::after {
content: '';
border-radius: 50%;
background-color: gray;
width: 1em;
height: 1em;
position: absolute;
top: 50%;
left: -1.1em;
/* Use translateX() and translateY()
if you care about old browsers */
transform: translate3d(0, -45%, 0);
}
<a class="link icon icon-back" href="#">Untitled</a>
Grouping classes makes things harder, also, use unicode in css content when it's not alpha-numerical text, try this:
<div class="flex-container">
<div class="arrow-container">
<a class="btn-icon" href="#">
<span class="icon-back"></span>
</a>
</div>
<div class="title">
<a href="#">Untitled
</a>
</div>
</div>
<style type="text/css">
.flex-container {
display: flex;
align-items: center;
}
.btn-icon {
font-size: 50px;
text-decoration: none;
}
.icon-back::before {
content: "\003c";
border-radius: 50%;
background-color: gray;
font-size: 40px;
height:40px;
width:40px;
vertical-align:middle;
display:inline-block;
margin-bottom:5px;
text-align:center;
}
.title {
margin-left: 5px;
font-size: 50px;
}
</style>