I am trying to make a footer for my website.
I want 2 divs and one list to be inline in this footer. But that is not happening. I used the css the CSS Property display:inline-block. What happens is that the divs get aligned but the list element just shifts a bit down.
Here is the jsFiddle Link: http://jsfiddle.net/tw2Wp/2/.
If you see the JSfiddle, you will that the three divs with class footerContents are not aligned in-line.
Could someone please explain me why this is happening? Is it right thing to use inline-block for this thing or is there some better way(I'm sure that there is)?
Please add vertical-align to .footerContents:
.footerContents {
display: inline-block;
width: 200px;
height: 200px;
padding: 5px;
margin-top: 30px;
margin-left: 50px;
margin-bottom: 5px;
background-color: red;
vertical-align: top; /* <<< */
}
Demo
Would you use the css3 flexbox module, like this:
HTML
<div id="footer">
<div class="footerContents">
...
</div>
<ul class="footerContents">
...
</ul>
<div class="footerContents">
...
</div>
</div>
<div>Copyright © </div>
CSS
#footer {
height:auto;
width:100%;
background-color:#666;
background-image:url(footer_shade.png);
background-repeat:no-repeat;
background-position:50% 0;
border-top:1px solid #FFF;
color:#fff;
font-family:'Bree Serif',serif;
font-size:16px;
line-height:20px;
display:-moz-box;
display:-webkit-box;
display:-ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-pack: justify;
-moz-box-pack: justify;
-ms-flex-pack: justify;
-webkit-justify-content: space-between;
justify-content: space-between;
}
.footerContents {
width:200px;
height: 200px;
padding:5px;
margin-top: 30px;
margin: 20px;
margin-bottom: 5px;
background-color: red;
-moz-flex-box:1;
-webkit-flex-box:1;
-ms-flex:1 1 200px;
-webkit-flex: 1 1 200px;
flex:1 1 200px;
}
Please view the demo. and some about the flexbox, if you want to know,please will click here and here.
A solution would be to float the elements rather than using inline-block, see working example here: http://jsfiddle.net/tw2Wp/2/
Note that I also added an extra div with the class clear which will clear the floats. By doing this your background will appear again. Because of the floated elements the parent div doesn't have a clue how large it should be (so it's height 0).
.clear{
clear:both;
}
You can do like this:
HTML
<div id="footer">
<div class="footerContents">
...
</div>
<ul class="footerContents">
...
</ul>
<div class="footerContents">
...
</div>
</div>
<div>Copyright © </div>
CSS
#footer {
height:auto;
width:100%;
background-color:#666;
background-image:url(footer_shade.png);
background-repeat:no-repeat;
background-position:50% 0;
border-top:1px solid #FFF;
color:#fff;
font-family:'Bree Serif',serif;
font-size:16px;
line-height:20px;
**white-space: nowrap;**
}
.footerContents {
display:inline-block;
width:200px;
height: 200px;
padding:5px;
margin-top: 30px;
margin-left: 50px;
margin-bottom: 5px;
background-color: red;
**vertical-align: top;
white-space: normal;**
}
please view the new demo.
Related
Is it possible to align my text to the vertical middle. I've used valign, text-align and padding but will doesn't work. Also, I don't want any image to align with text.
Solution needs to be HTML only.
body {
background-color: #6B6B6B;
margin: 50px;
<div style="background:#2f2f2f;height:42px;width:250px;"><i><b style="padding-top:10px;text-align:middle">Text</a></div>
Just add to the div.
display: flex;
align-items: center;
body {
background-color: #6B6B6B;
margin: 50px;
<div style="background:#2f2f2f;height:42px;width:250px;display: flex;
align-items: center;"><i><b style="padding-top:10px;text-align:middle">Text</a></div>
Also, the html format is not valid, a better code would be something like this:
body {
background-color: #6B6B6B;
margin: 50px;
}
.container {
background: #2f2f2f;
height: 42px;
width: 250px;
display: flex;
align-items: center;
}
<div class="container">
<span>Text</span>
</div>
Your HTML has some syntax errors, and you need to use negative margins in this case to align to the bottom center.
body {
background-color: #6B6B6B;
}
.bottomcenter {
position:absolute;
width:300px;
height:300px;
bottom:0px;
right:25%;
left:50%;
margin-left:-150px;
color:white;
}
<div style="background:#2f2f2f;height:42px; text-align:center;" class="bottomcenter"><i><a style="padding-top:10px;">Text</a></i></div>
I think it's this one. If you want to make the text go to the center you just write this code:
text-align: center;
I've seen this asked many times, none of the solutions are working for me. As you can see in the Fiddle this is working exactly how I want it to in Chrome, but in IE the text is stuck at the top of the box, instead of in the middle. If you run it in IE browser and Chrome side by side you'll see what I mean. I want it in the middle exactly, using margin:auto; works perfectly in chrome, but in IE it doesn't. I'm not sure of a fix that will move the paragraph down so it is aligned in the middle both vertically and horizontally.
<section class="info">
<p class="infofont">Size: Large<br><br>
100% Cotton<br><br>
Excellent Condition!
</p>
</section>
CSS:
.info{
display:flex;
width:325px;
margin:auto;
}
.infofont{
font-weight:bold;
text-align:center;
margin:auto;
}
https://jsfiddle.net/fmu8g38h/
try this instead:
.info{
display:flex;
top:50%;
left:50%;
transform: translate(-50%, -50%);
position:absolute;
}
https://jsfiddle.net/k1cbjvj7/1/
margin:auto is used to align the texts horizontally.
to align in center the top portion must be aligned seperately
You forgot to write flex-direction: row / column; align-items: center; justify-content: center; for when display is flex and inside content will be vertically and horizontally center and you should remove margin: auto; from .infofont class.
Below is update your CSS code.
.info{
border: 1px solid black;
align-items: center;
display: flex;
flex-direction: row;
justify-content: center;
width: 325px;
margin:auto auto;
height: 500px;
}
.infofont{
font-weight:bold;
text-align:center;
}
Check the snipped
.info{
border: 1px solid black;
align-items: center;
display:flex;
flex-direction: row;
justify-content: center;
width:325px;
margin:auto auto;
height:500px;
}
.infofont{
color: green;
font-size: 16px;
font-weight:bold;
line-height: 1.2;
margin: 0;
text-align:center;
}
*,
*:after,
*:before{
box-sizing: inherit;
}
html{
box-sizing: border-box;
}
<section class="info">
<p class="infofont">Size: Large<br><br>
100% Cotton<br><br>
Excellent Condition!
</p>
</section>
Note: I test this code only IE11, Chrome and Safari.
I'm a noob at CSS and I was playing with CSS and DIVS, everything was going well until I decided put 2 Divs inside of one. I can put ONE div inside of another, but when I put 2 it just bugs.
I could put the green Div inside of yellow div but not the cyan
Here is my HTML:
<html>
<head>
<link type="text/css" rel="stylesheet" href="style_divs.css">
</head>
<body>
<div id="table">
<div id="year">2017</div>
<div id="month">
<div id="previousMonth">Previous</div>
<div id="nextMonth">Next</div>
January
</div>
</div>
</body>
</html>
CSS
#table{
width:25%;
height:50%;
background-color: red;
margin: 0 auto;
}
#year{
width:100%;
height:10%;
background-color: blue;
margin: 0 auto;
text-align: center;
}
#month{
width:100%;
height:10%;
background-color: yellow;
margin: 0 auto;
text-align: center;
}
#previousMonth{
width:12%;
height:100%;
background-color: green;
margin-left: 0%;
text-align: center;
}
#nextMonth{
width:12%;
height:100%;
background-color: cyan;
margin-left: 88%;
text-align: center;
}
Thanks.
The best approach is to use the #previousmonth float:left and #nextMonth float:right
You should not use the margin feature to achieve this below is the corrected two styles using the float command
#previousMonth{
width:12%;
float:left;
height:100%;
background-color: green;
text-align: center;
}
#nextMonth{
width:12%;
height:100%;
float:right;
background-color: cyan;
text-align: center;
}
body{
height:500px;
width:600px;
}
#table{
width:50%;
height:70%;
background-color: red;
margin: 0 auto;
}
#year{
width:100%;
height:10%;
background-color: blue;
margin: 0 auto;
text-align: center;
}
#month{
width:100%;
height:10%;
background-color: yellow;
margin: 0 auto;
}
/*wrapped them in div so they can be one group*/
#pager{
height:100%;/*tells the pager to take 100% of parent's height(month)*/
}
#pager div{/*tells the child divs of pager to have same properties*/
display:inline-block;/*this will display contents side by side one another*/
width:12%;
height:100%;
}
#previousMonth{
background-color: green;/*assign properties that are unique to the child*/
}
#nextMonth{
background-color: cyan;
float:right; /* this will make it float to right */
}
#monthname{
text-align:center;
}
<body>
<div id="table">
<div id="year">2017</div>
<div id="month">
<div id="pager">
<div id="previousMonth">Previous</div>
<div id="nextMonth">Next</div>
</div>
<div id="monthname">January<div/>
</div>
</div>
</div>
</body>
I have tinkered with your codes a bit. You need to tell the element what to do. Also, try not to wrote same codes to children since they will inherit the parent's properties. Pressing F12 will tell you which properties the element has when rendered. Hope this helps. Good luck and happy coding.
I have a span which has to aligned bottom and left-most to the content of it's container. Span text-node and container text-node font-size may differ.
Whatever it's span should always align to its container text-node bottom and to left-most. I tried using float left to the span node. It aligns to the left most but not to it's bottom. Removing float to the span, Aligns bottom but not left most. Sorry if I have not explained you better.
Refer the image attached for more clarification
Also here is the code which I tried:
.flexCtn{
display:flex;
align-items:center;
justify-content:flex-end;
height:50px;
width:300px;
border:1px solid #dfdfdf;
background:#fff;
}
.w100{
font-size:30px;
width:100%;
text-align:right
}
span{
font-size:14px;
float:left;
display:inline-block;
}
<div class="flexCtn">
<div class="w100">
<span>check</span>
the alignment
</div>
</div>
P.S I don't want any modification to the DOM. I have specific reason for this DOM structure which is going ti be vague if i'm going to explain you guys. Also don't want absolute position to be applied for the span. Thanks in advance
You have a flexbox container - so why not make w100 also a flexbox and align vertically using align-items: center - see demo below:
.flexCtn {
display: flex;
align-items: center;
justify-content: flex-end;
height: 50px;
width: 300px;
border: 1px solid #dfdfdf;
background: #fff;
}
.w100 {
font-size: 30px;
width: 100%;
text-align: right;
display: flex;
justify-content: space-between;
align-items: center;
}
span {
font-size: 14px;
float: left;
display: inline-block;
}
<div class="flexCtn">
<div class="w100">
<span>check</span>
the alignment
</div>
</div>
.flexCtn{
display:flex;
align-items:center;
justify-content:flex-end;
height:50px;
width:300px;
border:1px solid #dfdfdf;
background:#fff;
}
.w100{
font-size:30px;
width:100%;
text-align:right
}
span{
font-size:14px;
float:left;
display:inline-block;
padding : 16px 0 0 0; /* specify top position */
}
<div class="flexCtn">
<div class="w100">
<span>check</span>
the alignment
</div>
</div>
I have used flex property
https://plnkr.co/edit/flxsEcpSBe8sr2w3wPFc?p=preview
div{
font-size:14px;
display:flex;
align-items:flex-end;
flex:1;
}
I'm trying to center image horizontally in this sample http://jsfiddle.net/3k3CC/1545/ , but I'm unsuccessfull. It only works when container is wider than image, but what I need is for the image to be centered even if the container is thinner than the image itself.
Sample CSS:
#artiststhumbnail {
width:100px;
height:308px;
overflow:hidden;
border-color:#DADADA;
border-style:solid;
border-width:thin;
background-color:pink;
}
#artiststhumbnail:hover {left:50px }
#genre {
font-size:12px;
font-weight:bold;
color:#2A2A2A
}
#artiststhumbnail a img {
display : block;
margin : auto;
}
Sample HTML:
<div id="artiststhumbnail">
<a href="#">
<!--image here-->
<img src="http://goo.gl/QrKCc" height="100%" alt="artist" border="1" />
</a>
</div>
You should add text-align: center; to #thumbnailwrapper and set display: inline-block; to #artiststhumbnail.
DEMO
EDIT:
I'm sorry I don't unsderstand your question at the beggining. Use this simple CSS:
#artiststhumbnail a img {
position: relative;
left: 50%;
transform: translateX(-50%);
}
DEMO2
you can add to the #artiststhumbnail this code,
width: 100%;
padding: 15px;
http://codepen.io/jrey/pen/waXgBO updated code :)
try this CSS.. comment your css and try this please...
#artiststhumbnail {
width:100px;
height:308px;
overflow:hidden;
border-color:#DADADA;
border-style:solid;
border-width:thin;
background-color:pink;
width: 100%;
padding: 15px;
display: inline-flex;
flex-flow: row wrap;
justify-content: center;
}
#artiststhumbnail:hover {left:50px }
#genre {
font-size:12px;
font-weight:bold;
color:#2A2A2A
}
#artiststhumbnail a {
display: flex;
justify-content: center;
}
#artiststhumbnail a img {
display : block;
margin : 15px;
width: 200px;
height: auto;
}
DEMO
CSS
#thumbnailwrapper {
color:#2A2A2A;
margin-right:5px;
border-radius:0.2em;
margin-bottom:5px;
background-color:#E9F7FE;
padding:5px;
border-color:#DADADA;
border-style:solid;
border-width:thin;
font-size:15px;
/* The following rules make this a flexbox container */
display: flex;
display: -webkit-flex;
-webkit-flex-direction: row;
flex-direction: row;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
}
#thumbnailwrapper:hover {
box-shadow:0 0 5px 5px #DDDDDD
}
#artiststhumbnail {
width:100px;
height:308px;
overflow:visible; // Changed from hidden to visible
border-color:#DADADA;
border-style:solid;
border-width:thin;
background-color:pink;
}
#artiststhumbnail:hover {
/*left:50px*/
}
/* No position: fixed. absolute, or relative; left: 50px has no effect on a static element */
#genre {
font-size:12px;
font-weight:bold;
color:#2A2A2A
}
#artiststhumbnail a img {
/* display: block;
margin: auto; */
}
/* Removed margin and block display to demonstrate that flexbox container and it's children elements are not easily influenced by other element properties and attributes */
HTML
<div id="thumbnailwrapper">
<div id="artiststhumbnail"> <a href="#">
<!--image here-->
<img src="http://goo.gl/QrKCc" height="100%" alt="artist" border="1" />
</a>
</div>
</div>
you could try your image width to 100%
#artiststhumbnail a img {
display : block;
margin : auto;
width:100%;
}
Not sure exactly what you mean by center but here it goes. If you want the image itself to center, use background-size: cover and background-position: center to accomplish this.
<div id="thumbnailwrapper">
<div id="artiststhumbnail">
<a href="#">
<!--image here-->
<div></div>
</a>
</div>
</div>
#artiststhumbnail a div {
display : block;
margin : auto;
height: 100%;
width: 100px;
background-image: url('http://goo.gl/QrKCc');
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
JSFiddle
EDIT: sorry, had the wrong jsfiddle link attached