Prevent float right sections overlap the wrapper - html

I have every other section floated a different direction but the sections that are floated right overlap the wrapper. How do I get it to not do that?
Also, I tried incorporating the float into the nth-child (odd/even) of the css and I couldn't get it to work right. If someone can help me do that so I can get rid of the float classes I would be grateful.
http://codepen.io/anon/pen/bdoQPQ
body,
html {
font: 1em "Open Sans", sans-serif;
margin: 0px;
padding: 0px;
}
#wrapper {
padding: 0px 10px 0px 10px;
width: 100%;
}
.vertSection {
width: 75%;
height: 175px;
border-top: 1px solid black;
border-bottom: 1px solid black;
margin: 0px 0px 15px 0px;
padding: 5px 0px 0px 10px;
box-shadow: 0px 3px 5px #888, 0px -3px 5px #888;
display: inline-block;
}
.vertSection:nth-child(even) {
float: left;
}
.vertSection:nth-child(odd) {
float: right;
text-align: right;
}
.vertSection p {
text-align: left;
}
.vertSection img {
line-height: 75px;
}
.floatL {
float: left;
}
.floatR {
float: right;
}
.clear {
clear: both;
}
<section id="wrapper">
<section>
<h1>Header</h1>
<p>This is where some information on my services would go.</p>
</section>
<section class="vertSection">
<img src="images/html5css3.png" class="floatL">
<h2>Heading</h2>
<p>A bunch of text and description here!</p>
</section>
<section class="vertSection">
<img src="images/responsive.png" class="floatR">
<h2>Heading</h2>
<p>A bunch of text and description here!</p>
</section>
<section class="vertSection">
<img src="images/search.jpg" class="floatL">
<h2>Heading</h2>
<p>A bunch of text and description here!</p>
</section>
<section class="vertSection">
<img src="images/communicate.png" class="floatR">
<h2>Heading</h2>
<p>A bunch of text and description here!.</p>
</section>
</section class="">

The problem is likely related to this part.
#wrapper {
padding: 0px 10px 0px 10px; /*top right bottom left*/
width: 100%;
}
So 100% + 10px + 10px causes the overflow, remove width:100% it should all good. By the way, it's safer to also set section {display:block;} in case some browsers don't render it as block level element.

Related

section containing text overlaps a section containing an unordered list

Brand new html/css user here! I'm sure there's an easy and elegant way to solve this issue, but I haven't been able to find it.
I currently have four sections in my code, and the latter three seem to fall exactly how I would expect in relation to one another, one after the other, but the second one overlaps on top of the first one. I have gotten around this by adding an id to the second section that gives it some padding, but as you will notice, it is padding from the top of the page, not from the section above it. If I take that padding away, "About Me" overlaps on top of the background of the first section which contains the links.
#firstlink {
padding: 15px 50px 0px 0px
}
#linkbar {
background-color: blue;
height: 15%;
position: absolute;
top: 0;
left: 0;
width: 100%;
}
li {
font-size: 35px;
padding: 15px 10px 0px 0px;
float: right;
display: inline;
}
#aboutme {
padding: 75px 0px 0px 0px;
}
<section id="linkbar">
<ul>
<li id="firstlink">link1</li>
<li>link2</li>
<li>link3</li>
</ul>
</section>
<section id="aboutme">
<h1>About Me</h1>
</section>
<section>
<h1>My Portfolio</h1>
</section>
<section>
<h1>Contact Me</h1>
</section>
Have a look on this fiddle, i think it is what you want - https://jsfiddle.net/swarn_singh/tv25eq3g/
#firstlink {
padding: 15px 50px 0px 0px
}
#linkbar {
background-color: blue;
height: 15%;
top: 0;
left: 0;
width: 100%;
}
li {
font-size: 35px;
padding: 15px 10px 0px 0px;
float: right;
display: inline;
}
.clear{
clear: both;
}
#firstlink {
padding: 15px 50px 0px 0px
}
#linkbar {
background-color: blue;
width: 100%;
height: 15%;
display: inline-block;
}
ul{
list-style-type:none;
padding: 0px;
margin: 0px;
float: right;
}
ul li {
font-size: 35px;
padding: 15px 10px 0px 0px;
display: inline-block;
}
#aboutme {
padding: 75px 0px 0px 0px;
}
<section id="linkbar">
<ul>
<li id="firstlink">link1</li>
<li>link2</li>
<li>link3</li>
</ul>
</section>
<section id="aboutme">
<h1>About Me</h1>
</section>
<section>
<h1>My Portfolio</h1>
</section>
<section>
<h1>Contact Me</h1>
</section>

Main column not rendering even with side column

I have a two column layout the main content area renders down the page. Not even with aside. I wonder if I need a wrapper div?
or maybe my CSS not right?
I did not post of the CSS just what Thought maybe important
#charset "utf-8";
body {
font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
background: #FFF;
background-image:url(../assets/bg1.png);
margin: 0;
padding: 0;
color: #000;
}
.sidebar h4 {
padding-bottom: 0;
font-size: 13px;
color: #fff;
text-transform: uppercase;
font-weight: normal;
padding: 7px 7px;
border-bottom: 1px solid #A31923;
background-color: #DE2D3A;
}
/* ~~this fixed width container surrounds the other divs~~ */
/*#container {
width: 960px;
margin: 20px auto;
padding: 10px;
box-shadow: 0 5px 5px 5px #CCCCCC;
background-color: #fff;
}*/
.container {
width: 1260px;
margin: 20px auto;
padding: 10px;
background: #FFF;
box-shadow: 0 0 5px 5px #B8B8B8;
/*margin: 0 auto; the auto value on the sides, coupled with the width, centers the layout */
}
.sidebar {
float: left;
width: 180px;
margin-top: 10px;
}
.sidebar h4 {
padding-bottom: 0;
font-size: 13px;
color: #fff;
text-transform: uppercase;
font-weight: normal;
padding: 7px 7px;
border-bottom: 1px solid #A31923;
background-color: #DE2D3A;
}
.footer {
padding: 10px 0;
background: #CCC49F;
position: relative;
clear: both;
}
.fltrt {
float: right;
margin-left: 8px;
}
.fltlft {
float: left;
margin-right: 8px;
}
.clearfloat {
clear:both;
height:0;
font-size: 1px;
line-height: 0px;
}
.clear {
clear: both;
}
<body>
<div class="container">
<header>
<h2>our website slogan here with header image</h2>
</header>
<nav>
<ul>
<li>X</li>
<li>X</li>
</ul>
</nav>
<aside class="sidebar">
<ul>
<li>
<h4>X</h4>
<ul>
<li>X</li>
<li>X</li>
</ul>
</li>
</ul>
</aside>
<main>
<section>
<article>
<h2>CCCC</h2>
<p>CCC</p>
</article>
<article>
<h1>xXX<h1>
<h2>XXX</h2>
<p>XX</p>
</article>
<article>
<h2>XXX</h2>
<p>V</p>
</article>
</section>
</main>
<div class="clear"></div>
<footer>
<p>XXX.</p>
</footer>
</body>
</html>
I wonder if I need a wrapper div?
Not really, you can achieve it without an additional wrapper.
or maybe my CSS not right?
That is the question, your CSS could be much better. You are using float, and unless there is a good reason behind its use, we are on 2017: use flexbox instead and forget float elements for a time.
Your example hasn't the full code, so I will do a simple code snippet with a full width header, a 180px aside with the main content next to it, and a full width footer. All of this within only one wrapper: the .container element.
span{
display: block;
color: white;
padding: 1rem;
}
.container{
display: flex;
flex-wrap: wrap;
}
header{
width: 100%;
min-height: 50px;
background-color: #e74c3c;
}
aside{
flex-basis: 180px;
min-height: 300px;
background-color: #f1c40f;
}
main{
flex: 1;
min-height: 300px;
background-color: #f39c12;
}
footer{
width: 100%;
min-height: 80px;
background-color: #2ecc71;
}
<div class="container">
<header>
<span>Header</span>
<!-- Put your content here -->
</header>
<aside>
<span>Aside</span>
<!-- Put your content here -->
</aside>
<main>
<span>Main</span>
<!-- Put your content here -->
</main>
<footer>
<span>Footer</span>
<!-- Put your content here -->
</footer>
</div>

Two Div's Are not aligning side by side

I have read almost every post on here about divs not lining up side by side but none of them apply to me.
It seems like I am missing a float:left; on both blocks but for whatever reason, they are not honoring that. If I do float:right; to the right container, then it just pushes the right container under the left container.
So far I have tried css attributes:
float: right and left;
display: in-line;
display: block;
width of both left nav and right container
It seems to me like the "main container" is preventing the right container from moving up but, this div is inside that container. I have also tried z-index, and position.
what am I doing wrong here?
body {
font-family: Arial, Helvetica, sans-serif !important;
background: URL("http://www.mscdirect.com/global/application-content/images/header/ribbon-bg-1.gif") repeat-x scroll top left;
clear: both;
}
#header {}
#content-container {
width: 961px;
}
.top-container {
border-bottom: 1px solid #ccc;
cursor: pointer;
font-size: 14px;
font-weight: bolder;
margin: 5px 0px 0px 20px;
padding: 10px 0 18px;
text-align: center;
text-transform: uppercase;
}
.reg-text {
font-weight: normal;
text-transform: uppercase;
font-size: 12.5px;
cursor: pointer;
}
.red-text {
color: #db403b;
font-size: 18px;
text-transform: uppercase;
cursor: pointer;
}
.left-container {
width: 262px;
border: 1px solid #ccc;
margin: 20px 0px 0px 20px;
}
.left-nav {
width: 245px;
margin-top: 10px;
}
.left-nav-head {
text-transform: uppercase;
width: 208px;
margin: 0px 0px 6px 7px;
padding: 5px 20px 3px 14px;
font-size: 12px;
list-style-image: none;
color: #fff;
background: #345599;
}
.left-nav li {
background: rgba(0, 0, 0, 0) url("http://www.mscdirect.com/global/application-content/images/content/contentArrow2.gif") no-repeat scroll 16px 7px;
list-style: inside none none;
margin: 0px 0px 5px 5px;
padding: 4px 16px 6px 27px;
font-size: 13px
}
.right-container {
width: 662px;
display: block;
}
ul {
list-style: none;
}
li:nth-child(odd) .prod-text-box {
float: left;
}
li:nth-child(odd) .prod-img-box {
position: relative;
padding-right: 100px;
}
#main-container {
width: 961px;
margin: 0px auto;
}
a {
text-decoration: none;
color: #2866B1 !important;
font: bold 12px Arial, Helvetica, sans-serif !important;
text-decoration: none;
padding: 5px 0 5px
}
a:hover:visted:link {
color: #2866B1 !important;
font: bold 12px Arial, Helvetica, sans-serif !important;
text-decoration: none;
padding: 5px 0 5px
}
.product-content {
float: left;
border: 1px solid #ccc;
width: 664px;
margin-left: 300px
}
.prod-box {
width: 644px;
border-bottom: 1px solid #ccc;
float: left;
clear: both;
margin: 0px 0px 10px 13px;
min-height: 200px;
}
.prod-img-box {
overflow: hidden;
margin-top: 20px;
float: right;
position: absolute;
}
.prod-text-box {
width: 272px;
position: relative;
float: right;
clear: both;
}
.prod-title {
font-size: 26px;
color: #00337a;
line-height: 30px;
text-align: left;
padding-top: 10px;
clear: both;
}
.prod-cta {
color: #2866B1 !important;
font: bold 12px Arial, Helvetica, sans-serif !important;
text-decoration: none;
padding: 5px 0 5px;
clear: both;
}
</style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> <!-- IE is not seeing HTML5 tags so I added this to fix that --> <!--[if lt IE 9]> <script> document.createElement('header');
document.createElement('nav');
document.createElement('section');
document.createElement('article');
document.createElement('figure');
document.createElement('figcaption');
document.createElement('footer');
</script> <![endif]-->
<div id="main-container">
<div id="header"><img src="header.png" width="961px" height="144px"></div>
<div class="top-container">save up to <span class="red-text">25% </span>on orders over <span class="red-text">$249</span> + get free shipping when you order online.<span class="reg-text"> enter code:</span> ALL25H <span class="reg-text">click to apply ►</span></div>
<div id="content-container">
<div class="left-container">
<!-- Left Navigation -->
<div class="left-nav">
<div class="left-nav-head">Head Protection</div>
<ul>
<li>Hard Hats</li>
<li>Bump Caps</li>
<li>Welding Helmets</li>
<li>Face Sheilds</li>
<li>Winter Liners</li>
</ul>
</div>
<!-- Products Section -->
<div class="right-container">
<div class="product-content">
<ul>
<li>
<a name="hardhat"></a>
<div class="prod-box">
<div class="prod-text-box">
<div class="prod-title">Hard Hats</div>
Protect yourself from minor head and neck injuries with the comfort and reliability of bump caps. Choose from a variety of styles, colors, and adjustment types.
<div class="prod-cta">Shop Bump Caps<span>►</span></div>
</div>
<div class="prod-img-box"><img src="images/hardhat.jpg" alt="Hard Hats"></div>
</div>
</li>
<li>
<a name="bumpcaps"></a>
<div class="prod-box">
<div class="prod-text-box">
<div class="prod-title">Bump Caps</div>
Protect yourself from minor head and neck injuries with the comfort and reliability of bump caps. Choose from a variety of styles, colors, and adjustment types.
<div class="prod-cta"><a class="prod-cta" href="/browse/tn/Safety/Personal-Protective-Equipment/Hard-Hats-Bump-Caps/Bump-Caps?navid=12106709&rdrct=Bump+Caps&intcmp=BumpCaps_SafetyHeadProtectionStaticPage_CTA_April2016_v1">Shop Bump Caps<span>►</span></a></div>
</div>
<div class="prod-img-box"><img src="images/hardhat.jpg" alt="Hard Hats"></div>
</div>
</li>
<li>
<a name="bumpcaps"></a>
<div class="prod-box">
<div class="prod-text-box">
<div class="prod-title">Bump Caps</div>
Protect yourself from minor head and neck injuries with the comfort and reliability of bump caps. Choose from a variety of styles, colors, and adjustment types.
<div class="prod-cta"><a class="prod-cta" href="/browse/tn/Safety/Personal-Protective-Equipment/Hard-Hats-Bump-Caps/Bump-Caps?navid=12106709&rdrct=Bump+Caps&intcmp=BumpCaps_SafetyHeadProtectionStaticPage_CTA_April2016_v1">Shop Bump Caps<span>►</span></a></div>
</div>
<div class="prod-img-box"><img src="images/hardhat.jpg" alt="Hard Hats"></div>
</div>
</li>
<li>
<a name="bumpcaps"></a>
<div class="prod-box">
<div class="prod-text-box">
<div class="prod-title">Bump Caps</div>
Protect yourself from minor head and neck injuries with the comfort and reliability of bump caps. Choose from a variety of styles, colors, and adjustment types.
<div class="prod-cta"><a class="prod-cta" href="/browse/tn/Safety/Personal-Protective-Equipment/Hard-Hats-Bump-Caps/Bump-Caps?navid=12106709&rdrct=Bump+Caps&intcmp=BumpCaps_SafetyHeadProtectionStaticPage_CTA_April2016_v1">Shop Bump Caps<span>►</span></a></div>
</div>
<div class="prod-img-box"><img src="images/hardhat.jpg" alt="Hard Hats"></div>
</div>
</li>
<li>
<a name="bumpcaps"></a>
<div class="prod-box">
<div class="prod-text-box">
<div class="prod-title">Bump Caps</div>
Protect yourself from minor head and neck injuries with the comfort and reliability of bump caps. Choose from a variety of styles, colors, and adjustment types.
<div class="prod-cta"><a class="prod-cta" href="/browse/tn/Safety/Personal-Protective-Equipment/Hard-Hats-Bump-Caps/Bump-Caps?navid=12106709&rdrct=Bump+Caps&intcmp=BumpCaps_SafetyHeadProtectionStaticPage_CTA_April2016_v1">Shop Bump Caps<span>►</span></a></div>
</div>
<div class="prod-img-box"><img src="images/hardhat.jpg" alt="Hard Hats"></div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
You currently have your markup set up like this:
<container>
<left-container>
<left-nav></left-nav>
<right-container></right-container>
</left-container>
</container>
It needs to be:
<container>
<left-container>
<left-nav></left-nav>
</left-container>
<right-container></right-container>
</container>
The left-container does not span the entire width of the container. From there you add
float: left;
to your left-nav and
float: right;
to your right-container and you should be all set!
What #kiaanabal said and a position absolute in your css on the left container would be quite useful too.
.left-container {
position: absolute;
width: 262px;
border: 1px solid #ccc;
margin: 20px 0px 0px 20px;
float: left;
overflow: auto;
}
http://codepen.io/Thrizian/pen/zBOZNE?editors=1100

Text flowing in CSS

Got problem with image nad text flowing.
I have image, from the right side text, but if height of text div becomes more then image div height the is beeing written from the new line under the picture, i don't need that. How to create something like
My code:
HTML:
<div id="wrapper">
<div id="content">
<div id="image" class="fleft"><img src="img/image.png" alt="dart-face"/></div>
<div id="text">
<h1>Darth Vader</h1>
<p>Darth Vader (born Anakin Skywalker) is a central character in the Star Wars saga,[1][2][3] appearing as one of the main antagonists of the original trilogy and as the main protagonist of the prequel trilogy.
<p>The character was created by George Lucas and numerous actors have portrayed him. His appearances span all six Star Wars films, and he is an important character in the expanded universe of television series, video games, novels, literature and comic books.</p>
</p>
</div>
</div>
</div>
CSS:
*{
margin: 0;
padding: 0;
}
body
{
font: 12px Arial, Helvetica, sans-serif;
background: url('../img/pattern.png');
}
#wrapper
{
max-width: 80%;
margin: 50px auto;
-webkit-box-shadow: 0 5px 13px rgba(0,0,0,0.75);
-moz-box-shadow: 0 5px 13px rgba(0,0,0,0.75);
-o-box-shadow: 0 5px 13px rgba(0,0,0,0.75);
-ms-box-shadow: 0 5px 13px rgba(0,0,0,0.75);
box-shadow: 0 5px 13px rgba(0,0,0,0.75);
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
-o-border-radius: 10px;
-ms-border-radius: 10px;
border-radius: 10px;
background: -webkit-linear-gradient(#d8d8d8,#fff,#fff,#c0c0c0);
background: -moz-linear-gradient(#d8d8d8,#fff,#fff,#c0c0c0);
background: -o-linear-gradient(#d8d8d8,#fff,#fff,#c0c0c0);
background: -ms-linear-gradient(#d8d8d8,#fff,#fff,#c0c0c0);
background: linear-gradient(#d8d8d8,#fff,#fff,#c0c0c0);
}
#content
{
display: inline-block;
/*position: relative;*/
}
#image
{
margin: 34px;
}
#text
{
/*position: absolute;*/
line-height: 20px;
text-align: left;
margin: 34px 25px 25px 25px;
}
#text h1, #text p
{
margin-bottom: 20px;
}
.fleft
{
float: left;
}
.fright
{
float: right;
}
Set overflow:hidden to #test to trigger its layout so it sees and stands away from floatting element around it and keep his inside .
#text {
overflow:hidden;/* triggers layout , so it cares about inside and outside floatting elements */
line-height: 20px;
text-align: left;
margin: 34px 25px 25px 25px;/* you might need to reset these since it will bang against floatting image */
}
Can also try this...The following code will easily fix the issue.
Here is updated HTML...Posting only updated part
<div id="content">
<div id="image"><img src="img/image.png" alt="dart-face"/></div>
<div id="text">
<h1>Darth Vader</h1>
<p>
Darth Vader (born Anakin Skywalker) is a central character in the Star Wars saga,[1][2][3] appearing as one of the main antagonists of the original trilogy and as the main protagonist of the prequel trilogy.
<p>
The character was created by George Lucas and numerous actors have portrayed him. His appearances span all six Star Wars films, and he is an important character in the expanded universe of television series, video games, novels, literature and comic books.
</p>
</p>
</div>
<div style="clearfix"> </div>
</div>
Now we have to remove unwanted code from CSS
Please remove following code from your CSS (same one to posted in question)
#image
{
margin: 34px;
}
#text
{
/*position: absolute;*/
line-height: 20px;
text-align: left;
margin: 34px 25px 25px 25px;
}
.fleft
{
float: left;
}
.fright
{
float: right;
}
Now simply add the following CSS
#image
{
float: left;
width:30%; /*Choose width accordingly*/
}
#text
{
float: left;
width:60%; /*Choose width accordingly*/
}
.clearfix
{
display:block;
clear:both;
content:'';
}
try this hope this help....and if any query ? donot hesitate to comment THANKS

div inside a div vertical in a side bar using css

i have a page that i need to have a left side bar that this one contain a a title under that an image under that a text under that a list how can i do this i tried the relative position and absolute but it did not work
what i need is a div inside a div means the leftsidebar is a div that include the the title , image, text, list.
can anyone help me ?????
this what i tried to do to the image
.leftsideBar h2 {
padding: 0px 0px 30px 0px;
letter-spacing: -1px;
font-size: 2em;
}
.leftsideBar {
float: left;
width: 290px;
padding: 0px 0px 20px 0px;
border:5px solid #FF0000;
position:relative;
}
#profileImage{
position:absolute;
top:40px;
border:5px solid #0000FF;
}
Is this fiddle what you are trying to achieve?
html:
<div class="leftsideBar">
<h2>title</h2>
<img src="" height="100" width="100"/>
<ul>
<li>test1</li>
<li>test1</li>
<li>test1</li>
<li>test1</li>
</ul>
</div>
css:
.leftsideBar h2 {
padding: 0px 0px 30px 0px;
letter-spacing: -1px;
font-size: 2em;
}
.leftsideBar {
float: left;
width: 290px;
padding: 0px 0px 20px 0px;
border:5px solid #FF0000;
position:relative;
}
#profileImage{
border:5px solid #0000FF;
}
here it is another option with the text next to the image -> fiddle2