Please Some one Tell me how do i make this Modal Responsive.
This is the Html code For the Modal and its Content.
<div class="modal-content">
<span class="close">×</span>
<br/>
<div class = "modal_img">
<img id = "modal_pic" src="resources/images/round/aqua.jpg">
</div>
<div class = "modal_desc">
<h3>PRODUCT DESCRIPTION</h3>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
<div class="colors">
</div>
</div>
And This is the CSS for The Modal Element and its Content.
Can Someone please tell me how do I alter these to make it Responsive
Thank You Very Much for your help:
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
background-color: #fefefe;
margin: auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
}
/* The Close Button */
.close {
color: red;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover, .close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal_img{
margin:20px 40px;
width: 25%;
height: 430px;
display: inline-block;
}
#modal_pic{
margin:auto;
width: 100%;
height: 100%;
border: solid black;
}
.modal_desc{
width: 30%;
float: right;
margin-top: 20px;
margin-right: 20%;
display: inline-block;
}
How do I make it Responsive.
In your css document use some of these:
#media all and (max-width: 900px) {
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
Also use firefox (F12) has a nice Responsive Design view so you can test out your website easier
with the #media tags you have to think what it will look like on a mobile first and then use the #media tags to change how the site looks for bigger desplay devices
Related
I am Mac OS user and I found something weird.
This is the example code.
header{
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 58px;
background-color: #3d3d3d;
}
.wrapper{
max-width: 500px;
border: 1px solid red;
box-sizing: border-box;
height: 100%;
margin: auto; /* to make align center */
}
main {
max-width: 500px; /* same as .wrapper */
width: 100%;
height: 120vh; /* to make scrollbar */
margin: auto; /* to make align center */
padding-top: 58px;
border: 1px solid blue;
box-sizing: border-box;
}
<header>
<div class="wrapper">123</div>
</header>
<main>main</main>
You can see the gap between header and main.
But I go to System Preferences of Mac, click the General and change Show scroll bars option to When scrolling, it shows well like below picture.
How can I align the layout of header and main even if I set the Show scroll bars option always?
List item
Consider the following code. I have placed comments in the CSS
* {
/* all elements are now border box */
box-sizing: border-box;
}
header {
position: fixed;
top: 0;
left: 0;
/* changed from 100vw to 100% */
width: 100%;
height: 58px;
background-color: #3d3d3d;
/* aligns wrapper element to the center of the header no matter its contents height */
display: flex;
align-items: center;
justify-content: center;
}
.wrapper {
/* use width or min width because contents may not be 500px wide */
min-width: 500px;
border: 1px solid red;
}
main {
/* use max width because you dont want your main element wider than 500px */
max-width: 500px;
/* to make scrollbar */
height: 120vh;
/* 0 margin on top and bottom and auto for left and right */
margin: 0 auto;
padding-top: 58px;
border: 1px solid blue;
}
<header>
<div class="wrapper">123</div>
</header>
<main>main</main>
I need to create an image lightbox. I basically started from this example from w3school, https://www.w3schools.com/howto/howto_js_lightbox.asp
However, it doesn't work for portrait oriented images. Eg. a landscape image is 1200x800 and a portrait can be 800x1200.
I need the images to resize responsive and work for both horizontal and vertical images.
It needs to work for all modern browsers, ios, android and also IE11.
you'll see I've added "max-width: 1200px;" to lightbox-content, which does the trick for horizontal images... but since a vertical image is 800 wide, it enlarges and the height exceeds.
<div class="lightbox">
<span class="close" onclick="closeLightbox()">×</span>
<div class="lightboxTitle">My Title</div>
<div class="lightbox-content">
<div class="slide"><img src="img1.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<div class="slide"><img src="img2.jpg"></div>
<!-- Next/previous controls -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
</div>
/* The Modal (background) */
.lightbox {
display: none;
position: fixed;
z-index: 99999999;
padding-top: 60px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
}
/* Modal Content */
.lightbox-content {
position: relative;
margin: auto;
padding: 0;
width: 100%;
max-width: 1200px;
}
.lightboxTitle {
position: absolute;
top: 20px;
left: 25px;
font-size: 20px;
}
/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #FF8511;
text-decoration: none;
cursor: pointer;
}
/* Hide the slides by default */
.slide {
display: none;
}
.slide img {
width: 100%;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
.prev {
left: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
color: #FF8511;
}
I had the same issue in one of my past projects. I solved it with this js library https://imagesloaded.desandro.com/,
It allows you to process the images after they are loaded, and you can then assign a css class to it according to the aspect ratio.
$('#container').imagesLoaded( function() {
// images have loaded
// check image height/width > 1, portrait
// check image heidht/width <= 1, square or landscape
// assign different classes for each case to handle
});
css:
.img-container {
//do whatever you need on the container
}
// keep the image classes like this
.img-container img.portrait {
height: 100%;
width: auto;
}
.img-container img.landscape {
width: 100%;
height: auto;
}
I want to do my masterpage for my php group assignment project shape like this:
masterpage image 1
However, it turns badly and out of place like this:
masterpage image 2
How do I ensure that the content area and header in right place and doesnt overlap each other.
here is my code for the masterpage:
CSS
<style>
/* The sidebar menu */
.sidebar {
height: 100%;
width: 250px;
/* Set the width of the sidebar */
position: fixed;
/* Fixed Sidebar (stay in place on scroll) */
z-index: 1;
/* Stay on top */
top: 0;
/* Stay at the top */
left: 0;
background-color: #262626;
/* Dark */
overflow-x: hidden;
/* Disable horizontal scroll */
padding-top: 20px;
color: #cccccc;
/* text colour */
text-align: justify;
position: absolute;
}
/* The navigation menu links */
.sidenav a {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 25px;
color: #cccccc;
/*#818181 */
display: block;
}
.main {
margin-left: 160px;
/* Same as the width of the sidebar */
padding: 0px 10px;
}
#media screen and (max-height: 450px) {
.sidenav {
padding-top: 15px;
}
.sidenav a {
font-size: 18px;
}
}
.img {
display: block;
margin-left: auto;
margin-right: auto;
width: 40%;
}
.header-banner {
position: absolute;
right: 0px;
}
</style>
HTML
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div class="sidebar">
<img class="img" src="/image/logo.png" alt="symbol" style="width:200px;height:125px;" />
</div>
<div class="header-banner">
<img class="banner" src="/image/banner.png" alt="header" style="width=1500px; height:150px;" />
</div>
<!-- Page content -->
</body>
</html>
Try css grid. Here is the code. lemme know if it works.
Markup :
<div class="wrapper">
<div class="mini-wrapper sidebar">
Sidebar
</div>
<div class="mini-wrapper header-top">
Header-top
</div>
<div class="mini-wrapper content-area">
Content Area
</div>
</div>
CSS
body {
margin: 40px;
}
.wrapper {
display: grid;
grid-gap: 10px;
grid-template-columns: 200px 600px;
background-color: #fff;
color: #444;
}
.mini-wrapper {
border:3px solid dodgerblue;
padding: 20px;
font-size: 150%;
}
.sidebar {
grid-column: 1;
grid-row: span 50;
}
.content-area{
grid-column: 2 ;
grid-row: span 49;
}
.header-top {
grid-column: 2;
grid-row:1;
}
https://codepen.io/anon/pen/MPvLqE
I want to show the divs #botone, #bottwo and #botthree one after the other. I also want to have the background image to be adjusted by 100% width and proportional height on #botone div.
Now the last two Divs show up behind the #botone Div and the #botone div adds the 49px to the vertical placement that comes from the .topnav Div.
I also want to fixate the .topnav Div on top.
** body {
margin: 0px 0px;
}
/* Add a black background color to the top navigation */
.topnav {
background-color: #000;
overflow: hidden;
height: 49px;
}
/* Style the links inside the navigation bar */
.topnav a {
float: right;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Change the color of links on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
}
/* Add a color to the active/current link */
.topnav a.active {
background-color: #4CAF50;
color: white;
}
.block {
float: left;
width: 40px;
}
.blocka {
float: right;
width: 250px;
}
#botone {
position: absolute;
height: 100%;
width: 100%;
background-image: url("arc.jpg");
background-size: cover;
}
#bottwo {
background-color: blue;
height: 400px;
width: 100%;
}
#botthree {
background-color: yellow;
height: 600px;
width: 100%;
}
<div class="topnav">
<div class="block">
Oi
</div>
<div class="blocka">
News
Contact
About
</div>
</div>
<div id="botone">testtext
</div>
<div id="bottwo">testtext
</div>
<div id="botthree">testtext
</div>
If I understand your question correctly, does this accomplish what you're trying to do?
HTML:
<div class="topnav">
<div class="block">
Oi
</div>
<div class="blocka">
News
Contact
About
</div>
</div>
<div id="botone">testtext
</div>
<div id="bottwo">testtext
</div>
<div id="botthree">testtext
</div>
CSS: (Changes at bottom)
body {
margin: 0px 0px;
}
/* Add a black background color to the top navigation */
.topnav {
background-color: #000;
overflow: hidden;
height: 49px;
}
/* Style the links inside the navigation bar */
.topnav a {
float: right;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Change the color of links on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
}
/* Add a color to the active/current link */
.topnav a.active {
background-color: #4CAF50;
color:white;
}
.block { float:left;width: 40px; }
.blocka { float:right;width: 250px; }
#botone {
position: absolute;
height: 100%;
width: 100%;
background-image: url("arc.jpg");
background-size: cover;
}
#bottwo {
background-color:blue;
height: 400px;
width: 100%;
}
#botthree {
background-color:yellow;
height: 600px;
width: 100%;
}
/*--- Fixes --*/
.topnav {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 5;
}
#botone {
/*-- Test --*/
background-image: url("https://images.pexels.com/photos/948358/pexels-photo-948358.jpeg?auto=compress&cs=tinysrgb&h=650&w=940");
background-position: center;
height: 100vh;
margin-top: 49px;
position: relative;
}
link to example
A little confused with your requirements description but I think this is what you're trying to achieve:
.topnav {
background-color: #000;
overflow: hidden;
height: 49px;
position:fixed; //add this
width:100%; //add this
}
#botone {
position: absolute;
margin-top: 49px; //add this
height: 100%;
width: 100%;
background-image: url("arc.jpg");
background-size: cover;
}
To fixate the top nav or header, use position:fixed. You would have to define the width as 100% or it automatically takes a width: auto.
To ensure the following div shows directly under the fixed element, give it a margin-top corresponding to the height of the fixed element. If you are using SCSS, this would be much better in responsive design, since you can create a function that applies the height to the margin-top at the same time. But if you are using CSS, just check your #media queries to make sure the height and the margin-top are consistent.
At the moment the blue element is your element that follows the fixed element. If you want to add something in between the blue element and the header (i.e. a slideshow, or banner) treat is as the blue element is being treated now. Give this the margin-top and remove it from the blue element, since the blue element is no longer directly under the fixed header.
See DEMO
Or the whole code in the snippet
body {
margin: 0px 0px;
}
/* Add a black background color to the top navigation */
.topnav {
background-color: #000;
overflow: hidden;
height: 49px;
position:fixed;
width:100%;
top:0;
}
/* Style the links inside the navigation bar */
.topnav a {
float: right;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Change the color of links on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
}
/* Add a color to the active/current link */
.topnav a.active {
background-color: #4CAF50;
color: white;
}
.block {
float: left;
width: 40px;
}
.blocka {
float: right;
width: 250px;
}
#botone {
position: absolute;
margin-top: 49px;
height: 100%;
width: 100%;
background-image: url("arc.jpg");
background-size: cover;
}
#bottwo {
background-color: blue;
height: 400px;
width: 100%;
}
#botthree {
background-color: yellow;
height: 600px;
width: 100%;
}
<div class="topnav">
<div class="block">
Oi
</div>
<div class="blocka">
News
Contact
About
</div>
</div>
<div id="botone">testtext
</div>
<div id="bottwo">testtext
</div>
<div id="botthree">testtext
</div>
I am currently building a site for school and things were going great. However, I attempted to open the site on different browsers and ran into a problem. In some browsers the off screen menu I made in html/css does not seem to want to work right. Sometimes it will appear on the screen and never close and sometimes the button I made will disappear and you can't access the menu at all. Is there a way to make it work across all browsers. I believe the error occurred in chrome and internet explorer as well as firefox. However it works right on my computer in all three browsers.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Code Resources</title>
<link rel="stylesheet" type="text/css" href="cisco.css" media="screen">
<link rel="stylesheet" type="text/css" href="template.css" media="screen">
</head>
<body>
<div class="navigation">
<figure>
<img src="menubanner.jpg" alt="menu banner" />
</figure>
<ul>
<li class="nav-item">Home</li>
<li class="nav-item">About</li>
<li class="nav-item">HTML & CSS</li>
<li class="nav-item">Cisco</li>
</ul>
</div>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger"></label>
<div class="site-wrap">
<h1>Cisco Router and Switch Commands</h1>
<h2></h2>
<br>
<br>
<br>
<br>
</div>
</body>
</html>
The Css is:
.navigation {
/* critical sizing and position styles */
width: 100%;
height: 100%;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 0;
/* non-critical appearance styles menu color */
list-style: none;
background: #333;
}
figure {
width: 200px;
text-align: center;
margin: 20px 0;
}
figure img {
width: 100px;
}
/* Navigation Menu - List items */
.nav-item {
/* non-critical appearance styles */
width: 200px;
border-top: 1px solid #111;
border-bottom: 1px solid #000;
}
.nav-item a {
/* non-critical appearance styles */
display: block;
padding: 1em;
background: linear-gradient(135deg, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%);
color: white;
font-size: 1.2em;
text-decoration: none;
transition: color 0.2s, background 0.5s;
}
.nav-item a:hover {
background: white;
color: rgb(123,193,149);
}
/* Site Wrapper - Everything that isn't navigation */
.site-wrap {
/* Critical position and size styles */
min-height: 100%;
min-width: 100%;
background-color: white; /* Needs a background or else the nav will show through */
position: relative;
top: 0;
bottom: 100%;
left: 0;
z-index: 1;
/* non-critical apperance styles */
padding: 4em;
background-image: url(b1.gif);
background-size: contain;
}
/* Nav Trigger */
.nav-trigger {
/* critical styles - hide the checkbox input */
display: block;
height: 0;
width: 0;
}
label[for="nav-trigger"] {
/* critical positioning styles */
position: fixed;
left: 15px; top: 15px;
z-index: 2;
/* Menu Button*/
/* non-critical apperance styles */
height: 75px;
width: 125px;
cursor: pointer;
background-image: url("menubutton.jpg");
background-size: contain;
}
/* Make the Magic Happen */
.nav-trigger + label, .site-wrap {
transition: left 0.2s;
}
.nav-trigger:checked + label {
left: 215px;
}
.nav-trigger:checked ~ .site-wrap {
left: 200px;
box-shadow: 0 0 5px 5px rgba(0,0,0,0.5);
}
body {
/* Without this, the body has excess horizontal scroll when the menu is open */
overflow-x: hidden;
}
/* Additional non-critical styles */
h1, h2, h3, h4, h5, h6, p {
max-width: 600px;
margin: 0 auto 1em;
}
code {
padding: 2px;
background: #ddd;
}
/* Micro reset */
*,*:before,*:after{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;margin:0;padding:0;}
html, body { height: 100%; width: 100%; font-family: Helvetica, Arial, sans-serif; }
#media only screen
and (min-width : 1224px) {
/* Styles */
.nav-trigger,label {display:none;}
.nav-item,figure {width:20%}
.site-wrap {min-width:80%;float:right;}
figure img {
width: 150px;
}
}
in this section needed to change the min-width to 1600 px
#media only screen
and (min-width : 1224px) {
/* Styles */
.nav-trigger,label {display:none;}
.nav-item,figure {width:20%}
.site-wrap {min-width:80%;float:right;}
figure img {
width: 150px;
}
}