The Responsive.css is not completed yet but it is responding according to the device size. The issues that are arising are that when I resize the the screen, the right section with header Memorial, an image below, and some text are not stacking correctly when the screen shrinks in size. Instead, it will be pushed down but remain on the right handside of the screen. Also have in issue with resizing the images I have displayed on my sites. I would like to resize accordingly with the size of the device. I have a logo image and a banner image and on top of these two images is the navigation bar which I am also having issue with resizing and making it transparent due to having the navigation bar on top of a grey background. How can I make it transparent on top of the banner and logo.
<img id="banner" src="img/banner.jpg"/>
<!--The main content of the website will go inside of the #wrapper id. It is divided into two sections: #primary & #secondary.-->
<div id="wrapper">
<!-- Two sections have been created for desktop view to have two columns. Mobile website will just be stacked-->
<div id="content">
<section id="primary"><!--Left column content goes here-->
<h2>Who We Are</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in elementum velit, venenatis rhoncus lacus. Ut consequat luctus enim, in auctor libero posuere ut. Curabitur vitae aliquet nisi. Etiam condimentum tincidunt venenatis. Fusce vel congue purus. Pellentesque ut eleifend ex. Nunc purus neque, aliquam vitae aliquam quis, accumsan id lacus. Nunc ac scelerisque magna. Etiam purus lorem, rutrum et ornare a, tincidunt non ipsum. Nullam blandit dui venenatis, malesuada felis a, porttitor purus.</p>
<p>This is how a link looks.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in elementum velit, venenatis rhoncus lacus. Ut consequat luctus enim, in auctor libero posuere ut. Curabitur vitae aliquet nisi. Etiam condimentum tincidunt venenatis. Fusce vel congue purus. Pellentesque ut eleifend ex. Nunc purus neque, aliquam vitae aliquam quis, accumsan id lacus. Nunc ac scelerisque magna. Etiam purus lorem, rutrum et ornare a, tincidunt non ipsum. Nullam blandit dui venenatis, malesuada felis a, porttitor purus.</p>
</section>
<section id="secondary"><!--Right column content goes here-->
<h2>Memorial</h2>
<img src="img/memorial_list.jpg"/>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in elementum velit, venenatis rhoncus lacus. Ut consequat luctus enim, in auctor libero posuere ut.</p>
</section>
</div>
</div>
<!--Footer still needs to be completed-->
<footer>
<div id="footer-right">
<ul><h3>ABOUT</h3>
<li>Contact Us</li>
<li>FAQ's</li>
<li>Site Map</li>
</ul>
<ul><h3>SUPPORT OUR CAUSE</h3>
<li>Donate</li>
<li>Volunteer</li>
<li>Fundraising Events</li>
</ul>
<ul><h3>FOLLOW US</h3>
<li>
<img src="img/facebook-icon.png" alt="Facebook Logo" class="social-icon">
<img src="img/instagram-icon.png" alt="Instagram Logo" class="social-icon">
<img src="img/twitter-icon.png" alt="Twitter Logo" class="social-icon"/>
<img src="img/pinterest-icon.png" alt="Pinterest Logo" class="social-icon"/>
</li>
</ul>
</div>
<div id="footer-left">
<p id="footer-slogan">BREAK THE <strong>SILENCE</strong> <br>AND <strong>CYCLE</strong> OF ABUSE</p>
<p id="copyright">Copyright© 2014 International Child Advocacy Network</p>
</div>
</footer>
Responsive CSS:
/*This is the placeholder for responsive CSS that we will implement for mobile design*/
/* Smartphones (portrait and landscape) ----------- */
#media screen and (min-device-width : 240px) and (max-device-width: 660px){
/* Styles */
#content{
float:left;
padding:0;
}
#body{
float:left;
font-family: 'Fabrica';
}
#logo {
margin-right:auto;
width: auto;
height: auto;
padding: 0;
}
#wrapper{
margin: 0 auto;
}
#wrapper p{
text-indent: 0;
}
#nav ul, nav a:visited{
position:relative;
display:none;
}
#nav a:hover {
display:block;
}
#nav li{
text-align:center;
width:100%;
}
#banner{
position:relative;
}
#footer{
font-family: 'Fabrica';
}
}
/* Desktops and laptops ----------- */
#media screen and (min-device-width: 1024px){
/* Styles */
#primary {
width: 50%;
float: left;
padding:10px;
}
#secondary {
width: 40%;
float: right;
padding:10px;
}
}
#font-face {
font-family: 'Fabrica';
font-style: normal;
font-weight: 100;
src: local('Fabrica'), local('Fabrica'), url(path/Fabrica.otf) format('otf');
}
Main CSS:
/***********************
GENERAL
***********************/
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
img {
max-width: 100%;
}
body {
/*font-family: 'Fabrica', 'Courier New';*/
font-family: 'Open Sans', sans-serif;
background-color:#e6e9ed;
color: #434a54;
}
#wrapper{
max-width:960px;
margin: 0 auto;
background-color: #f5f7fa;
overflow: auto; /*This fixed the wrapper background color problem that happened bc floating content*/
line-height: 1.8em;
}
#wrapper img {
border-radius:5px 20px 5px;
}
#wrapper p {
text-indent: 2.5em;
}
#banner {
margin-left: auto;
margin-right:auto;
padding: 0;
display:block;
clear:both;
}
#content {
padding:20px 40px;
padding-bottom:50px;
}
h1, h2, h3 {
font-family: 'Droid Serif', serif;
}
/***********************
HEADER - Top image strip above banner
***********************/
#logo {
text-align:right;
max-height:100%;
max-width:100%;
padding: 10px 0px 10px 30px;
}
#header {
background-image: url(../img/header.jpg);
background-repeat: no-repeat;
background-position: top;
margin: 0 auto;
max-width:960px;
}
/*Commented out for testing new header technique
#header {
margin-left: auto;
margin-right: auto;
padding: 0;
display: block;
clear: both;
font-family: 'Fabrica', Arial;
}
*******/
/***********************
NAVIGATION - Main site navigation
***********************/
nav{
background-color:#4888dc;
text-align:center;
color:blue;
max-width:960px;
margin: 0 auto;
text-align:center;
font-size:1.2em;
}
nav ul{
list-style:none;
margin:0 10px; /*Can be change later on in the design if it doesn't work*/
}
nav li{
/*Inline, mostly text. Appears in the same line, inline as the rest of the text. Block
pushes other items out of the page. Inline block maintains width and
height but is in line with other images*/
display:inline-block;
list-style:none;
padding: .4em 1.5em;
}
nav a {
font-weight: 800;
}
nav a:visited, nav a:link {
color:#f5f7fa;
text-decoration: none;
}
nav a:hover {
color:#0B108C;
text-decoration: none;
}
/**********************
FOOTER
**********************/
footer {
font-family: 'Open Sans', sans-serif;
max-width:950px;
background-color:#434a54;
font-size:0.75em;
clear:both;
color:#e6e9ed; overflow:auto;
margin: 0 auto;
padding:5px;
}
footer h3{
padding-left: .9em;
font-family: 'Open Sans', sans-serif;
}
footer ul {
display:inline-block;
list-style-type: none;
}
footer ul li{
list-style:none;
text-decoration:none;
margin-left: 1em;
}
footer ul li a{
color:#e6e9ed;
}
footer a:hover {
color:#FFFFFF; /*Change hover color to make it more prominent*/
}
/**********************
RIGHT SIDE OF FOOTER
**********************/
#footer-right {
float:right;
margin-right:15px;
}
.social-icon {
display:inline-block;
width:24px;
height:24px;
margin-bottom:22.7px; /*controls height of "follow us" in footer*/
padding:1px;
border-radius: 20%;
}
/**********************
LEFT SIDE OF FOOTER
**********************/
#footer-left {
float:left;
padding-left: 2em;
text-align:left;
font-size: 1.35em;
display:inline-block;
line-height: 1.5em;
}
#footer-slogan {
font-family: 'Georgia', 'Droid Serif', sans-serif;
}
#copyright{
font-size: .75em;
text-align:left;
margin-top: 5px;
display:inline-block;
font-family: 'Open Sans', sans-serif;
}
I use this media query for my responsive design that I use on marketing platform to blast out to users:
#media screen and (max-width: 000px), screen and (max-device-width: 000px)
this works on android, iphone4,5,6 and ipad +other tablets
Use min-width and max-width instead of min-device-width and max-device-width. Device width refers to the display's resolution, i.e. 1024x800, not the size of the window.
Related
In mobile view, the footer is not remaining at at the bottom of the page. It stays somewhere above the bottom. I want the footer to stay at the bottom always in mobile view and desktop view. But the footer should not be visible always, if the site has much contents, user will have to scroll down to see the footer. What changes do I need to make in the css file to make the footer stay at the bottom of the page always?
html { height: 100%; }
body {
font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
color:#303036;
margin:0px;
background:url('../images/diagonal_noise.png');
background-repeat:repeat;
min-width:1100px;
overflow:auto;
height:100%;
}
#mainPart{
margin:0 auto;
}
.container{
overflow:hidden;
clear:both;
max-width:1080px;
margin:20px auto 40px auto;
}
footer {
color: white;
width:100%;
padding:0;
display:block;
clear:both;
height: 40px; /* added */
}
.footrow{
overflow:hidden;
background-color: #111;
display:block;
}
.footrow2{
overflow:hidden;
background-color: #002c42;
display:block;
padding:15px;
}
.foot{
max-width:1080px;
margin:0 auto;
font-size:11px;
line-height:18px;
}
.foot-p{
font-weight: 600;
padding:2px;
color:#66e355 !important;
}
.half-width {
width: 50%;
float:left;
}
.quarter-width {
width: calc(25% - 30px);
float:left;
padding:15px;
}
#social2 {
display: block;
background-color: transparent;
float: left;
margin: 0 auto;
}
.sc-icn2 {
width: 50px;
height: 50px;
display: block;
margin-right: 5px;
margin-bottom: 5px;
float: left;
}
<html>
<head>
</head>
<body>
<div id="mainPart">
</div>
<div class="container">
</div>
<footer>
<div class="footrow" >
<div class="foot">
<div class="quarter-width">
<div>
</div>
</div>
<div class="quarter-width">
</div>
<div class="quarter-width">
<div id="social2">
</div>
</div>
<div class="quarter-width">
</div>
</div>
</div>
<div class="footrow2" >
<div class="foot">
<div class="half-width">
</div>
<div class="half-width">
</div>
</div>
</div>
</footer>
</body>
</html>
To achieve that result define the footer position to bottom. position: absolute; bottom: 0;
The position property specifies the type of positioning method used for an element. The absolute element is positioned relative to its first positioned ancestor element which is the body As you can see in body css rule the element is positioned relative to its normal position.
More about position property can be found here.
html {
position: relative;
min-height: 100%;
height: 100%;
overflow-x: hidden;
overflow-y: scroll;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
overflow-x: hidden;
margin: 0px;
position: relative;
min-height: 100%;
height: auto;
}
.demo {
margin: 0 auto;
padding-top: 64px;
max-width: 640px;
width: 94%;
}
.demo h1 {
margin-top: 0;
}
/**
* Footer Styles
*/
.footer {
position: absolute;
right: 0;
bottom: 0;
left: 0;
padding: 1rem;
background-color: #34495e;
color:#fff;
text-align: center;
}
<div class="demo">
<h1>Footer Stays Bottom</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque congue nunc at ex ultricies molestie. Cras in tempor turpis. Suspendisse et aliquam nisl. Vestibulum semper nibh at nibh dignissim, ac dapibus lorem facilisis. Donec rhoncus lacus sit amet risus dapibus sollicitudin. Ut vitae auctor dolor, et molestie nunc. Maecenas iaculis ante in tincidunt finibus. Etiam vehicula odio a lorem varius sagittis. Suspendisse sed purus at justo porta blandit quis at quam. Sed vitae faucibus nulla. Sed tincidunt tellus sapien, eu pulvinar nisi suscipit sed. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec eget felis ultricies, iaculis est eu, posuere nulla.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque congue nunc at ex ultricies molestie. Cras in tempor turpis. Suspendisse et aliquam nisl. Vestibulum semper nibh at nibh dignissim, ac dapibus lorem facilisis. Donec rhoncus lacus sit amet risus dapibus sollicitudin. Ut vitae auctor dolor, et molestie nunc. Maecenas iaculis ante in tincidunt finibus. Etiam vehicula odio a lorem varius sagittis. Suspendisse sed purus at justo porta blandit quis at quam. Sed vitae faucibus nulla. Sed tincidunt tellus sapien, eu pulvinar nisi suscipit sed. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec eget felis ultricies, iaculis est eu, posuere nulla.</p>
</div>
<div class="footer">This footer will always be positioned at the bottom of the page, but <strong>not fixed</strong>.</div>
To make the footer stay at bottom of the page, you simply have to add position: absolute; and bottom: 0; in the block of CSS that applies to footer. So it will become:
footer{
color: white;
width:100%;
padding:0;
display:block;
clear:both;
height: 40px; /* added */
position: absolute;
bottom: 0;
}
You can do this by many ways:
There is negative bottom margins on wrappers
There was a wrapping element that held everything except the footer. It had a negative margin equal to the height of the footer.
* {
box-sizing: border-box;
}
html, body {
height: 100%;
margin: 0;
}
.content {
padding: 20px;
min-height: 100%;
margin: 0 auto -50px;
}
.footer,
.push {
height: 50px;
}
footer {
background: #42A5F5;
color: white;
line-height: 50px;
padding: 0 20px;
}
<div class="content">
<h1>Sticky Footer with Negative Margin 1</h1>
</div>
<footer class="footer">
Footer
</footer>
Negative top margins on footers
This technique did not require a push element, but instead, required an extra wrapping element around the content in which to apply matching bottom padding to. Again to prevent negative margin from lifting the footer above any content.
html, body {
height: 100%;
margin: 0;
}
.content {
min-height: 100%;
}
.content-inside {
padding: 20px;
padding-bottom: 50px;
}
.footer {
height: 50px;
margin-top: -50px;
background: red;
}
<div class="content">
<div class="content-inside">
content
</div>
</div>
<footer class="footer"></footer>
There is calc() reduced height wrappers
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.content {
min-height: calc(100vh - 70px);
padding: 40px 40px 0 40px;
}
.footer {
height: 50px;
background: #42A5F5;
color: white;
line-height: 50px;
padding: 0 20px;
}
<div class="content">
<h1>Sticky Footer with calc()</h1>
</div>
<footer class="footer">
Footer
</footer>
And also you can use flexbox
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
height: 100vh;
}
.content {
flex: 1 0 auto;
padding: 20px;
}
.footer {
flex-shrink: 0;
padding: 20px;
background: #42A5F5;
color: white;
}
<div class="content">
<h1>Sticky Footer with Flexbox</h1>
</div>
<footer class="footer">
Footer
</footer>
This works for you. Try it.
For that add enough content in side the .container div.
And add min-height value to .container as below.
body {
font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
color:#303036;
margin:0px;
background:url('../images/diagonal_noise.png');
background-repeat:repeat;
min-width:100%;
overflow:auto;
height:100%;
}
.container{
overflow:hidden;
clear:both;
max-width:1080px;
margin:20px auto 40px auto;
/*new style*/
min-height:768px;
}
#media only screen and (max-width: 768px) {
.container{
max-width: 80%;
margin:20px auto 40px auto;
min-height:480px;
}
}
html { height: 100%; }
body {
font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
color:#303036;
margin:0px;
background:url('../images/diagonal_noise.png');
background-repeat:repeat;
min-width:100%;
overflow:auto;
height:100%;
}
#mainPart{
margin:0 auto;
}
.container{
overflow:hidden;
clear:both;
max-width:1080px;
margin:20px auto 40px auto;
min-height:768px;
}
footer {
color: white;
width:100%;
padding:0;
display:block;
clear:both;
height: 40px; /* added */
}
.footrow{
overflow:hidden;
background-color: #111;
display:block;
}
.footrow2{
overflow:hidden;
background-color: #002c42;
display:block;
padding:15px;
}
.foot{
max-width:1080px;
margin:0 auto;
font-size:11px;
line-height:18px;
}
.foot-p{
font-weight: 600;
padding:2px;
color:#66e355 !important;
}
.half-width {
width: 50%;
float:left;
}
.quarter-width {
width: calc(25% - 30px);
float:left;
padding:15px;
}
#social2 {
display: block;
background-color: transparent;
float: left;
margin: 0 auto;
}
.sc-icn2 {
width: 50px;
height: 50px;
display: block;
margin-right: 5px;
margin-bottom: 5px;
float: left;
}
#media only screen and (max-width: 768px) {
.container{
max-width: 80%;
margin:20px auto 40px auto;
min-height:480px;
}
}
<html>
<head>
</head>
<body>
<div id="mainPart"></div>
<div class="container">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
<footer>
<div class="footrow" >
<div class="foot">
<div class="quarter-width">
<div>
</div>
</div>
<div class="quarter-width">
</div>
<div class="quarter-width">
<div id="social2">
</div>
</div>
<div class="quarter-width">
</div>
</div>
</div>
<div class="footrow2">
<div class="foot">
<div class="half-width">
</div>
<div class="half-width">
</div>
</div>
</div>
</footer>
</body>
</html>
I'm hoping someone is able to help with an issue I'm currently having with a website I am designing. The media query for mobile is where I'm getting hung up.
This is an image of it.
The content isn't centered. I can fix the text simply with a text-align property, and I assume that I can just make the image display as a block and use margin: 0 auto to center it, the problem is that the container itself is not centered. I'm using Bootstrap, and it's all in a Bootstrap container.
I think part of the issue is that on small screens, I am hiding some content that is to the right of the content I can't get centered using Bootstrap's "hidden-xs" and "hidden-sm" properties.
Here is the code for the relevant section in the screenshot, plus my CSS for the media query. If anyone could point me in the right direction, I'd appreciate it.
/* Content Styles*/
.gas-content {
margin: 4.50em 0 4.50em 5%;
}
.left-content {
margin: 2.50em 0 2.50em 5%;
}
.content-container {
width: 75%;
float: left;
}
.test-container {
width: 25%;
float: left;
margin-top: -10px;
}
.move-up {
margin-top: -2em;
}
.move-down {
margin-top: 2em;
}
.img-center {
display: block;
margin: 0 auto;
}
.content-heading {
color: rgb(3, 17, 85);
font-family: 'Montserrat', sans-serif;
font-weight: 600;
line-height: 1.50em;
}
.services li {
color: rgb(3, 17, 85);
font-family: 'Montserrat', sans-serif;
text-transform: uppercase;
font-size: 1.25em;
font-weight: 600;
}
.emergency-services li {
color: rgb(3, 17, 85);
font-family: 'Montserrat', sans-serif;
text-transform: uppercase;
font-size: 1.25em;
font-weight: 600;
}
.contact-box {
background-color: rgb(3, 17, 85);
padding: 2em 0 6.50em 0;
}
.contact-box h3 {
color: white;
text-transform: uppercase;
margin-left: 15px;
font-family: 'Montserrat', sans-serif;
font-weight: 600;
}
.contact-info {
color: white;
margin-left: 15px;
}
.eztouselogo {
margin-left: 15px;
margin-bottom: 15px;
}
.services-left {
margin-right: 0.50em;
}
.content-paragraph {
font-family: 'Open Sans', sans-serif;
margin-bottom: 5em;
line-height: 2.25em;
}
#media (max-width: 991px) {
.test-container {
display: none;
}
.content-container {
display: block;
margin: 0 auto;
padding: 0 0 0 0;
float: none;
clear: both;
}
.container {
display: block;
margin: 0 auto;
float: none;
clear: both;
}
.pipes-img {
width: 75%;
height: 75%;
display: block;
margin: 0 auto;
float: none;
}
}
<!--Begin Main Content -->
<div class="container"> <!--New Container -->
<div class="content-container"> <!--Content on Left Side of Testimonials -->
<div class="row gas-content"> <!--Gas, Water, & Sewer Line Row -->
<div class="col-md-4">
<img class="pull-left img-responsive pipes-img" src="img/pipes.jpg">
</div>
<div class="col-xs-8 move-up">
<h3 class="content-heading">Gas, Water, & Sewer Line Inspection and Replacement in the Pittsburgh Area</h3>
<p class="content-paragraph">Vivamus id ante molestie, vehicula justo nec, facilisis justo. Sed efficitur feugiat accumsan. Nunc vitae fermentum nulla. Aliquam imperdiet nunc felis, et malesuada ligula molestie eget. Proin sodales dictum semper. Proin nec sodales quam. Maecenas ac erat non mauris laoreet volutpat. Proin egestas enim ut magna sagittis vulputate. Aenean non odio lacus. Nam vehicula metus viverra quam laoreet, nec interdum orci porttitor. Etiam gravida velit sit amet commodo suscipit. Cras est erat, scelerisque quis velit non, luctus molestie ex.</p>
<div class="row">
<div class="col-xs-5">
<ul class="services services-left">
<li>Sewer Lines</li>
<li>Gas Lines</li>
<li>Water Lines</li>
</ul>
</div>
<div class="col-xs-7">
<ul class="services services-right">
<li>Sewer Inspections</li>
<li>Water Heaters</li>
<li>Full-Service Plumbing</li>
</ul>
</div>
</div>
</div>
</div> <!--End Gas, Water, & Sewer Line Row -->
Change col-xs-8 to col-md-8 to match the same breakpoint as that on the image. Otherwise, the div wrapping the image will be 100%, but the sibling div will remain 2/3s width.
I don't think we (web developer) need to customize the media query of Bootstrap Framework. Bootstrap has built-in or default media query that fits to all devices such as :
Extra small devices Phones (<768px)
Class prefix : .col-xs-
Small devices Tablets (≥768px)
Class prefix : .col-sm-
Medium devices Desktops (≥992px)
Class prefix : .col-md-
Large devices Desktops (≥1200px)
Class prefix : .col-lg-
We just need to use it "cleverly" as it is.
First of all, this is my code for the web page
#import url("reset.css");
#import url('https://fonts.googleapis.com/css?family=Raleway');
*
{
box-sizing:border-box;
}
body
{
background-color: #9E9E9E;
}
#wrapper
{
width:95%;
max-width:980px;
margin: 0 auto;
font-family: 'Raleway', sans-serif;
line-height: 2rem;
}
.header
{
padding:18px;
background-color: #757575;
border-radius:5px;
width:100%;
margin-top:5px;
margin-bottom:5px;
}
.column_left
{
float:left;
padding:18px;
width:70% ;
background-color:#607D8B;
border-top-left-radius: 5px;
border-bottom-left-radius:5px;
}
.column_right
{
float:right;
padding:18px;
width:29.99%;
background-color:#455A64;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
/*For Screens 750 PX or less (width)*/
#media screen and (max-width:750px)
{
.header
{
text-align:center;
}
.column_right
{
display:none;
}
.column_left
{
width:100%;
border-radius:5px;
}
}
h1
{
font-size:1.8rem;
}
h2
{
font-size: 1.4rem;
}
p
{
}
nav
{}
nav ul
{}
nav ul li
{
width:100%;
background-color:#607D8B;
text-align:center;
padding:2.5px;
border-radius:5px;
margin-bottom:5px;
}
nav ul li a
{
color:#455A64;
}
footer
{
padding:18px;
background-color: #757575;
border-radius:5px;
width:100%;
margin-top:5px;
margin-bottom:5px;
float:none;
display:flex;
}
<meta name="viewport" content="width=device-width, user-scalable=no">
<div id="wrapper">
<h1 class="header">Lorem Ipsum</h1>
<div class="column_left">
<h2>Welcome to Lorem Ipsum</h2>
<p>Aenean nec vestibulum justo, ut aliquet ante. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Etiam viverra interdum neque, sed sagittis lectus sodales sit amet.</p>
<p>Maecenas posuere laoreet auctor. Integer vel nulla ut magna interdum consectetur.</p>
<p>Vestibulum non ligula sed diam luctus tincidunt in sit amet metus.</p>
</div>
<div class="column_right">
<h2>Navigation</h2>
<nav>
<ul>
<li><a class="button" href="#">Link</a></li>
<li><a class="button" href="#">Link</a></li>
<li><a class="button" href="#">Link</a></li>
</ul>
</nav>
</div>
<footer>
© 2016 Ipsum Lorem
</footer>
</div>
Basically I would like to have the column_left and column_right classes the same height, without using height=100%. The website will have more than one page, and the length on the others may not be the same as the example page. Here is an image of what I got so far:
Basically, I want the navigation div to be as tall as the one beside it.
If flexbox is an option, you can give:
display: flex;
flex-wrap: wrap;
to wrapper and that will fix the heights - see demo below:
#import url("reset.css");
#import url('https://fonts.googleapis.com/css?family=Raleway');
* {
box-sizing: border-box;
}
body {
background-color: #9E9E9E;
}
#wrapper {
width: 95%;
max-width: 980px;
margin: 0 auto;
font-family: 'Raleway', sans-serif;
line-height: 2rem;
display: flex;
flex-wrap: wrap;
}
.header {
padding: 18px;
background-color: #757575;
border-radius: 5px;
width: 100%;
margin-top: 5px;
margin-bottom: 5px;
}
.column_left {
float: left;
padding: 18px;
width: 70%;
background-color: #607D8B;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
.column_right {
float: right;
padding: 18px;
width: 29.99%;
background-color: #455A64;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
/*For Screens 750 PX or less (width)*/
#media screen and (max-width: 750px) {
.header {
text-align: center;
}
.column_right {
display: none;
}
.column_left {
width: 100%;
border-radius: 5px;
}
}
h1 {
font-size: 1.8rem;
}
h2 {
font-size: 1.4rem;
}
p {} nav {} nav ul {} nav ul li {
width: 100%;
background-color: #607D8B;
text-align: center;
padding: 2.5px;
border-radius: 5px;
margin-bottom: 5px;
}
nav ul li a {
color: #455A64;
}
footer {
padding: 18px;
background-color: #757575;
border-radius: 5px;
width: 100%;
margin-top: 5px;
margin-bottom: 5px;
float: none;
display: flex;
}
<div id="wrapper">
<h1 class="header">Lorem Ipsum</h1>
<div class="column_left">
<h2>Welcome to Lorem Ipsum</h2>
<p>Aenean nec vestibulum justo, ut aliquet ante.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Etiam viverra interdum neque, sed sagittis lectus sodales sit amet.</p>
<p>Maecenas posuere laoreet auctor. Integer vel nulla ut magna interdum consectetur.</p>
<p>Vestibulum non ligula sed diam luctus tincidunt in sit amet metus.</p>
</div>
<div class="column_right">
<h2>Navigation</h2>
<nav>
<ul>
<li><a class="button" href="#">Link</a>
</li>
<li><a class="button" href="#">Link</a>
</li>
<li><a class="button" href="#">Link</a>
</li>
</ul>
</nav>
</div>
<footer>
© 2016 Ipsum Lorem
</footer>
</div>
If you can't use flexbox, which is the recommended way, and you don't want script, here is 2 options:
Since both float: right and position: absolute takes the element out of flow (in their own way), the latter will solve your problem if the left column is always higher. With an added wrapper (columns) it could look like this
#import url("reset.css");
#import url('https://fonts.googleapis.com/css?family=Raleway');
*
{
box-sizing:border-box;
}
body
{
background-color: #9E9E9E;
}
#wrapper
{
width:95%;
max-width:980px;
margin: 0 auto;
font-family: 'Raleway', sans-serif;
line-height: 2rem;
}
.header
{
padding:18px;
background-color: #757575;
border-radius:5px;
width:100%;
margin-top:5px;
margin-bottom:5px;
}
.columns
{
position: relative;
}
.columns::after
{
content: '';
display:block;
clear:both;
}
.column_left
{
float:left;
padding:18px;
width:70% ;
background-color:#607D8B;
border-top-left-radius: 5px;
border-bottom-left-radius:5px;
}
.column_right{
position: absolute;
top: 0;
right: 0;
padding:18px;
width:30%;
background-color:#455A64;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
height: 100%;
}
/*For Screens 750 PX or less (width)*/
#media screen and (max-width:750px)
{
.header
{
text-align:center;
}
.column_right
{
display:none;
}
.column_left
{
width:100%;
border-radius:5px;
}
}
h1
{
font-size:1.8rem;
}
h2
{
font-size: 1.4rem;
}
p
{
}
nav
{}
nav ul
{}
nav ul li
{
width:100%;
background-color:#607D8B;
text-align:center;
padding:2.5px;
border-radius:5px;
margin-bottom:5px;
}
nav ul li a
{
color:#455A64;
}
footer
{
padding:18px;
background-color: #757575;
border-radius:5px;
width:100%;
margin-top:5px;
margin-bottom:5px;
float:none;
display:flex;
}
<meta name="viewport" content="width=device-width, user-scalable=no">
<div id="wrapper">
<h1 class="header">Lorem Ipsum</h1>
<div class="columns">
<div class="column_left">
<h2>Welcome to Lorem Ipsum</h2>
<p>Aenean nec vestibulum justo, ut aliquet ante. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Etiam viverra interdum neque, sed sagittis lectus sodales sit amet.</p>
<p>Maecenas posuere laoreet auctor. Integer vel nulla ut magna interdum consectetur.</p>
<p>Vestibulum non ligula sed diam luctus tincidunt in sit amet metus.</p>
</div>
<div class="column_right">
<h2>Navigation</h2>
<nav>
<ul>
<li><a class="button" href="#">Link</a></li>
<li><a class="button" href="#">Link</a></li>
<li><a class="button" href="#">Link</a></li>
</ul>
</nav>
</div>
</div>
<footer>
© 2016 Ipsum Lorem
</footer>
</div>
Use display: table. With an added wrapper (columns) it could look like this:
(I favor this before the above as it is dynamic and keep both columns equal high regardless of which one is higher.)
#import url("reset.css");
#import url('https://fonts.googleapis.com/css?family=Raleway');
*
{
box-sizing:border-box;
}
body
{
background-color: #9E9E9E;
}
#wrapper
{
width:95%;
max-width:980px;
margin: 0 auto;
font-family: 'Raleway', sans-serif;
line-height: 2rem;
}
.header
{
padding:18px;
background-color: #757575;
border-radius:5px;
width:100%;
margin-top:5px;
margin-bottom:5px;
}
.columns
{
display: table;
width: 100%;
}
.column_left
{
display: table-cell;
padding:18px;
width:70%;
background-color:#607D8B;
border-top-left-radius: 5px;
border-bottom-left-radius:5px;
}
.column_right{
display: table-cell;
padding:18px;
width:30%;
background-color:#455A64;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
}
/*For Screens 750 PX or less (width)*/
#media screen and (max-width:750px)
{
.header
{
text-align:center;
}
.column_right
{
display:none;
}
.column_left
{
width:100%;
border-radius:5px;
}
}
h1
{
font-size:1.8rem;
}
h2
{
font-size: 1.4rem;
}
p
{
}
nav
{}
nav ul
{}
nav ul li
{
width:100%;
background-color:#607D8B;
text-align:center;
padding:2.5px;
border-radius:5px;
margin-bottom:5px;
}
nav ul li a
{
color:#455A64;
}
footer
{
padding:18px;
background-color: #757575;
border-radius:5px;
width:100%;
margin-top:5px;
margin-bottom:5px;
float:none;
display:flex;
}
<meta name="viewport" content="width=device-width, user-scalable=no">
<div id="wrapper">
<h1 class="header">Lorem Ipsum</h1>
<div class="columns">
<div class="column_left">
<h2>Welcome to Lorem Ipsum</h2>
<p>Aenean nec vestibulum justo, ut aliquet ante. </p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>Etiam viverra interdum neque, sed sagittis lectus sodales sit amet.</p>
<p>Maecenas posuere laoreet auctor. Integer vel nulla ut magna interdum consectetur.</p>
<p>Vestibulum non ligula sed diam luctus tincidunt in sit amet metus.</p>
</div>
<div class="column_right">
<h2>Navigation</h2>
<nav>
<ul>
<li><a class="button" href="#">Link</a></li>
<li><a class="button" href="#">Link</a></li>
<li><a class="button" href="#">Link</a></li>
</ul>
</nav>
</div>
</div>
<footer>
© 2016 Ipsum Lorem
</footer>
</div>
Per this similar question, you can achieve this using JavaScript.
document.getElementsByClassName("column_left")[0].style.height = document.getElementsByClassName("column_right")[0].style.height;
This will set the left column's height to the right column's height. You can switch around the code, and use the question's answers too.
I am having a problem with an overlapping DIV.
This is how the webpage appears when the window is maximised
This is how the webpage appears when the window is shrunk
This is how the webpage appears when the user scrolls to the right (red arrow) to view the text/image but the problem is that the content overlaps the side bar (blue arrow).
So my question is, how do stop this happening (or how should I be doing this)?
This is my HTML/CSS (it's not in a Fiddle because I can't demonstrate the issue that way)
<!DOCTYPE html><head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<title>Example Title</title>
<style>
#import url(https://fonts.googleapis.com/css?family=Open+Sans);
.content {
width:auto;
float:left;
clear: right;
}
#sidebar #menubar li, #sidebar #menubar li:link, #sidebar #menubar li:visited {
padding-top: 10px;
padding-right: 25px;
padding-bottom: 10px;
padding-left: 25px;
}
#sidebar #menubar li a, #sidebar #menubar li a:link, #sidebar #menubar li a:visited {
font-family: 'Open Sans', sans-serif; font-size: 80%;
color: #FFF;
text-decoration: none;
}
#logo {
height: 90px;
width: 200px;
margin-top: 0px;
margin-right: 25px;
margin-bottom: 25px;
margin-left: 25px;
}
#sidebar #menubar li:hover {
padding-top: 10px;
padding-right: 25px;
padding-bottom: 10px;
padding-left: 25px;
background-color: #06C;
}
#sidebar #menubar li a:hover {
font-family: 'Open Sans', sans-serif; font-size: 80%;
color: #FFF;
text-decoration: none;
}
#sidebar #menubar li#active{
font-family: 'Open Sans', sans-serif;
color: #FFF;
text-decoration: none;
padding-top: 10px;
padding-right: 25px;
padding-bottom: 10px;
padding-left: 25px;
background-color: #0066CC;
}
#sidebar #menubar {
padding: 0px;
margin: 0px;
list-style-type: none;
}
h1 {
font-family: 'Open Sans', sans-serif;
font-size: 125%;
color: #006;
text-decoration: none;
}html, body {
height:100%;
margin: 0px;
padding: 0px;
background-color: #FFF;
}
#sidebar {
width: 250px;
height: 100%;
left: 0;
top: 0;
float:left;
background-color: #006;
padding-top: 25px;
position: fixed;
clear: right;
overflow-y:auto;
overflow-x:hidden;
bottom: 0px;
}
#content {
width: auto;
float: left;
margin-left: 250px;
padding-top: 125px;
padding-right: 125px;
padding-bottom: 125px;
padding-left: 125px;
position: absolute;
overflow-y: auto;
overflow-x: hidden;
}
#media only screen and (max-width: 500px){
#sidebar{
position:relative;
height:auto;
width:100%;
float:left;
clear: right;
padding-bottom: 25px;
}
#content {
position:relative;
width:auto;
float:left;
margin: 0px;
padding: 25px;
clear: right;
}
}
</style>
</head>
<body>
<section><div id="sidebar">
<div id="logo"><img src="http://dummyimage.com/200x89/000/fff&text=Logo" width="200" height="89" alt="" /></div>
<ul id="menubar">
<li >Link 1</li>
<li >Link 2</li>
<li >Link 3</li>
<li >Link 4</li>
<li >Link 5</li>
</ul>
</div></section>
<div id="content">
<div class="content">
<h1>Example H1</h1>
<p>Duis aliquam mauris ac felis tincidunt varius. Maecenas pharetra id risus sed adipiscing. Vestibulum non libero eu quam semper commodo. Aliquam et diam ac tortor molestie blandit. Nullam et sem elit. Aenean tincidunt vitae lacus luctus fringilla. Cras mattis placerat semper. Etiam ullamcorper nunc vel mauris suscipit feugiat. In ac sollicitudin tellus, quis condimentum velit. Sed aliquam, leo non luctus dignissim, sapien felis ultrices sapien, vitae sollicitudin tortor sapien viverra diam. Nam varius nulla sapien, in pharetra sem placerat pretium. Ut varius vehicula nisl vel scelerisque. In hac habitasse platea dictumst. Sed iaculis, risus condimentum accumsan sagittis, mauris sem accumsan lectus, interdum porta metus leo sit amet tortor.
</p>
<div class="content-image"><img src="http://dummyimage.com/650x400/000/fff&text=Large+Image" alt="" width="650" height="400" border="0" align="middle" /></div>
</div>
</div>
<div style='clear:both;'></div>
</body>
</html>
EDIT: The reason why the side bar has a position: fixed is because this happens if it isn't:
This is because the sidebar is fixed. To achieve what you want, try floating both the sidebar and the content to the left.
Here's a simplified example: Fiddle
#sidebar
{
float:left;
background-color:#56B7BF;
width:150px;
height:400px;
}
#content
{
float:left;
background-color:#BF5E56;
width:400px;
height:400px;
}
The side bar needs to have a position absolute, give this a read:
https://developer.mozilla.org/en-US/docs/Web/CSS/position
<!DOCTYPE html><head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telephone=no" />
<title>Example Title</title>
<style>
#import url(https://fonts.googleapis.com/css?family=Open+Sans);
.content {
width:auto;
float:left;
clear: right;
}
#sidebar #menubar li, #sidebar #menubar li:link, #sidebar #menubar li:visited {
padding-top: 10px;
padding-right: 25px;
padding-bottom: 10px;
padding-left: 25px;
}
#sidebar #menubar li a, #sidebar #menubar li a:link, #sidebar #menubar li a:visited {
font-family: 'Open Sans', sans-serif; font-size: 80%;
color: #FFF;
text-decoration: none;
}
#logo {
height: 90px;
width: 200px;
margin-top: 0px;
margin-right: 25px;
margin-bottom: 25px;
margin-left: 25px;
}
#sidebar #menubar li:hover {
padding-top: 10px;
padding-right: 25px;
padding-bottom: 10px;
padding-left: 25px;
background-color: #06C;
}
#sidebar #menubar li a:hover {
font-family: 'Open Sans', sans-serif; font-size: 80%;
color: #FFF;
text-decoration: none;
}
#sidebar #menubar li#active{
font-family: 'Open Sans', sans-serif;
color: #FFF;
text-decoration: none;
padding-top: 10px;
padding-right: 25px;
padding-bottom: 10px;
padding-left: 25px;
background-color: #0066CC;
}
#sidebar #menubar {
padding: 0px;
margin: 0px;
list-style-type: none;
}
h1 {
font-family: 'Open Sans', sans-serif;
font-size: 125%;
color: #006;
text-decoration: none;
}html, body {
height:100%;
margin: 0px;
padding: 0px;
background-color: #FFF;
}
#sidebar {
width: 250px;
height: 100%;
left: 0;
top: 0;
float:left;
background-color: #006;
padding-top: 25px;
position: absolute;
clear: right;
overflow-y:auto;
overflow-x:hidden;
bottom: 0px;
}
#content {
width: auto;
min-width: 700px;
float: left;
margin-left: 250px;
padding-top: 125px;
padding-right: 125px;
padding-bottom: 125px;
padding-left: 125px;
position: absolute;
overflow-y: auto;
overflow-x: hidden;
}
#media only screen and (max-width: 500px){
#sidebar{
position:relative;
height:auto;
width:100%;
float:left;
clear: right;
padding-bottom: 25px;
}
#content {
position:relative;
width:auto;
float:left;
margin: 0px;
padding: 25px;
clear: right;
}
.content img {
display: none;
}
}
</style>
</head>
<body>
<section><div id="sidebar">
<div id="logo"><img src="http://dummyimage.com/200x89/000/fff&text=Logo" width="200" height="89" alt="" /></div>
<ul id="menubar">
<li >Link 1</li>
<li >Link 2</li>
<li >Link 3</li>
<li >Link 4</li>
<li >Link 5</li>
</ul>
</div></section>
<div id="content">
<div class="content">
<h1>Example H1</h1>
<p>Duis aliquam mauris ac felis tincidunt varius. Maecenas pharetra id risus sed adipiscing. Vestibulum non libero eu quam semper commodo. Aliquam et diam ac tortor molestie blandit. Nullam et sem elit. Aenean tincidunt vitae lacus luctus fringilla. Cras mattis placerat semper. Etiam ullamcorper nunc vel mauris suscipit feugiat. In ac sollicitudin tellus, quis condimentum velit. Sed aliquam, leo non luctus dignissim, sapien felis ultrices sapien, vitae sollicitudin tortor sapien viverra diam. Nam varius nulla sapien, in pharetra sem placerat pretium. Ut varius vehicula nisl vel scelerisque. In hac habitasse platea dictumst. Sed iaculis, risus condimentum accumsan sagittis, mauris sem accumsan lectus, interdum porta metus leo sit amet tortor.
</p>
<div class="content-image"><img src="http://dummyimage.com/650x400/000/fff&text=Large+Image" alt="" width="650" height="400" border="0" align="middle" /></div>
</div>
</div>
<div style='clear:both;'></div>
</body>
I am trying to extend the background color of my nav-wrapper div or in general, my navigation area, beyond the 960px container. I have tried some techniques, but nothing has appeared to be working. See attached code and JSFiddle.
JSFidde: Header Background Color Extend
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Responsive 3-Line Menu</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<link type="text/javascript" src="navicon.js">
</head>
<body>
<!-- Start Wrapper -->
<div class="wrapper">
<!-- Start Navigation Wrapper -->
<nav class="nav-wrapper">
<img src="tappery.png"/>
<!-- Start Navigation Links -->
<ul id="nav">
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<!-- End Navigation Links -->
</nav>
<!-- End Navigation Wrapper -->
<!-- Start Content -->
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla imperdiet ante orci, vitae auctor risus pharetra at. Quisque gravida a massa eget hendrerit. Nulla facilisi. Ut rutrum commodo faucibus. Aenean nec libero condimentum, vehicula nisi ut, ullamcorper felis. Ut non tempus odio. Donec vulputate blandit adipiscing. Ut condimentum feugiat lacus. Morbi eget mi pulvinar, imperdiet quam non, commodo ante. Proin vel urna in quam malesuada tincidunt. Suspendisse bibendum lacinia mi, et consectetur felis. Quisque a sem vel justo condimentum scelerisque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec molestie dapibus quam, nec pharetra nisl pretium in. Fusce blandit felis vitae eros tempor, in tempor neque malesuada. Duis in dignissim sem.</p>
</div>
<!-- End Content -->
</div>
<!-- End Wrapper -->
<script type="text/javascript">$("#nav").addClass("js").before('<div id="menu">☰</div>');
$("#menu").click(function(){
$("#nav").slideToggle();
});
$(window).resize(function(){
if(window.innerWidth > 768) {
$("#nav").removeAttr("style");
}
});</script>
</body>
</html>
CSS:
html, body {
overflow-x: hidden;
}
body {
margin: 0;
padding: 0;
background-color: #cecece;
}
.wrapper {
top:0;
margin-top: 0;
width: 960px;
margin-right: auto;
margin-left: auto;
background-color: #fff;
overflow: hidden;
}
#logo {
width: 200px;
}
#logo img {
width: 150px;
height: 40px;
}
#nav {
width: 100%;
}
#content {
margin-top: 50px;
}
li {
}
li:last-child {
border-right:none;
}
li a {
display: block;
width:100%;
background:#fff;
color: #3d6430;
font-size:1.35em;
text-decoration: none;
margin-top: 5px;
}
#media screen and (max-width: 768px) {
.wrapper {
width: 100%;
overflow: hidden;
}
#nav {
clear: both;
}
#menu {
width:1.4em;
display: block;
background:#fff;
font-size:1.35em;
text-align: center;
float: right;
top:0;
}
#logo {
float: none;
}
#nav.js {
display: none;
padding: 0;
}
ul {
width:100%;
list-style:none;
height: auto;
}
li {
width:100%;
border-right:none;
border-top: 1px solid #3d6430;
}
}
#media screen and (min-width: 768px) {
.nav-wrapper {
background-color: #fff repeat-x;
width: 100%;
overflow: hidden;
position: fixed;
z-index: 100;
}
#nav {
clear: both;
}
#logo {
float: left;
display: inline;
}
ul {
width:100%;
background-color: #fff;
height: 40px;
padding: 0;
display: inline;
}
li {
padding: 0 20px;
float: left;
list-style-type: none;
}
#menu {
display: none;
}
}
Okay, here is my answer. It's a little bit hackish but it should work...so, you can't confine it within the bounds of the wrapper, because it's limited to 960px. You'll need to declare something before the wrapper.
What I would do is make a small, white image that is 1px wide and however tall your nav is. Then, set the background color AND image in the body:
body{
background-image: url('white.jpg');
background-color: #cecece;
background-position: left top;
background-repeat: repeat-x;
}
There are downsides; you'd have to know the exact height of your nav, and if that changes you'd need to change the image's size as well. Let me know if that works--thank you for providing the image, it cleared up what you wanted.
Just set left:0; to the .nav-wrapper and remove repeat-x from background color:
.nav-wrapper {
background-color: #fff;
width: 100%;
overflow: hidden;
position: fixed;
left:0;
z-index: 100;
}
Here is a FIDDLE
If anyone came here in hopes to extend background colors outside of Bootstrap container, this is how I solved it.
Bootstrap's container will give you a centered column of content on the page. But what if you want to give color to JUST ONE of the margin areas outside of Bootstrap's container?
I solved it by wrapping the container, with a flexbox-container and building 3 distinct columns: left margin column, content column, and the right margin column.
To ensure that it's always centered, I used this bit to determine the width of each margin column:
.right-box, .left-box{
width: calc((100vw - 1170px) /2);
}
Here's a code pen.
Cant you just add a div before the wrapper?
Somthing like this:
|HTML|
<body>
<div class="backgroundColorContainer">
<div class="wrapper">
// code here
</div>
</div>
</body>
|CSS|
.backgroundColorContainer
{
background-color: #222222;
}
Worked for me :D