Removing Border Style Changes Page Layout

Removing border style changes page layout

Borders separate collapsing margins: http://www.w3.org/TR/CSS21/box.html#collapsing-margins

How to remove border from elements in the last row?

You can add a negative bottom margin to your elements then hide the overflow. This will hide the unwanted borders.

.qa {

border-bottom: 1px solid #ccc;

margin-bottom:-1px;

margin-top:1px; /*to rectify the bottom margin, we can also consider padding-bottom*/



/*irrelevant styles*/

padding: 5px;

margin-left:5px;

margin-right:5px;

box-sizing: border-box;

flex:1 1 40%;

}

.wrapper {

display: flex;

flex-wrap: wrap;

flex-direction: row;

overflow:hidden;

}
<div class="wrapper">

<div class="qa">

<div>Question</div>

<div>Answer<br>Answer</div>

</div>

<div class="qa">

<div>Question</div>

<div>Answer</div>

</div>

<div class="qa">

<div>Question</div>

<div>Answer</div>

</div>

<div class="qa">

<div>Question</div>

<div>Answer<br>Answer</div>

</div>

<div class="qa">

<div>Question</div>

<div>Answer</div>

</div>

<div class="qa">

<div>Question</div>

<div>Answer</div>

</div>

<div class="qa">

<div>Question</div>

<div>Answer</div>

</div>

<div class="qa">

<div>Question</div>

<div>Answer</div>

</div>

<div class="qa">

<div>Question</div>

<div>Answer</div>

</div>

<div class="qa">

<div>Question</div>

<div>Answer<br>Answer</div>

</div>

</div>

How to remove the bottom border of a box with CSS

Just add in: border-bottom: none;

#index-03 {
position:absolute;
border: .1px solid #900;
border-bottom: none;
left:0px;
top:102px;
width:900px;
height:27px;
}

Remove border from IFrame

Add the frameBorder attribute (note the capital ‘B’).

So it would look like:

<iframe src="myURL" width="300" height="300" frameBorder="0">Browser not compatible.</iframe>

Why is adding or removing a border changing the way margins work?

The specific answer to your question is collapsing margins and is part of the W3C's BOX MODEL specifications:


Vertical margins may collapse between certain boxes:

  • Two or more adjoining vertical margins of block boxes in the normal flow collapse. The resulting margin width is the maximum of the adjoining margin widths. In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins. If there are no positive margins, the absolute maximum of the negative adjoining margins is deducted from zero. Note. Adjoining boxes may be generated by elements that are not related as siblings or ancestors.
  • Vertical margins between a floated box and any other box do not collapse (not even between a float and its in-flow children).
  • Vertical margins of elements that establish new block formatting contexts (such as floats and elements with 'overflow' other than 'visible') do not collapse with their in-flow children.
  • Margins of absolutely positioned boxes do not collapse (not even with their in-flow children).
  • Margins of inline-block elements do not collapse (not even with their in-flow children).
  • If the top and bottom margins of a box are adjoining, then it is possible for margins to collapse through it. In this case, the position of the element depends on its relationship with the other elements whose margins are being collapsed.
    • If the element's margins are collapsed with its parent's top margin, the top border edge of the box is defined to be the same as the parent's.
    • Otherwise, either the element's parent is not taking part in the margin collapsing, or only the parent's bottom margin is involved. The position of the element's top border edge is the same as it would have been if the element had a non-zero bottom border.

An element that has had clearance applied to it never collapses its top margin with its parent block's bottom margin.

Note that the positions of elements that have been collapsed through have no effect on the positions of the other elements with whose margins they are being collapsed; the top border edge position is only required for laying out descendants of these elements.
Margins of the root element's box do not collapse.


So, when you add a border, you're doing exactly what the specification says, therefore you have no margin.

There are many ways and fixes and hacks to solve this, but to me, the most direct and easy is as simple as to apply an overflow:auto; property to the div you want to clear the margin.

Thus, in your CSS, you would only need to change it like this:

.second-div
{
background-color: blue;
min-height: 50px;
overflow:auto;
}

I forked your fiddle with even more border so you can notice the effect and see how good it works

How to prevent adjoining elements from moving when increasing border width?

Pretty easy to do actually. If you don't want to go the absolute position route, you can do it two ways: substitute a box-shadow the increased border if your don't mind the compatibility compromise or use box-sizing:border-box. The only problem with box-sizing:border-box is that it shifts your content inward (the style rule calculates the total width + padding + border-width in the width attribute. If you set a 5px border to a 100px box, the width is normally 110px to include both left and right borders. With the box-sizing attribute it calculates the border width into the width making it 90px wide instead to allow for the 10px of border width).

j08691 already has the box-sizing solution in his answer, so here is the box-shadow method (notice that I only added 1px of box shadow. This is because the border is still present providing half of the desired width):

 .action_box {

width: 300px;

height: 200px;

border: 1px solid black;

float: left;

margin-left: 10px;

margin-top: 10px;

}

.action_box p {

border: 1px solid black;

margin-top: 0px;

text-align: center;

}

.action_box:hover {

box-shadow: 0 0 0 1px black;

cursor: pointer;

}
<div class="action_box">asdasds</div>

<div class="action_box">asdasds</div>

<div class="action_box">asdasds</div>

<div class="action_box">asdasds</div>

<div class="action_box">asdasds</div>

how to remove the borders in JQuery Layout?

Remove one border:

pageLayout.panes.north.css('border','none');

Remove all borders:

As you should be quite sure that each pageLayout.pane will have o as a property:

for(property in pageLayout.panes){
pageLayout.panes[property].css('border', 'none');
}

How you should really do it - checks to make sure o is a property of pageLayout.pane before attempting to access it:

for(property in pageLayout.panes){
if(pageLayout.panes.hasOwnProperty(property)){
pageLayout.panes[property].css('border', 'none');
}
}


Related Topics



Leave a reply



Submit