I set a div's width to 100% of the window. When I apply a border to this div, the right border is cut off. Do I have to perform a box model hack to this?
#textBoxContainer { width:100%; height:30%; position:fixed; z-index:99; bottom:0px; left:0px; background-color:#999; border: 4px solid #000; }
<div id="textBoxContainer"></div>
It seems like this should be one of the easiest things to understand in CSS. If you want a block-level element to fill any remaining space inside of its parent, then it's simple — just add width: 100% in your CSS declaration for that element, and your problem is solved.
CSS Border Not Showing If you've set the shorthand border property in CSS and the border is not showing, the most likely issue is that you did not define the border style. While the border-width and border-color property values can be omitted, the border-style property must be defined. Otherwise, it will not render.
To convert it to a fixed-width layout, simply add a fixed with to the #wrapper and set the margins to auto. Setting the margins to auto will cause the left and right margins to be equal no matter how wide the browser window is, which will cause your fixed-width layout to be positioned in the center of the browser.
Already has been answered, but I like this solution better. Add this to textBoxContainer:
-webkit-box-sizing: border-box; -moz-box-sizing: border-box; -ms-box-sizing: border-box; box-sizing: border-box;
It will put the border on the inside of the box. More info: http://css-tricks.com/box-sizing/
Edit - Doesn't work on IE7, but not much does. Here's more on that: box-sizing support in IE7
The easiest fix in your case is this:
#textBoxContainer { height: 30%; position: fixed; z-index: 99; bottom: 0; left: 0; right: 0; background-color: #999; border: 4px solid #000; }
<div id="textBoxContainer"></div>
Live Demo
width: 100%
.div
fill the screen, instead add right: 0
.It's perfectly viable to give an element both a left
and a right
(or a top
and a bottom
), like we're doing here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With