I have a sidebar & a navbar in my html file. That's all I have. I wanted to insert my content into the div main-content. But when I insert anything into the main-content div. It appears like this -
I want my content to appear on the empty space.
What I am using here.
<div class="wrapper">
<nav>
<div class="nav-wrapper">
<ul>
<li>...</li>
<li>...</li>
</ul>
</div>
</nav>
<div class="sidebar">
<ul>
<li>...</li>
<li>
<ul>
<li>...</li>
</ul>
</li>
</ul>
</div>
<div class="main-content">
<!--Main Content Here-->
</div>
</div>
.sidebar{
padding-top: 84px;
position: fixed;
width: 223px;
height: 100%;
background: #333;
min-width: 120px;
transition: 0.5s ease-in;
}
.nav-wrapper{
background-color: white;
color: #222;
z-index: 9999;
}
I make style for your output so when you add the style in your code it will work like you want.
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 100%;
background: #f2f2f9;
}
.wrapper {
width: 100%;
display: inline-block;
}
.sidebar {
padding-top: 50px;
position: fixed;
width: 223px;
height: 100%;
background: #333;
min-width: 120px;
transition: 0.5s ease-in;
z-index: 1;
}
.nav-wrapper{
background-color: white;
color: #222;
}
nav {
z-index: 9999;
position: relative;
}
.main-content {
padding-left: 243px;
display: inline-block;
width: 100%;
padding-top: 15px;
}
</style>
I fixed my problem by shifting my sidebar into a main-container and then adding a padding of -100%. Then i made another division with class content and set its padding to 223px (the width of the sidebar) and adding padding further. If anyone has a better solution please answer!
Could you try as left the content as left & right? Find below a sample i tried
<div class="wrapper">
<nav>
<div class="nav-wrapper">
Nav Wrapper
</div>
<div class="wrapper-content">
<!--Main Content Here-->
Main Content
</div>
</nav>
<div class="sidebar">
SideBar
</div>
</div>
CSS
.nav-wrapper {
background-color: white;
color: #222;
z-index: 9999;
float: left;
margin-bottom: 84px;
}
.wrapper-content {
float: right;
}
Related
I'm new to Bootstrap. Trying to implement a fixed footer to the page with a logo whose height > height of the footer. The footer with an image are fixed at the bottom, while the image sticks out of the footer.
Like this...
If I make the image a part of the footer it resizes to the height of the footer. How do I implement this? I have been stuck on this for a while now.
/***Footer***/
footer {
width: 100%;
z-index: 9;
background: #bff;
position: fixed;
bottom: 0px;
left: 0px;
height: 40px;
padding: 0 25px;
color: #808080;
}
.foot-lg {}
.foot-lg img {
width: 50px;
}
.footer-logo-copyright,
.foot-menu,
.foot-social {
overflow: hidden;
display: flex;
height: 40px;
}
/*** added on 04.Jun.21 to display GPTW logo sticking out of footer ***/
.foot-pop img {
overflow: visible;
max-height: 100%;
height: 100%;
width: auto;
}
/**********************************************************************/
.footer-logo-copyright *,
.foot-menu *,
.foot-social * {
align-self: center;
}
.footer-logo-copyright p {
padding: 0 10px;
font-size: 11px;
}
.foot-menu li {
float: left;
list-style: none;
border-right: 1px solid #808080;
}
.foot-menu li:last-child {
border-right: none;
}
.foot-menu li a {
display: block;
padding: 0px 15px;
text-decoration: none;
color: #808080;
text-transform: uppercase;
font-size: 12px;
letter-spacing: 1px;
}
.foot-menu li:hover a {
color: #f37e1f;
}
.foot-social li {
float: left;
margin-right: 10px;
}
.foot-social li:last-child {
margin-right: 0;
}
.foot-social li a img {
width: 13px;
filter: invert(.7);
opacity: 0.5;
}
.foot-social li:hover a img {
/* filter: invert(0); */
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<footer>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 no-pd">
<div class="footer-logo-copyright">
<a href="" class="pull-left foot-lg">
<img src="img/logo-animation.gif" alt="footer-logo">
</a>
<p class="pull-left">is a registered trademark of XYZ Pty Ltd.</p>
<p class="pull-left">© 2021. all rights reserve to XYZ Pty Ltd.</p>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
<ul class="pull-right foot-menu">
<li>
Careers
</li>
<li>
Sitemap
</li>
</ul>
</div>
<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
<ul class="foot-pop pull right">
<li>
<a href="# ">
<img src="img/gptw21.jpg ">
</a>
</li>
</ul>
<ul class="foot-social pull-right ">
<li>
<a href="https://www.linkedin.com/company/sjs-enterprises-pvt.-ltd./?originalSubdomain=in " class=" ">
<img src="img/linked-in-logo-key.svg ">
</a>
</li>
</ul>
</div>
</div>
</footer>
Thanks
Keep the HTML structure you have now, that is with the logo as part of the footer so it is positioned and is sized in relation to the footer.
What you want is for the logo to be able to be set at the bottom of the footer (perhaps with some padding or a margin) but to have, say, twice the height, or the height of the footer plus a bit (it's not possible to tell exactly which from the question).
This boiled-down snippet assumes you want the logo to be the height of the footer plus a bit. If you want it to be twice the height of the footer, say, see the comment.
body {
width: 100vw;
height: 100vh;
}
footer {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 10%;
background-color: cyan;
}
footer .logo {
position: absolute;
right: 1vmin;
bottom: 1vmin;
height: calc(100% + 30px); /* CHANGE to be what you want - e.g. height: 200% for twice the footer height %/
width: auto;
}
<footer>
<img src="https://i.stack.imgur.com/csy1S.png" class="logo">
</div>
</footer>
In your img tag add following style :
img {
max-height: 100%;
height: 100%;
width: auto;
}
If you're wanting to have a fixed image appear in the corner of the page, over the footer, you can easily use fixed positioning to achieve the desired result.
All you would need to do is create a new div container and add the fixed positioning to that element. See the below implementation for more information.
<style>
.fixed-image {
position: fixed;
bottom: 0;
right: 0;
}
</style>
<div class="fixed-image">
<img src="https://dummyimage.com/120x170/000/fff" alt="Image">
</div>
Documentation:
https://developer.mozilla.org/en-US/docs/Web/CSS/position
Attached is a JsFiddle:
https://jsfiddle.net/aus_tin/0dsoqecz/2/
You can achieve this result if you make the footer relative positioned and image as absolute
position: absolute;
bottom: 0;
right: 20px; // Change it as per your requirement
html,
body {
height: 100%;
background-color: cadetblue;
margin: 0;
padding: 0;
}
div#wrapper {
height: 100%;
display: grid;
grid-template-rows: 100px auto 50px;
}
header {
background-color: purple;
}
footer {
position: relative;
background-color: lime;
}
footer>img {
position: absolute;
bottom: 0;
right: 20px;
}
<div id="wrapper">
<header>header</header>
<main>body</main>
<footer>
footer
<img src="https://picsum.photos/100" />
</footer>
</div>
In normal (not responsive yet) my website running good, but after I set responsive to (width: 1336px) for my web it's display screen like this although I've set width for this is 100%
/* Here is my CSS *style.css* */
* {
box-sizing: border-box;
}
body {
font-family: 'Montserrat', sans-serif;
margin: 0;
width: 100%;
}
/* style for header section */
h1 {
line-height: 65px;
font-size: 48px;
}
.header-container {
background-image: linear-gradient( 0deg, rgba(35, 39, 49, -0.18), rgba(35, 39, 49, 1.82)), url("images/bg-image.jpeg");
background-repeat: no-repeat;
background-size: cover;
box-sizing: border-box;
position: absolute;
width: 100%;
height: 743px;
left: -1px;
top: 0px;
}
.nav-bar {
position: absolute;
width: 1700px;
height: 135px;
left: 69px;
top: 17px;
filter: brightness(100%);
}
.header-logo {
float: left;
}
.nav-content {
list-style-type: none;
}
.menu-section {
width: 50%;
float: right;
margin-top: 34px;
}
.menu-item {
float: left;
display: block;
margin-right: 70px;
}
/* nav menu */
.nav-content li a {
text-decoration: none;
color: #fff;
font-size: 20px;
}
.nav-content li a:hover {
color: #00B9F7;
}
/* header title */
.header-title {
color: #fff;
text-align: center;
margin: auto;
width: 30%;
padding: 10px;
margin-top: 10%;
}
/* header video */
.header-video {
margin-left: 30%;
width: fit-content;
}
<!-- here is my HTML code *index.html* -->
<header class="header-container">
<div class="header-content">
<div class="nav-bar">
<div class="header-logo">
<a href="#">
<img id="image-logo-header" class="bottom img-logo" src="images/logo.png">
</a>
</div>
<div class="menu-section">
<div class="menu-btn-group">
<div class="menu-toggle"></div>
<div class="menu-close"></div>
</div>
<div class="navigation navbar-collapse ">
<nav role="navigation">
<ul class="nav-content">
<li class="menu-item"><a class="active-item" href="#">Home</a></li>
<li class="menu-item">Blog</li>
<li class="menu-item">About</li>
<li class="menu-item">Contact</li>
<li class="menu-item">Login</li>
<li class="menu-item">Sign up</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="header-title">
<h1>SHARE YOUR HOLIDDAY DREAM</h1>
</div>
<div class="header-video">
<img class="video-img" src="images/video-img.png">
</div>
</div>
</header>
Can anyone help me, please? your answer is my happiness, thank you so much
This is happening because in your code you have set background width to 100% that is working fine but when you are using resposive design the background image not filling the screen.
Because the background image is filling the 100% width of your responsive container but the blank space that you are seeing in right side is because of nav-bar, you have set its width fixed to 1700px.
To resolve this make your nav-bar responsive so that it can also set its width according to container.
You can use
.nav-bar {
position: absolute;
width: 100%;
height: 135px;
left: 69px;
top: 17px;
filter: brightness(100%);
}
width: 100% make your nav-bar responsive too.
Can you try using img: { width: 100vw };?
In css, verify the margins and padding.
I will explain my problem.
For school I have to make a website, but it is not working how it should be.
I have a border made of divs around the screen, and the page in the middle. When I first open the page, everything is in place, but when I click on one of the nav items (#link) the page suddenly loses its margin top and left. So it goes outside of the borders. I pasted all the code in the snippet, as I believe it will be too much for a post.
To see the full page and problem, please copy the code in a file to open it in the browser itself. I used vw and vh because it want it to be the same on different screens. I will do the inside elements mostly with percentages
So my questions:
How do I prevent this from happening, and an example?
Is there a way to set #Home as the usual landing space? without adding #Home in the link (and without changing its position)?
And my last question regarding CSS animation, how do I add a transition so it looks like the page is scrolling to the #div.
body{
top: 0;
margin: 0;
padding: 0;
left: 0;
}
.wrapper{
width: 100vw;
height: 100vh;
overflow: hidden;
}
.container{
width: 300vw;
height: 200vh;
background-image: url("../img/background.png");
background-size: cover;
}
/* simple nav*/
ul{
display: inline;
z-index: 99;
position: fixed;
}
ul li{
list-style-type: none;
display: inline;
}
ul li a{
text-decoration: none;
}
/*pages*/
.page{
margin: 10vh 10vw;
width: 80vw;
height: 80vh;
transition: 2s;
}
#Interactive{
background: blue;
float: left;
}
#Graphical{
float: left;
}
#Company{
float: left;
}
#Conclusion{
float: left;
}
#Home{
float: left;
}
/*header borders*/
.borders{
position: fixed;
z-index: 30;
}
.border-top{
height: 10vh;
width: 100vw;
top:0;
background: #007CFF;
}
.border-left{
height: 100vh;
width: 10vw;
top: 0;
background: #007CFF;
position: absolute;
}
.border-right{
height: 100vh;
width: 10vw;
top: 0;
background: #007CFF;
float: right;
margin-top: -10vh;
}
.border-bottom{
height: 10vh;
width: 100vw;
bottom: 0;
background: #007CFF;
position: absolute;
}
<div class="header">
<ul>
<li>Home</li>
<li>Interactive</li>
<li>Graphical</li>
<li>Company</li>
<li>Conclusion</li>
</ul>
</div>
<div class="borders">
<div class="border-top">
</div>
<div class="border-left">
</div>
<div class="border-right">
</div>
<div class="border-bottom">
</div>
</div>
<div class="wrapper">
<div class="container">
<div id="Interactive" class="page">
</div>
<div id="Graphical"class="page">
</div>
<div id="Company"class="page">
</div>
<div id="conclusion"class="page">
</div>
<div id="home"class="page">
</div>
</div>
</div>
Thanks for thinking with me, any help is appreciated.
I didn't really know how to call this post, so the search for it was difficult.
Please remove this div
#Interactive{
background: blue;
float: left;}
I think this only you are expecting.
I have made changes to your HTML code and CSS code on the basis of what i thought you wanted to achieve. Below is the code.
* {
padding: 0;
margin: 0;
}
body{
display: flex;
flex-direction: column;
}
.header {
padding: 10px 50px;
}
ul li{
list-style-type: none;
display: inline-block;
padding: 10px;
}
.wrapper {
flex-grow: 1;
padding: 50px 150px;
}
.page{
transition: 2s;
width: 100%;
height: 100%;
}
#Home{
background-color: pink;
}
#Interactive{
background: blue;
}
#Graphical{
background-color: green;
}
#Company{
background-color: yellow;
}
#Conclusion{
background-color: orange;
}
<div class="header">
<ul>
<li>Home</li>
<li>Interactive</li>
<li>Graphical</li>
<li>Company</li>
<li>Conclusion</li>
</ul>
</div>
<div class="wrapper">
<div id="Home" class="page">
</div>
<div id="Interactive" class="page">
</div>
<div id="Graphical" class="page">
</div>
<div id="Company" class="page">
</div>
<div id="Conclusion" class="page">
</div>
</div>
If you want to use transition for smooth scrolling. Refer to
this
article, you will have to use jQuery.
Also do not use fixed width or height until necessarily required.
Use document.getElementById('Home').focus() in document.ready() of js to bydefault show the Home Page.
Always focus on making responsive solutions with relative content rather than absolute content.
Let me know if you need more help :)
I have two div. One contains the navbar and the other is the first section of the site. Both have background images and content. The background of the navbar isn't showing while the content is there. I wanted the navbar to be on top of the section and that is why I have z-index:2. The thing is even if I remove that, the background-color doesn't appear.
I inspected it every way but whatever I do it is simply not showing.
This is the navbar css:
#section{
height: 70px;
z-index: 2;
padding-left: 10%;
padding-right: 10%;
clear: both;
max-width: 100%;
background-color: black;
}
This is the section css:
#section-1{
background: url(Images/1.jpg);
max-width: 100%;
padding-top:14%;
padding-bottom: 7%;
color:white;
height:710px;
margin-top:-70px;
}
Here is the HtmL:
<div id="section"> <!-- navigation bar -->
<div class="navbar" id="nav">
Home
Contact
</div>
<div id="section-1"> <!-- first -->
<div class="row"></div></div></div>
Z-index only works on positioned elements, so giving your elements a position of relative should make it work.
As of:
https://www.w3schools.com/cssref/pr_pos_z-index.asp
probably do to you not using positions.
#section {
position: relative;
height: 70px;
z-index: 2;
padding-left: 10%;
padding-right: 10%;
clear: both;
max-width: 100%;
background-color: black;
}
#section-1 {
position: absolute;
text-align: center;
width: 50%;
height: 50%;
background-color: red;
opacity: 0.6;
}
<div id="section">
<div id="section-1"></div>
</div>
the element on which you are setting z-index property has its position property set to static. z-index requires the element's position set to anything except static - which is the default.
take a look here:
https://developer.mozilla.org/en/docs/Web/CSS/z-index?v=control
Your section-1 is a child of section. Children will always be above their parents. A z-index (which BTW is only active/valid on positioned elements) won't ever change that.
#section {
height: 70px;
z-index: 2;
padding-left: 10%;
padding-right: 10%;
clear: both;
max-width: 100%;
background-color: black;
}
#section-1 {
background: url(http://placehold.it/300x200/eb6);
max-width: 100%;
padding-top: 14%;
padding-bottom: 7%;
color: white;
height: 710px;
margin-top: -70px;
}
<div id="section">
<!-- navigation bar -->
<div class="navbar" id="nav">
Home
Contact
</div>
<div id="section-1">
<!-- first -->
<div class="row"></div>
</div>
</div>
I feel like this should be much easier than I am making it...I'm looking for a solution to have 1 solid color extend from the left and end at a logo, then have a second solid color extend all the way to the right. I want the wrapper divs to extend 100%. So something like:
<div id="header-wrap"><!--100% page width-->
<div id="header"><!--1000px centered fixed width-->
<div id="logo"></div><!-- align left-->
<div id="nav"></div><!-- align right-->
</div>
<div id="sub-header-wrap">
...
</div>
</div>
Here's an image showing what I mean:
There is a lot that goes into this.
Let me start of with a link to a working fiddle: JSFiddle
How can I explain this?
Basically I have the two full-width divs that have the full background color. Inside those two divs I have a div classified as .inner that has 80% of the width (which can be whatever you want) that is aligned to the center with margins.
Inside .inner I have a left div and a right div of the proper sizes to contain the logo/navigation. Inside the left divs, I have another div, .shade that will darken the left side of the header.
The .left divs are relatively positioned and the .shade divs are absolutely positioned.
CSS:
body{
margin: 0;
}
header
{
display:block;
width: 100%;
}
header .top
{
background: #00a;
text-align: center;
color: white;
}
header .inner
{
width: 80%;
margin: 0 10%;
text-align: left;
}
header .inner .logo, header .inner .left
{
display: inline-block;
width: 20%;
margin: 0;
text-align: center;
height: 100%;
padding: 10px 0px;
position: relative;
z-index: 1;
}
header .inner .right
{
display: inline-block;
width: 78%;
margin: 0;
text-align: right;
}
header li
{
display: inline-block;
list-style: none;
}
header .bottom
{
background: #ca0;
}
header .shade
{
width: 1000%;
height: 100%;
position: absolute;
top: 0px;
right: 0px;
background: rgba(0, 0, 0, .3);
z-index: -1;
}
HTML:
<header>
<div class="top" align="center">
<div class="inner">
<div class="logo">
Logo
<div class="shade"></div>
</div>
<div class="right">
<li>Nav 1</li>
<li>Nav 2</li>
</div>
</div>
</div>
<div class="bottom">
<div class="inner">
<div class="left">
Subtext
<div class="shade"></div>
</div>
<div class="right">
<li>Link</li>
</div>
</div>
</div>
</header>
Full JSFiddle
If I understand you correctly, try something like this in a separate CSS file, or within a <style> block. It's not tested though, sorry.
#header {
margin: 0 auto; /* for centering */
width: 1000px;
}
#logo {
float: left;
width: 250px; /* for example */
background-color: red; /* for example */
}
#nav {
float: right;
width: 750px; /* for example */
background-color: blue; /* for example */
}
UPDATE:
If you can afford CSS3, this post can be intresting for you as well.