adding margin-left creates horizontal scroll bar to white space - html

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)

Related

Div tags moving along when zooming

I am pretty new at HTML, and I am experimenting with some div tags to move along when zooming in or out the page. The structure of my HTML code is:
<header>
<div class="header">
<div class="title">
<h1>Here goes a title</h1>
</div>
<div class="logo">
<img class="logo" src="my/image/path.png">
</div>
</div>
</header>
And the corresponding CSS code:
header{
padding-left: 260px;
padding-top: 65px;
padding-right: 0px;
padding-bottom: 20px;
}
.title{
float: left;
width: 50%;
}
img.logo{
width: 243.77px;
height: 73.43px;
padding-top: 3px;
position: absolute;
}
Both my title and the logo image moves when zooming.
Any help would be appreciated.
Regards.
That is because you use the padding-left to change the position of the full header, but also you use the px unit which makes its position seems keep changing in different screen size.
A solution is to use percentage instead or use media screen query.
An off-topic suggestion, it is not always a good practice to use padding to change position, use margin is always better.
*This is an example use percentage you could change based on what you want.
header{
padding-left: calc(20vw);
padding-top:calc(5vh);
padding-right: 0;
padding-bottom: calc(10vh);
}
.title{
float: left;
width: 50%;
}
img.logo{
width: 243.77px;
height: 73.43px;
padding-top: 3px;
position: absolute;
}
<header>
<div class="header">
<div class="title">
<h1>Here goes a title</h1>
</div>
<div class="logo">
<img class="logo" src="my/image/path.png">
</div>
</div>
</header>

absolute positioned element extends past sticky footer

I have a dynamic mega menu item when opened the height varies depending on the data, often the height will cause the element to extend past the sticky footer (also position absolute), which is not really what i want at all, is there any solution other than creating unnesesary content to fill the void?
html -
<nav class="menu__base drop-shadow--standard desktop" style="background:#034774;;">
<div class="container">
<ul class="menu__items menu__items--hidden">
<li class="menu__item menu__sub-menu-item">nav item</li>
<li class="menu__item menu__sub-menu-item">nav item</li>
<li class="menu__item menu__sub-menu-item open">
<span class="menu__sub-menu-item__title">Open nav item</span>
<span class="menu__item__hover-underline"></span>
<div class="menu__sub-menu-wrapper drop-shadow--standard" style="height: 732px; left: -2px; background-color: #034774;">
<div class="menu__sub-menu" style="margin-top: 0px;">
<div class="menu__mega-menu">
<div class="mega-menu-multi-race ">
<table class="mega-menu-multi-race__table">
content, lots and lots of content inside the open nav item
</table>
</div>
</div>
</div>
</div>
</li>
<li class="menu__item menu__sub-menu-item">nav item</li>
</ul>
</div>
</nav>
<div class="container">
<p>
content inbetween
</p>
</div>
<div class="container">
<p>
more content
</p>
</div>
<div class="container">
<p>
more content.............
</p>
</div>
<footer class="container-fluid footer">
<section class="row">
<div class="container padding-all-10">
<div class="footer__info">
<div class="col-lg-6 col-md-6 col-xs-12 padding-lf-0">
<p class="margin-all-0">Sticky footer</p>
</div>
</div>
</div>
</section>
</footer>
css -
.menu__sub-menu-wrapper {
position: absolute;
top: 100%;
left: 0;
overflow: hidden;
margin-top: 2px;
left: -2px;
}
.menu__sub-menu {
left: 0;
top: 0;
}
.menu__item {
float: left;
position: relative;
border-right: solid 2px #053b5e;
font-weight: bold;
font-size: 17px;
list-style-type: none;
min-width: 100px;
text-align: center;
padding:5px;
}
.menu__items {
list-style-type: none;
margin: 0;
padding: 0;
float: left;
}
.footer {
width: 100%;
background:red;
font-size: 17px;
position: absolute;
bottom: 0;
}
link to fiddle - https://jsfiddle.net/2648daniel/wo3jxjb8/
Dan,
I have modified your fiddle a fair bit and have achieved what you are after. The menu no longer overlaps the footer and scales as required, based on a fixed height or whatever content within that block.
https://jsfiddle.net/2gLLkoks/7/
In summary I have used a combination of floating elements left/clearing the floats as appropriate. eg
.menu__sub-menu-wrapper {
float:left;
...
.menu__sub-menu {
float:left;
...
....
<div class="clear"></div>
</nav>
etc
I have also removed the absolute positioning from the elements and added a content wrapper which is absolutely positioned with a negative z-index so it appears under the sub menu.
.containerWrapper {position:absolute;top:50px;float:left;z-index:-1}
<div class="containerWrapper">
<div class="container">
<p>
more content...........
Hope this helps ;)

Prevent images from overlapping a fixed header

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.

Fixed image and content overlaps fixed sidebar as screen resolution/window size decreases

I have a page with the following structure:
<body>
<div id="page">
<div id="header-container">
<header>
</header>
</div>
<div id="main-container">
<div id="main" class="site-main">
<div id="sidebar-container">
<div id="sidebar">
</div>
</div>
<div id="content-container">
<div id="main-banner-container">
<div id="main-banner-holder">
<img id="main-banner" src="http://dummyimage.com/900x300/000/fff" />
</div>
</div>
<div id="content" class="content" role="main">
</div>
</div>
</div>
<div id="footer-container">
<footer>
<div id="footer-images">
</div>
</footer>
</div>
</div>
</div>
</body>
And formatted with the following CSS:
body {
margin: 0 auto;
width: 70%;
background-color: rgb(0,114,187);
font-family: verdana;
}
#header-container {
padding-bottom: 15px;
padding-top: 20px;
padding-left: 35px;
padding-right: 35px;
height: 190px;
}
header {
position: fixed;
width: 66%;
padding-top: 30px;
top: 0px;
}
#sidebar-container {
height:500px;
width:320px;
float:right;
}
#sidebar {
position: fixed;
color: rgb(211,34,52);
padding: 10px;
right: 16.5%;
top:226px;
}
#content-container {
width: 72%;
}
#main-banner-container {
max-width: 900px;
}
Viewing the page on a widescreen shows the content fine. However, as I reduce the window size, or if I view the site on a lower resolution screen, the fixed image and the text underneath it starts to obscure the sidebar, even though it does scale a little. Furthermore, when the page is scrolling, even though some of the text move to make space for the sidebar, the text below it overlaps when scrolled.
A rough example of the problem can be seen here: http://jsfiddle.net/4WQzP/
What changes do I need to make?
EDIT: To clarify, I was hoping a plain CSS/HTML based fix. Javascript is an option, though I'm trying to avoid it since I haven't really used it in this site so far.
for using an adaptive design used two ways)), the first is to use the bootstrap framework, the second is writing media queries

Unexpected gap right of header and footer when both are set with width:100%?

Problem
When using my phone to view a website i'm creating the site appears and seems to act differently than i expect?
I have a screenshot to demonstrate the problem on said smartphone screen.
Smartphone view
As you can see both the header and footer are not expanding 100% in width as they should, and do when viewed using a desktop browser.
Desktop view
Header CSS
#banner {
background-image: url(images/images/bannersketchBG.jpeg);
float: left;
height: 100px;
width: 100%;
font-size: 36px;
font-style: italic;
}
#banner1 {
float: left;
height: 50px;
font-style: normal;
margin-top: 10px;
padding-left: 10px;
color: #FFF;
font-size: 24pt;
top: 0px;
}
#banner2 {
float: left;
height: 30px;
width: 410px;
font-size: 14pt;
font-style: italic;
padding-left: 30px;
color: #FFF;
}
Footer CSS
.footer {
background-color: #2E2E2E;
word-spacing: normal;
float: left;
color: #FFF;
font-weight: bold;
width: 100%;
height: 100px;
bottom: 0px;
}
HTML
Header
<div align="center">
<div id="banner">
<div id="logo"><img src="images/Joel-Compass-black.png" width="119" height="95" alt="CCFS"></div>
<div id ="banner1">Columbus Car Finder Group</div>
<div id ="banner2">"Exploring your Needs"</div>
</div>
</div>
Footer
<div class="footer">
<div class="footercontainer">
<div id="footerTabsContainer">
<div class='tab one'>
<ul>
<li>Find My Car</li>
</ul>
</div>
<div class='tab two'>
<ul>
<li>About Us</li>
</ul>
</div>
<div class='tab three'>
<ul>
<li>How it Works</li>
</ul>
</div>
<div class='tab three'>
<ul>
<li>How it Works</li>
</ul>
</div>
<div class='tab five'>
<ul>
<li>Contact Us</li>
</ul>
</div>
<div class='tab six'>
<ul>
<li>Home</li>
</ul>
</div>
</div>
<div class="footerinfo">Web Design - CundyTech Copyright South West Car Finder 2013</div>
</div>
</div>
I notice the background image cuts off at the same point too, so could this be an overflow issue?!
Any help or pointers would be greatly appreciated!
PS i know i haven't quite got the finer points of css like using ID's and Classes properly but i am still learning so please dont hate on me too much!
Do not set div to width 100%, it expands by default. What you can try is to remove width property (from footer and header) and set min-width to be the same as your content's (it is a fixed width right?).
Do you have a link to the website that we can access? It is easy to test what works with Chrome/Firefox developer tools.
This generally happens when your content isn't enough to fill up the screen. I personally use calc() to sort it out. You can try this.
.your_header{
height:100px;
}
.your_content{
min-height:calc(100% - 300px);
}
.your_footer{
height:200px;
}
What it does is that it calculates min-height for your_content to 100% - height of your header - height of your footer;
Don't float your #banner or .footer. Check this cool tutorial on positioning to get a better idea: CSS Learn Positioning
Change the positioning of the footer to be fixed.
positioning: fixed; // will make the footer stick to the base of the viewport.
right: 0; // fill space to right
bottom: 0; // stick to the bottom of page
left: 0; // fill space to left
Notice we left out the top attribute... this is because we want that to be set automatically by the height of the inner elements.
You may also want to try position: absolute; and tweak the bottom padding on the body to give a result that will clear the body content and not stick to the viewport.
This should get you heading in the right direction.
As mentioned by #Linek in his answer, in the comments, adding a min-width style to body will solve this problem. I also had to add a min-width to the header, not sure why body didn't do both though?
Solution
Css
Body
{
min-width:1003px;
}