I am trying to make my webpage more responsive but I am struggling to figure out the cause of this problem here: https://imgur.com/a/QIPdJnp and https://imgur.com/a/3UNzAVF
my website looks okay with high width viewport values like for iPads and desktops, but when the width of the view port is small like less than 360px, my footer header has this empty white space that gets created between it and the right edge of the screen as i showed above.
it seems like that the CSS grid and "experience" header stick out just way too much to the right which causes things like the footer (which properly fits the screen width) appear as if it is not fitting the screen width.
here is the code for the header (resides inside CSS grid section) that is pushing too much to the right. If I can find out what's wrong here, I can apply this to the CSS grid.
<main class = "gallery-page">
<div class="col-lg-12 text-center">
<h2 class="section-title">Experience</h2>
</div>
</main>
h1, h2, h3, h4, h5, h6 {
color: #000;
font-family: "Playfair Display", serif;
line-height: 1.2;
}
h2, .h2 {
font-size: 60px;
}
#media (max-width: 250px) {
h2, .h2 {
font-size: 40px;
}
}
CSS provides two properties that could be used to implement your request namely position and display. I will not really cover display here or advanced items like flex, let's focus on position, and bootstrap.
I noticed you are using "col-lg-12", "section-title", "text-center" as a class. This class comes from a framework like bootstrap. Bootstrap has it's own header that you could use called NavBar. Also the col-lg-12 is part of the grid layout in bootstap. I assumed bootstrap here, but there are other frameworks with similar constructs like Material.
Let's implement your html and css with some minor changes. Here we will use pure css without a framework, I will show you how to implement a NavBar later.
I changed the body background to blue as follows:
body {
background-color: blue;
}
I then implemented your css as follows:
<style>
h1, h2, h3, h4, h5, h6 {
font-family: "Playfair Display", serif;
line-height: 1.2;
}
h2, .h2 {
font-size: 60px;
}
.header {
background-color: purple;
color: white;
}
#media (max-width: 250px) {
h2, .h2 {
font-size: 40px;
}
}
</style>
<main class = "gallery-page">
<div class="text-center header">
<h2 class="section-title">Experience</h2>
</div>
<div> tmp text here </div>
</main>
Notice I change the text to white and the heading to purple. The result is as follows:
To see what happens with some text and some scroll bars I added some temp text:
When it scrolls the head moves up, and if we change the screen size it appears as follows:
The position property of css provides the following five options:
static
relative
fixed
absolute
sticky
Static is the default and are not affected by the top, bottom, left, and right properties, specified by position. Your header is an example of static.
Relative is positioned relative to its normal position. Setting the top, right, bottom, and left properties of a relatively-positioned element will cause it to be adjusted away from its normal position. Other content will not be adjusted to fit into any gap left by the element.
Let's change the header to relative:
.header {
background-color: purple;
color: white;
position: relative;
}
Notice nothing changes, but now we can move this relative to its position, so for example left 30px.
.header {
background-color: purple;
color: white;
position: relative;
left: 30px;
}
As you can see this moves your header relative to it's position, scrolling behaves like before.
Let's change the position to fixed as follows:
.header {
background-color: purple;
color: white;
position: fixed;
}
Now something strange happens, for one the block is larger, and two you can scroll the text below while the block remains in the same place. This is because fixed is relative to the view-port and not the window. You can control what is above (header) or below (the text) by setting the z-index.
We can also reposition where in the view-port we want the header by changing it's position. Like before we could use left 30px:
.header {
background-color: purple;
color: white;
position: fixed;
left: 30px;
}
But unlike before it is now squashed and does not disappear to the right. We can also use top, bottom etc.
Let's position it at the top, left, right, with a smaller height:
.header {
background-color: purple;
color: white;
position: fixed;
top: 0px;
left: 0px;
right: 0px;
}
The window will be responsive:
Absolute is similar to fixed except now the element is fixed to the nearest position ancestor in this case body and not the view port.
.header {
background-color: purple;
color: white;
position: absolute;
top: 0px;
left: 0px;
right: 0px;
}
While it looks similar to before, with the text underneath, scrolling the page will show that the header moves with the body and is no longer fixed to the view-port:
In these examples I have showed you how you can use position to get the effect of a header that you want.
Let's revert back to your original html, and include the bootstrap framework, note that I am keeping the poor choice in colours:
<style>
h1, h2, h3, h4, h5, h6 {
font-family: "Playfair Display", serif;
line-height: 1.2;
}
h2, .h2 {
font-size: 60px;
}
.header {
background-color: purple;
color: white;
}
#media (max-width: 250px) {
h2, .h2 {
font-size: 40px;
}
}
</style>
<main class = "gallery-page">
<div class="col-lg-12 text-center header">
<h2 class="section-title">Experience</h2>
</div>
<div>
some text
</div>
</main>
The result is as follows:
From the bootstrap examples you can see the rendering is I assume as you expected, I do not have the rest of your html, and so I do not know why you are getting strange behavior, it could be you have wrapped the code with a container, or the footer is rendered with other tags.
Let's implement a NavBar.
You can do this with the following HTML:
<main>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
Experience
</div>
</nav>
<div>
</div>
</main>
In addition html provides tags for headers and footers.
So let's update the html to include a bootstrap NavBar using the header tag, and leave the main for the body.
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
Experience
</div>
</nav>
</header>
<main>
<div>
</div>
</main>
We can now implement the footer tag as follows:
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
Experience
</div>
</nav>
</header>
<main>
<div>
some content
</div>
</main>
<footer class="footer bg-light">
<div class="container">
<span >My footer</span>
</div>
</footer>
Notice I am using the footer tag, with a bootstrap footer class and bg-light class. The footer is added at the bottom, and if we scroll we can see it:
Scrolling also moves the header up, we can fix both by making them fixed.
We could use bootstrap to fix it, but let's use the CSS we used above, and we will add it as a class.
Add the following css:
.header-top {
position: fixed;
top: 0px;
left: 0px;
right: 0px;
}
.footer-bottom {
position: fixed;
bottom: 0px;
left: 0px;
right: 0px;
}
Use the tags in your html as follows:
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light header-top">
<div class="container-fluid">
Experience
</div>
</nav>
</header>
<main>
<div>
some contents
</div>
</main>
<footer class="footer bg-light footer-bottom ">
<div class="container">
<span >My footer</span>
</div>
</footer>
The result are fixed headers and footers:
Related
For some reason, I was able to achieve what I wanted earlier in the day, but now when I am trying to re-create my code, it won't replicate.
I want two header elements, h2 and h3, centered-aligned in one div row, within the jumbotron section.
Then, I want to add bottom-margin to the h3 element to lift it slightly above the h2 element, like in the photo.
I still have my original code in hand, but even after copynpasting the exact code with the same styling, the h3 element ends up being directly below h2.
I have tried cross-referencing with dev tools, and i found that the only difference is the div row containing the h2 and h3 elements is missing display:flex, but it's still not working.
what i want to happen
what is happening
Original Working Code:
HTML:
<section class="jumbotron">
<div class="container">
<div class="row">
<h2>Jumbotron</h2>
<h3>Bootstrap</h3>
</div>
</div>
</section>
CSS:
.jumbotron {
display: flex;
align-items: center;
background-image: url('https://images.unsplash.com/photo-1665956600293-4511bd26ea98?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2787&q=80');
background-size: cover;
color: #ffffff;
height: 400px;
}
.jumbotron h2 {
font-size: 60px;
font-weight: 700;
margin: 0;
color: ;
}
.jumbotron h3 {
margin: 0 0 20px;
color: #fff;
}
Thank you for your help!
change row class with d-flex like
<section class="jumbotron">
<div class="container">
<div class="d-flex">
<h2>Jumbotron</h2>
<h3>Bootstrap</h3>
</div>
</div>
</section>
I'm writing the CSS for my site. I have text that I am putting on top of my background image. My HTML and CSS is below:
HTML
<header class="site-header">
<div class="site-header__menu-icon">
<div class="site-header__menu-icon__middle"></div>
</div>
<div class="site-header__menu-content">
<div class="site-header__btn-container">
Request A Demo
</div>
<nav class="primary-nav primary-nav--pull-right">
<ul>
<li>Home</li>
<li>Services</li>
<li>Why Us</li>
</ul>
</nav>
</div>
</div>
</header>
<div class="section">
<picture>
<img src="assets\images\pepper.jpg">
</picture>
<div>
<div class="section__text-content">
<h1 class="section__title">Company</h1>
<h3 class="section__sub-title">Company Slogan</h3>
<div class="btn-container">
<a class="btn" href="#">Talk To A Specialist</a>
<a class ="btn btn__white btn__pepper-white" href="#">Get A Quote</a>
</div>
</div>
</div>
</div>
CSS
.section {
position: relative;
max-width: 100%;
&__text-content {
position: absolute;
top: 30%;
width: 100%;
margin-left:
}
&__title {
font-size: 7rem;
font-weight: 300;
color: #ffffff;
margin-bottom: 0;
}
&__sub-title {
font-size: 2.5rem;
font-weight: 300;
margin-top: 3%;
margin-bottom: 2%;
color: #ffffff;
}
}
The problem arises when I try to add a margin-left to the .section class in my CSS, because then a blank which space to the right of my screen appears with a horizontal scroll bar in direct proportion to the amount of margin I specified to move to the left.
I know that I could use a simple "background-image" for my css, but I'd prefer to do it this way for responsive imaging (it's how I learned to do it and I'm on a bit of a time crunch).
Any suggestions?
FIXED
My problem was I was writing my margin in relative terms by doing:
.section__text-content {
position: absolute;
margin-left: 10%
}
Which is wrong, because the &__text-content is set to position: absolute
Percentage is relative position, with an absolutely positioned image you need absolute margins (i.e. pixels)
The problem is about-me section is slightly more wider than the header section even though they both have the same width.You can even observe this in the picture. Blue background is header section inspected in console and white area is the about me section This is also showing the side navigation bar on the bottom which is trouble some.
<!--Header Section -->
<section id="header">
<div class="header-bg-overlay">
<div class="header-bg">
<div class="container">
<div class="hero-content">
</div>
</div>
</div>
</div>
</section>
<section id="about-me">
<div class="about-section">
</div>
</section>
CSS
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: 'Montserrat', sans-serif;
}
h5{
color:white;
font-size:75px;
font-weight: bold;
}
h4{
color:white;
font-size:55px;
font-weight: bold;
}
body{
font-family: 'Roboto', sans-serif;
margin:0;
padding: 0;
}
.header-bg{
width:100vw;
height: 100vh;
background-color: black;
background: url('../assets/background.jpg')no-repeat center;
background-position: -30px -80px;
}
#about-me{
width:100vw;
height: 100vh;
background-color: #FFFFFF;
box-sizing: border-box;
}
Try to change the width of both the sections to 100%
vw = document + scrollbar.
Fix:
.header-bg, #about-me {
width: 100vw;
max-width: 100%
}
Space and new line characters in your HTML code are rendered as one-character space in the browser. Because of that, actually there is another element in addition to the box with 100vw and 100vh dimensions and this causes the overflow.
You have two options:
Remove the new line and space characters before the opening tag and after the closing tag of the .header-bg element. These tags should be in touch with the tags of the parent element.
Use display:flex on parent element. Contrary to other display options, flexbox does not render space characters around its children.
I have a fixed header with three tabs. On the rest of the page I have both text and images. I was able to have text scroll "under" the fixed header but the images overlap. I tried setting the background of the header as an image but that did not work. I also tried various z-index values but also lacked results. I'm posting the CSS with no z-index on the header because it doesn't affect the fixed header in terms of the overlap problem, but only shifts it off-center. Is there a way to fix this with CSS?
Thanks
HTML Code:
<div class="header">
<div class="container">
<ul class="pull-right nav nav-pills">
<li>tab1</li>
<li>tab2</li>
<li>tab3</li>
</ul>
</div>
</div>
<div class="content">
<div class="container">
<p>text here</p>
<img src="image.jpg"/>
<p>more text</p>
</div>
</div>
CSS code:
body {
width: 100%
margin: auto;
background-color: #f7f7f7;
}
.header {
background: #FFFFFF;
position: fixed;
top: 0;
width: 100%
}
.toolbar a {
font-family: 'Raleway', sans-serif;
color: #5a5a5a;
font-size: 13px;
font-weight: bold;
text-transform: uppercase;
}
.toolbar li{
display: inline;
}
.content {
margin-top:100px;
z-index:10;
}
<div class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!--Tabs Here-->
</div>
</div>
You have to use a Bootstrap feature (navbar) as opposed making the div a fixed element at the top of the page.
I have a page using boostrap layout.
<body>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
//All menu stuff occuping all the width of the top.
</div>
//Jumbotron rendering body of views.
<div class="jumbotron">
#RenderBody()
</div>
</body>
The jumbotron CSS:
.jumbotron {
height: 100%;
padding-top: 80px;
padding: 40px;
margin-bottom: 0px;
font-size: 15px;
font-weight: 100;
line-height: 2.1428571435;
color: inherit;
}
I have a view with a telerik grid, and when it is displayed on the screen it fits behind the Menu. Becouse the jumbotron is taking 100% i think. So, how can i fit the jumbotron below the menu, separating them?
Remove the navbar-fixed class from your nav like so:
<div class="navbar navbar-default" role="navigation">
If you want a fixed navbar, add a padding top: 30px (equal to the height of your navbar) to body
body {
padding: 30px 0 0;
}