How to make div width almost 100%
Tags: html,css
Problem :
I have such a html code:
<div id="outer">
<div id="inner"></div>
</div>
How can I make #inner div to have width 100% of #outer but minus 10px?
Here is my css:
#outer {
width: 100%;
max-width: 500px;
}
Solution :
NOTE
See ThirtyDot's answer, as it does not impact the outer element's width:
How to make div width almost 100%
The below will actually make the outer element's width total the width plus the padding left and right values, which is not what the question is asking. Sorry for the confusion. :)
You could add a padding left and right of 5px
(assuming you want the #inner
to be 10px
less total, not per side):
<div id="outer">
<div id="inner"></div>
</div>
#outer {
width: 500px;
height: 500px;
background: red;
padding: 2px 5px;
}
#inner {
width: 100%;
height: 500px;
background: blue;
}
EDIT
Taking into account the max-width
property, see this demo:
<div id="test">
<div id="outer">
<div id="inner"></div>
</div>
</div>
<p>
<input type="button" onclick="changeWidth('400px')" value="Change to 400px"/>
<input type="button" onclick="changeWidth('500px')" value="Change to 500px"/>
<input type="button" onclick="changeWidth('600px')" value="Change to 600px"/>
</p>
#outer {
width: 100%;
max-width: 500px;
background: red;
padding: 2px 5px;
}
#inner {
width: 100%;
height: 200px;
background: blue;
}
#test {
background: yellow;
width: 600px;
}
function changeWidth(width) {
document.getElementById('test').style.width = width;
}
CSS Howto..
Here's a javascript answer for you though if you don't want to use @jatrim's css solution var colSelector = function (args) { var num = 0; var i = 0;...
Yes and no, you can't add scripts in the html editor and if you are copy-pasting something that has a FORM element, it won't directly work without modification. One possible...
You can use jQuery to do this. Google offset().top and scrollTop() functions in jQuery. The simple logic is, as the gap between an element and the top of the document...
You can use .length to check if the element exists in DOM. $('.element-rendered .select-inline') will select all the elements having class select-inline inside the element with class element-rendered. .length on...
Looks like you're missing a closing </div> tag which is more than likely why it's jumping all over the page. Use a tool like this to help you: http://www.freeformatter.com/html-validator.html Nice...
Mobile only and tablet only are actually just media queries that show/hide elements based on some predetermined screen width. You can do this on your own using jQuery. $(window).resize(function ()...
This can not be done; CSS can not be used to insert elements into a HTML page.
You are using PhpStorm's own simple built-in web server which uses URLs like http://localhost:63342/ProjectName/app_login.php. You cannot make http://localhost:63342/app_login.php using such server as it will not be able to tell what...
I suggest you do it using CSS transitions. I believe this is what you're trying to do, but I can't find the referenced 'scaleDown' animation anywhere. My solution animates both...
This should do the trick for you: #contact_form{ width:50%; margin-left:auto; margin-right:auto; } Check the fiddle here I have not added all your CSS, only showed how you can center the...
You can edit the color by this code:- echo '<font style="color:what you want;">'; echo "["; echo date('H:i:s', $row['timestamp']); echo "]"; echo '</font>'; echo '<font style="color:what you want;">'; echo htmlspecialchars($row['name']); echo...
.group-item img { float: left; margin-right: 15px; width: 80px; } should work, I removed the s from groups- in the css declaration ...
just use !important on your css which should override existing css tr:hover { background:red !important; } ...
Since a <p> is a block level element it will always force other content down. If you place the image inside the paragraph it floats within the paragraph to the...
The best you could probably do would be to find out what the browser is and from that, see what it's capable of. I suggest you start looking at $_SERVER['HTTP_USER_AGENT']...
You can use Bootstrap's text-center and text-right classes to modify inner alignment of columns. <div class="row"> <div class="col-4"><img src="http://www.panext.com/wordpress/wp-content/uploads/2012/09/question-63916_640-400x200.jpg"></div> <div class="col-4 text-center"><img...
Rails' .text_field method will generate an input tag in your HTML, so you need to target that input tag instead. Also, you should be using .field, not #field, since it's...
Block-level elements that are not floated (like your #boxContainer div) will default to 100% width. You can change it to display: inline-block to only take up the space that it...
CSS pseudo element ::before (:before) or ::after (:after) + content property, creates a child element inside the container. And a percentage padding value is relative to the width of the...
I solved it by editing the style.css in the themes\avada directory and imported my font via the font-face, plus I selected none for the font selection boxes in the typography...
Updated answer: Use both :not(:first-child) and :not(:last-child) div.entry p:not(:first-child):not(:last-child) See updated JSFiddle....
//partial css search with "*" By regExCss = By.cssSelector("[ng-style*='background-image']"); List<WebElement> children = driver.findElements(regExCss); // And if you want to print every child(possibly some attribute) // do a loop int count...
Guess you've been sleeping for a while? Anyway the Mozilla Ducmentation mentioned is useful: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries But that may be confusing. When coming to the realm of Responsive Web design you...
Those are not fb elements, they are like and comment elements in the fb XML namespace. The W3C way to do all this is to declare the namespace in your...
The width on your hover is causing the jump. I moved it to the "a" tag and cleaned up the other code a bit as well: #city-navigation li a {...
I've had about the same problem. Though I can't help for your IE7-specific issue, using overflow: hidden on the left column did the trick for the layout overlapping (and did...
Ah, the good old "how to overlay stuff on top of a responsive image -- responsively" question. A little tricky, but not too bad. The tricky bit is how to...
You could combine the use of <span> elements, which are inherently inline-block, with word-wrap:break-word. HTML: <div class="box"> <div class="price"> <span>HUF</span> <span>12944444</span> </div> </div> CSS: .box { background-color:#00FF7F; height: 300px; width:120px;...
Your code seems to be working fine.. See the fiddle.. Please change your <script> for jquery as follows: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> To remove the extra white spacing, add this to your...
Just use element:nth-child(1){ /*whatever*/ } or element:first-child { /*whatever*/ } You can also use element:nth-of-type(1){ /*whatever*/ }...