Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Div extending beyond container

Posted on 2014-10-07
4
Medium Priority
?
306 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

876 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