Solved

Div extending beyond container

Posted on 2014-10-07
4
280 Views
Last Modified: 2014-10-07
I have a CSS class called "news".  It's within another div with a class called "content-wrapper".  When I add a 15px padding to the "news" class it pushes the left side beyond the "content-wrapper" div.  How do I fix this?

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>CSS Width Issue</title>
    <style type="text/css">
        .container {
            width: 100%;
            background-color:aqua;
            padding: 25px
        }

        .content-wrapper {
            width: 350px;
            background-color: red;  
            margin: 0 20px 0 0;
            float:left;  
            padding: 15px;        
        }

        .news {
            width: 100%;
            padding: 15px;
            background-color: blue;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="container">
        <div class="content-wrapper">
            <div class="news">
                Here's My News!
            </div>
        </div>
    </div>
    </form>
</body>
</html>

Open in new window

0
Comment
Question by:cdemott33
  • 2
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40367137
Add this css

* {
    box-sizing: border-box;
}

Open in new window

0
 

Author Comment

by:cdemott33
ID: 40367313
Hi Gary,

Sorry, no luck.  I even tried to remove the float: left to see if that was messing things up and it isn't.  Here's a screen capture and my updated code.  Any other ideas?

css-issue.jpg
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>CSS Width Issue</title>
    <style type="text/css">
		* {
		box-sizing: border-box;
		}

        .container {
            width: 100%;
            background-color:aqua;
            padding: 25px
        }

        .content-wrapper {
            width: 350px;
            background-color: red;  
            margin: 0 20px 0 0;
            padding: 15px;        
        }

        .news {
            width: 100%;
            padding: 15px;
            background-color: blue;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="container">
        <div class="content-wrapper">
            <div class="news">
                Here's My News!
            </div>
        </div>
    </div>
    </form>
</body>
</html>

Open in new window

0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40367320
Code is working fine.

http://jsfiddle.net/3phpuswm/
0
 

Author Comment

by:cdemott33
ID: 40367343
Looks like you helped me figure out the problem.  It turns out that I needed to remove this...

<!DOCTYPE html>

Open in new window


... from the top of the page and it worked.   Thanks for your help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now