Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

p element inside div is wider than the parent div

Take a look at the link. The p element within it's parent has more width. I want to display p within the dialog box. How would I do this?

http://jsfiddle.net/2y1wj0mm/

.dialog-box {
margin:0 auto;
width:300px;
height:200px;
background-color:#326A16;
-webkit-filter:drop-shadow(0px 0px 5px #000000);
border-radius:20%/34%;
}
.dialog-box:before {
content:"";
position: absolute;
width: 0px;
height: 0px;
border-right: 21px solid transparent;
border-left: 18px solid transparent;
border-top: 42px solid #326A16;
margin:195.71428571428572px 90px;
}
.dialog-box p {
display:inline;
margin:10% 14%;
text-wrap:normal;
}
like image 323
arvind Avatar asked Mar 27 '15 07:03

arvind


People also ask

Why child div is bigger than parent?

A child div can also be wider than its parent by utilizing different positioning such as absolute or fixed positioning. Different results can occur depending on the specified position of the parent div but as long as the element is either absolute/fixed or contains a specified width, it will grow outside the parent.

How do you make a div bigger than a parent?

- First set the width of the extended-content-container div to 500%. This will make the div you are trying to extend 5 time wider than the center column it lives inside. This can be adjusted up or down depending on the size of the center column you are working with.

Does div take up remaining width?

The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent. Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.

Does padding increase div size?

Any padding added to the element will increase the total computed width and/or height of the element—this is how the default box model works in regards to sizing the element.


1 Answers

Update your .dialog-box:

.dialog-box p {
    display: block;
    margin:10% 14%;
    width: 200px;
    word-wrap: wrap;
    word-break: break-all;
    padding-top: 30px;
}

3 things to do here:

  1. display: inline does not work in your case; you have to use the width & height of p element
  2. You have to wrap & break the words using word-wrap and word-break
  3. You probably need to place the words inside the green dialog, using padding-top

Side note:

There is no point to set margin with so many decimal places. Use integers only.

Demo: http://jsfiddle.net/9bpyjnfL/1/

like image 123
Raptor Avatar answered Sep 20 '22 02:09

Raptor