I am using some CSS classes to manipulate my validation summary. Currently, I only show the first error. I wish to align this error inside its div. However my vertical-align properties seem to be having no effect. I can see that they are applied when I inspect the element with firebug in Firefox, yet they don't render as vertically aligned (they sit at the top). The other elements of the classes render correctly.
My div
<div style ="float: left; max-width: 200px; height: 75px; vertical-align:middle">
#Html.ValidationSummary(false)
</div>
My CSS classes
.validation-summary-errors li {
color: #b94a48;
vertical-align: middle;
}
.validation-summary-errors ul li:nth-child(n+2) {
display: none;
}
JSfiddle: http://jsfiddle.net/9ejZz/1/
vertical-align only apply to cell elements such as <td> or elements that have the css rule display:table-cell
See this example : http://jsfiddle.net/V9by8/
You should provide a jsfiddle for your problem, I could help you center it
UPDATE
Updataed with your code http://jsfiddle.net/9ejZz/6/
Six methods for centering something vertically. Pick your poison. This question seriously comes up once a week...
http://www.vanseodesign.com/css/vertical-centering/
Line-height
<div id="parent">
<img src="image.png" alt="" />
</div>
#parent {
line-height: 200px;
}
#parent img {
vertical-align: middle;
}
Table
<div id="parent">
<div id="child">Content here</div>
</div>
#parent {display: table;}
#child {
display: table-cell;
vertical-align: middle;
}
Negative Margins
<div id="parent">
<div id="child">Content here</div>
</div>
#parent {position: relative;}
#child {
position: absolute;
top: 50%;
left: 50%;
height: 30%;
width: 50%;
margin: -15% 0 0 -25%;
}
Stretching
<div id="parent">
<div id="child">Content here</div>
</div>
#parent {position: relative;}
#child {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 50%;
height: 30%;
margin: auto;
}
Equal Padding
<div id="parent">
<div id="child">Content here</div>
</div>
#parent {
padding: 5% 0;
}
#child {
padding: 10% 0;
}
Floater Div
<div id="parent">
<div id="floater"></div>
<div id="child">Content here</div>
</div>
#parent {height: 250px;}
#floater {
float: left;
height: 50%;
width: 100%;
margin-bottom: -50px;
}
#child {
clear: both;
height: 100px;
}
Related
I have to fix this layout, which is a messy combination of flexbox, table layout and absolute positioning.
While it's working normal on Chrome, FF and Safari, the output screen on IE11 is strange.
In my code, I want the span to be at the bottom-right of each square, but on IE11, it appears on top-right instead.
Can anyone please help me to fix this problem? The constraint here is that the flexbox .container and the table system must be maintained. I want to fix only the span element. Thanks in advance!
.container {
display: flex;
width: 400px;
}
.inner {
width: 50%;
}
.table {
display: table;
width: 100%;
border: 1px solid;
}
.table:before {
content: '';
display: table-cell;
width: 0;
padding-bottom: 100%;
}
.cell {
display: table-cell;
vertical-align: bottom;
position: relative;
padding: 20px;
}
.cell span {
position: absolute;
bottom: 20px;
right: 20px;
}
<div class="container">
<div class="inner">
<div class="table">
<div class="cell">
Yeah?
<span>Yo!</span>
</div>
</div>
</div>
<div class="inner">
<div class="table">
<div class="cell">
Yeah?
<span>Yo!</span>
</div>
</div>
</div>
</div>
remove your .cell span block and
use below code instead of that.
i have checked its working in every browser.
.cell span {
float: right;
}
One thing you can do to fix it in IE11 is to wrap your cell contents into a block container and then add position: relative to it. Now you can adjust the position with right: 0px - see demo below:
.container {
display: flex;
width: 400px;
}
.inner {
width: 50%;
}
.table {
display: table;
width: 100%;
border: 1px solid;
}
.table:before {
content: '';
display: table-cell;
width: 0;
padding-bottom: 100%;
}
.cell {
display: table-cell;
vertical-align: bottom;
position: relative;
padding: 20px;
}
.cell span {
position: absolute;
/*bottom: 20px;
right: 20px;*/
right: 0px; /* ADDED */
}
.cell div { /* ADDED */
position: relative;
}
<div class="container">
<div class="inner">
<div class="table">
<div class="cell">
<div>Yeah?
<span>Yo!</span></div>
</div>
</div>
</div>
<div class="inner">
<div class="table">
<div class="cell">
<div>Yeah?
<span>Yo!</span></div>
</div>
</div>
</div>
</div>
Here is a content inside: <div class="traki"> </div>
I add following css:
.traki {margin-left: auto !important;
margin-right: auto !important;}
}
And goal is to set inside content center. but it doesn't apply, demo: http://buhehe.de/kalender-2018/
You cannot do an "auto" margin to vertically center an element.
There is a workaround though, you could try this:
.container {
display: table;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
}
.helper {
#position: absolute;
#top: 50%;
display: table-cell;
vertical-align: middle;
}
.content {
#position: relative;
#top: -50%;
margin: 0 auto;
width: 200px;
border: 1px solid orange;
}
<div class="container">
<div class="helper">
<div class="content">
<p>stuff</p>
</div>
</div>
</div
I am a bit newbie with CSS and i am pretty obfuscated trying to center a group of divs inside a div. What i want:
divs 2,3 and 4 should be centered inside div1.
My approach:
.div1 {
display: inline-block;
margin: 0 auto;
text-align: center;
}
.restofdivs {
width: 470px;
margin: 20px;
min-height: 1px;
float:center
}
the result is: the 3 divs (2,3 and 4) one on top of another...
Regards,
This can easily be done with table display:
.table-display {
display: table;
width: 100%;
}
.cell-display {
display: table-cell;
}
.div1, .div2, .div3, .div4 {
padding: 40px;
}
.div1 {
background: #ABC;
}
.div2 {
background: #DEF;
}
.div3 {
background: #CAD;
}
.div4 {
background: #FAD;
}
<div class="div1">
<div class="table-display">
<div class="cell-display div2"></div>
<div class="cell-display">
<div class="div3"></div>
<div class="div4"></div>
</div>
</div>
</div>
Maybe set a width on .div1 and remove inline-block from .div1
.div1 {
width: 960px;
margin: 0 auto;
text-align: center;
}
.restofdivs {
width: 470px;
margin: 20px;
min-height: 1px;
}
The most common way to center a block element if you know it's width is to define the width and use "margin: 0 auto". This tells the browser to give a top and bottom margin of 0, and to automatically determine equal margins on the left and right.
Using floats, you can create the layout you described as follows:
http://jsfiddle.net/ynt4suee/
Markup:
<div>
<div id="one" class="border clearfix">one
<div id="wrapper">
<div id="two" class="border">two</div>
<div class="subcontainer">
<div id="three" class="border">three</div>
<div id="four" class="border">four</div>
</div>
</div>
</div>
CSS:
div.border{
border: 1px solid red;
}
div#wrapper{
width: 400px;
margin: 0 auto;
}
div#two{
width: 250px;
float: left;
}
div.subcontainer{
float: right;
width: 130px;
}
.clearfix:after {
content: " "; /* Older browser do not support empty content */
visibility: hidden;
display: block;
height: 0;
clear: both;
}
Here's another approach, using inline-block elements for the inner divs instead:
http://jsfiddle.net/xojqq4v5/
Markup:
<div id="one" class="border">
div 1
<div id="wrapper">
<div id="two" class="border">div 2</div>
<div id="subcontainer">
<div id="three" class="border">div 3</div>
<div id="four" class="border">div 4</div>
</div>
</div>
</div>
CSS:
div.border{
border: 1px solid red;
margin-bottom: 5px;
}
div#wrapper{
width: 450px;
margin: 0 auto;
}
div#two, div#subcontainer{
display: inline-block;
vertical-align: top;
}
div#two{
width: 300px;
}
div#three, div#four{
width: 140px;
}
Still, so long as you know the total width of the inner divs, you can center the wrapper using "margin: 0 auto", which has the advantage of not centering text on all child elements unless otherwise specified.
The difference here is that to lay out the inner divs in columns, div 2 and the container div containing divs 3 and 4 are defined as inline-block elements.
Below I have 3 rows (.child) with different heights.
The height of the parent (#parent) cannot be known in advance and it will actually change if the height of its parent (the parent of #parent) changes.
Is there some CSS combination that I could use that would set the margins between those rows in such a way that the rows are spread out evenly on the vertical ?
Similar to when we have cells with different widths that we want to spread out evenly on the horizontal. This is easy to achieve by using display: table-cell; I believe, even if the width of their parent is unknown.
JSFIDDLE : http://jsfiddle.net/7ty82k3b/5/
CSS :
#parent {
display: table;
position: fixed;
top: 0px;
left: 0px;
height: 100%;
width: 93px;
background-color : red;
}
.child {
position : relative;
float: left;
clear: both;
border: 1px solid blue;
display: table-row;
width: 91px;
}
span.child {text-align:center;}
HTML :
<body>
<div id="parent">
<img class="child" src="http://www.philreinhardt.com/downloads/SuperSqueezePages/Super%20Squeeze%20Page%20Pack/BonusMoreAnimatedArrows/More%20Animated%20Arrows/Arrow%20Right%201/Arrow%20Right%201%20Small/ArrowRightBlueSmall.gif">
<span class="child">Hey!</span>
<img class="child" src="http://www.philreinhardt.com/downloads/SuperSqueezePages/Super%20Squeeze%20Page%20Pack/BonusMoreAnimatedArrows/More%20Animated%20Arrows/Arrow%20Right%201/Arrow%20Right%201%20Small/ArrowRightBlueSmall.gif">
</div>
</body>
Wrap your .child inside some .row so you can display the .row as a table-row and the .child as a table-cell and then vertical-align: middle them. Also, keep in mind that images are crybabies that won't handle very well "exotic" displays, so don't try to display them as table-row or table-cell.
#parent {
display: table;
position: fixed;
top: 0px;
left: 0px;
height: 100%;
width: 93px;
background-color: red;
}
.row {
display: table-row;
}
.child {
position: relative;
border: 1px solid blue;
display: table-cell;
vertical-align: middle;
}
span.child {
text-align: center;
}
<div id="parent">
<div class="row">
<div class="child">
<img src="http://www.philreinhardt.com/downloads/SuperSqueezePages/Super%20Squeeze%20Page%20Pack/BonusMoreAnimatedArrows/More%20Animated%20Arrows/Arrow%20Right%201/Arrow%20Right%201%20Small/ArrowRightBlueSmall.gif">
</div>
</div>
<div class="row"> <span class="child">Hey!</span>
</div>
<div class="row">
<div class="child">
<img src="http://www.philreinhardt.com/downloads/SuperSqueezePages/Super%20Squeeze%20Page%20Pack/BonusMoreAnimatedArrows/More%20Animated%20Arrows/Arrow%20Right%201/Arrow%20Right%201%20Small/ArrowRightBlueSmall.gif">
</div>
</div>
</div>
I know there are a ton of posts about this issue. After reading all them I feel like I am close, but it still isn't working for me.
HTML:
<div class="product">
<div class="image">
<a href="#">
<img src="http://i.imgur.com/rthFtAb.jpg" />
</a>
</div>
</div>
CSS
.product {
height:225px;
min-height:225px;
max-width:220px;
background-color:#ff00ff;
}
.image {
min-height:225px;
display:table-cell;
vertical-align:middle;
}
.image img {
max-width:100%;
}
http://jsfiddle.net/SBqU5/
What am I doing wrong here?
Six methods for centering something vertically.Pick your poison. Your method would fall under the "Table" option.
http://www.vanseodesign.com/css/vertical-centering/
Line-height
<div id="parent">
<img src="image.png" alt="" />
</div>
#parent {
line-height: 200px;
}
#parent img {
vertical-align: middle;
}
Table
<div id="parent">
<div id="child">Content here</div>
</div>
#parent {display: table;}
#child {
display: table-cell;
vertical-align: middle;
}
Negative Margins
<div id="parent">
<div id="child">Content here</div>
</div>
#parent {position: relative;}
#child {
position: absolute;
top: 50%;
left: 50%;
height: 30%;
width: 50%;
margin: -15% 0 0 -25%;
}
Stretching
<div id="parent">
<div id="child">Content here</div>
</div>
#parent {position: relative;}
#child {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 50%;
height: 30%;
margin: auto;
}
Equal Padding
<div id="parent">
<div id="child">Content here</div>
</div>
#parent {
padding: 5% 0;
}
#child {
padding: 10% 0;
}
Floater Div
<div id="parent">
<div id="floater"></div>
<div id="child">Content here</div>
</div>
#parent {height: 250px;}
#floater {
float: left;
height: 50%;
width: 100%;
margin-bottom: -50px;
}
#child {
clear: both;
height: 100px;
}
if you use display:table-cell; and max-width; parent should be display:table; table-layout:fixed and width:xxpx. DEMO
.product {
height:225px;
width:220px;
background-color:#ff00ff;
display:table;
table-layout:fixed;
}
.image {
display:table-cell;
vertical-align:middle;
}
.image img {
max-width:100%;
}
If you are able to define a width and height to your image, you can use `position: absolute'.
.image {
position: relative;
height: 100%;
}
.image img {
width: 220px;
height: 105px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -110px;
margin-top: -52px;
}
DEMO
Note that the negative left and top margins are half of their width and height, respectively.