I am making a ticker which will eventually look like ESPN's bottom line.
Internet Explorer (7, 8, and 9) respect the width attribute on my divs, but do not respect the centering of the main div.
While WebKit (Safari 5 and 6, Chrome) and Firefox do not respect the width of the divs, but does center the main div properly. I am racking my head trying to get the CSS to work cross bowser.
HTML
<div id="ticker">
<div id="homeTeam">Team A</div>
<div id="homeScore">1</div>
<div id="awayTeam">Team B</div>
<div id="awayScore">2</div>
<div id="remaining">Final</div>
</div>
CSS
#ticker {
margin: auto;
width: 778px;
background-color: black;
height: 28px;
border-top-width: 3px;
border-top-style: outset;
border-top-color: #FFFFFF;
}
#homeScore {
width: 60px;
margin-left: -4px;
padding-right: 10px;
background-color: #79000a;
font-size: 24px;
color: white;
display: inline;
text-align: right;
}
#awayScore {
width: 60px;
margin-left: -4px;
padding-right: 10px;
background-color: #79000a;
font-size: 24px;
color: white;
display: inline;
text-align: right;
}
#homeTeam {
width: 270px;
padding-left: 10px;
background-color: #7c000e;
font-size: 24px;
color: white;
display: inline;
}
#awayTeam {
margin-left: 25px;
width: 270px;
padding-left: 10px;
background-color: #7c000e;
font-size: 24px;
color: white;
display: inline;
}
#remaining {
width: 76px;
background-color: black;
margin-left: 25px;
font-size: 20px;
color: white;
display: inline;
text-align: left;
}
The problem is you are setting the display property to inline. IE erroneously respects the width property on inline elements whereas the others follow web standards and do not.
You can:
1) Change inline to inline-block
or
2) Change them to block and use the float property.
Here is an explanation how to get inline-block to work in IE7 http://blog.mozilla.org/webdev/2009/02/20/cross-browser-inline-block/
Related
I have this button I am trying to make, but I am unable to get the text to be centered. I have previously looked at what past people have answered on how to align text within a button, but the ones I have tried do not seem to work.
.btn1 {
width: 160px;
height: 40px;
align-items: center;
text-align: center;
display: inline;
border-radius: 60px;
background-color: white;
border-color: #05434a;
border-width: 3px;
box-shadow: 5px 6px #05434a;
text-transform: uppercase;
font-size: 1.7vh;
margin-left: auto;
margin-right: auto;
vertical-align: middle;
font-family: poppins;
padding: 0px;
}
.nd {
text-decoration: none;
}
.social-link {
text-align: center;
margin-top: 20px;
margin-bottom: 0 !important;
}
<div class="social-link">
<a class = "nd" href = "">
<button class="btn1">
<p>text</p>
</button></a>
</div>
While one thing that seems OK is centering of the text, your HTML has these problems:
Error: The element button must not appear as a descendant of the a
element.
Error: Element p not allowed as child of element button in this
context
So this snippet removes these two elements and moves the CSS button styling onto the anchor element. It makes this inline-flex to help center the text.
Note: the text is centered though it can sort of appear as if it's a bit high because of the visual strength of the shadow. This snippet puts a 1px width border on the element just so you can assure yourself the text is centered.
.btn1 {
width: 160px;
height: 40px;
align-items: center;
justify-content: center;
text-align: center;
display: inline-flex;
border-radius: 60px;
background-color: white;
border-color: #05434a;
border-width: 1px;
border-style: solid;
box-shadow: 5px 6px #05434a;
text-transform: uppercase;
font-size: 1.7vh;
margin-left: auto;
margin-right: auto;
font-family: poppins;
padding: 0px;
}
.nd {
text-decoration: none;
}
.social-link {
text-align: center;
margin-top: 20px;
margin-bottom: 0 !important;
}
<div class="social-link">
<a class="nd btn1" href="">
text
</a>
</div>
Well, pretty easy and always works:
display: flex;
justify-contect: center;
align-item: center;
that will get the job done
for the element, set:
text-align: center;
I apologize in beforehand if this is a duplicate but I can't seem to find an answer.
I made something that resembles a progress bar. It's a div with p elements inside. However I can't seem to center the p elements vertically.
All i did now was give the parent div some padding and logically the text should be in the middle but it seems like the font is counting the height differently. And so the solution to change the line-height won't work. If I change the font to Verdana the text is aligned but that is not a preferred solution.
Snippet:
div {
width: 90%;
background-color: green;
text-align: left;
padding: 1.2%;
border-radius: 5px;
height: 20px;
font-family: 'Hind Guntur', sans-serif;
}
p {
font-size: 90%;
display: inline;
margin: 0;
color: white;
}
<link href="https://fonts.googleapis.com/css?family=Catamaran|Hind+Guntur" rel="stylesheet">
<div>
<p>1</p>
</div>
This should be what you are looking for. Your problem was that you had a fixed height of 20px on the div. If you change that value to 28px, your text might vertical-align.
div {
width: 90%;
background-color: green;
text-align: left;
padding: 1.2%;
border-radius: 5px;
height: 28px;
font-family: 'Hind Guntur', sans-serif;
}
p {
font-size: 90%;
display: inline;
margin: 0;
color: white;
}
<link href="https://fonts.googleapis.com/css?family=Catamaran|Hind+Guntur" rel="stylesheet">
<div>
<p>1</p>
</div>
check this
div {
width: 90%;
background-color: green;
text-align: left;
padding: 1.2%;
border-radius: 5px;
height: 20px;
font-family: 'Hind Guntur', sans-serif;
}
p {
font-size: 90%;
display: inline;
margin: 0;
color: white;
vertical-align: middle;
}
<link href="https://fonts.googleapis.com/css?family=Catamaran|Hind+Guntur" rel="stylesheet">
<div>
<p>1</p>
</div>
I have 3 div blocks, the first one is bigger on the left hand side of the web-page and the other are smaller in located the right hand side. I want their relative location become fixed in all browsers with any zoom level. The two div blocks in the right column drop down below the first big div if I zoom in now.
Here is JFFIDDLE link of the code, please zoom in/out to see the issue.
<div id="topdiv">
<div class="bigdiv">
<p> big div </p>
</div>
<div id="staticcal">
<p> staticcal </p>
</div>
<div id="staticnews">
<p> staticnews </p>
</div>
</div
#topdiv{
display: inline-block;
background-color:#b0c4de;
}
.bigdiv{
margin: 10px 0;
position: relative;
width: 335px;
height: 250px;
float: left;
border: 2px solid #c7930d;
}
#staticcal {
width: 220px;
height: 100px;
line-height: 175px;
float: right;
display: inline-block;
border: 2px solid #c7930d;
border-radius: 4px;
margin: 5px;
margin-top: 10px;
margin-right: 0px;
position: relative;
}
#staticnews {
width: 220px;
height: 100px;
line-height: 175px;
float: right;
display: inline-block;
border: 2px solid #c7930d;
border-radius: 4px;
margin: 5px;
margin-right: 0px;
position: relative;
}
Add min-width: 800px; to the #topdiv id in your CSS file.
CSS:
#topdiv {
display: inline-block;
background-color:#b0c4de;
min-width: 800px;
}
I noticed that you are using border-radius in your development, so I updated your file to account for cross browser use. Here is an updated JSFiddle for your review. Additionally I lined up your staticcal and staticnews by adding float: left. Here is a minified version of your code: CLICK HERE
HTML:
<div id="topdiv">
<div class="bigdiv">
<p>big div</p>
</div>
<div id="staticcal">
<p>staticcal</p>
</div>
<div id="staticnews">
<p>staticnews</p>
</div>
</div>
CSS:
#topdiv {
display: inline-block;
background-color:#b0c4de;
min-width: 800px;
}
.bigdiv, #staticcal, #staticnews {
position: relative;
float: left;
border: 2px solid #c7930D;
}
.bigdiv {
margin: 10px 0;
width: 335px;
height: 250px;
}
#staticcal, #staticnews {
display: inline-block;
line-height: 175px;
width: 220px;
height: 100px;
margin: 5px;
margin-top: 10px;
margin-right: 0px;
-webkit-border-radius: 4px; /*This will address iOS 1 to 3.X, Android 1.6-2.1, Safari 3 - 4*/
-moz-border-radius: 4px; /*Firefox 1 to 3.6*/
border-radius: 4px; /*IE 9+, Opera 10.5, Chrome, Safari 5, FireFox 4+, iOS 4, Android 2.1+,
}
p {
text-align: center;
}
HTML:
<div id="main" class="rounded-corners">
<div id="benefits">
<img src="/benefits-heading.png" style="padding: 30px;" />
<div id="corporateside">
<h1>Corporate Benefits</h1>
<p>blah</p>
</div>
<div style="clear: both;"></div>
<div id="employeeside">
<h1>Employee Benefits</h1>
<p>blah</p>
</div>
<div style="clear: both;"></div>
</div>
</div>
CSS:
#corporateside { width: 420px; height: 100%; position: absolute; left: 0; padding: 20px; height: 100%; display: block; }
#corporateside h1 { font-size: 24px; font-weight: 500; }
#corporateside h2 { color: #cc0000; font-size: 18px; font-weight: bold; text-transform: uppercase; padding-top: 10px; }
#corporateside p { padding: 0px; margin-top: -10px; }
#employeeside { width: 420px; position: absolute; right: 0; padding: 20px; height: 100%; display: block; }
#employeeside h1 { font-size: 24px; font-weight: 500; }
#employeeside h2 { color: #cc0000; font-size: 18px; font-weight: bold; text-transform: uppercase; padding-top: 10px; }
#employeeside p { padding: 0px; margin-top: -10px; }
#benefits { position: relative; height: auto; }
#main { width: 940px; height: auto; background-color: #ffffff; margin: 0 auto; padding: 0; background: #ffffff; border: 2px solid #ffc40d; -moz-border-radius: 20px; -webkit-border-radius: 20px; -khtml-border-radius: 20px; border-radius: 20px; }
I have fixed this issue by removing the position: absolute; from each div. Also I removed the <div style="clear: both;"></div> between the two divs. Thanks for your help!
It's because your divs are set with position: absolute;. This removes the div from the document flow and so the containing element behaves as if the divs are not present for its layout.
I'm not sure exactly what you're going for, but if you want to adjust the position of the two divs, try position relative or examine their margins and padding. A CSS reset can be very helpful as a general tool for making consistent layouts, especially across browsers.
Here's a jsfiddle of my suggestion, showing the divs side by side and the container behaving as desired.
http://jsfiddle.net/wCnLZ/
Please help. I want to achieve that text and button on yellow box be alligned left and right (text on left side - margin 20 px; button on right side - margin 20 px) and menu in footer aligned with yellow box.
I can't add picture, sorry.
Edit: Added JSFiddle - http://jsfiddle.net/wqBEf/
This is my css code:
#page
{
width: 960px;
margin-left: auto;
margin-right: auto;
border: 1px solid red;
background-color: blue;
}
#page > #main
{
border: 1px solid #000;
width: 650px;
margin-left: auto;
margin-right: auto;
background: white;
border-radius: 5px;
margin-top: 20px;
}
#main > #inner
{
margin: 20px;
}
#page-title h1
{
font-size: 24px;
text-align: center;
}
#footer-hotline
{
height: 50px;
background-color: rgb(255,207,0);
border-radius: 5px;
box-shadow: 0px 3px 3px #999999;
margin-top: 20px;
border: 1px solid #000;
width: 650px;
margin-left: auto;
margin-right: auto;
position: relative;
z-index: 2;
}
#footer-hotline > .part
{
float: left; width: 33%;
margin-left: 20px;
line-height: 50px;
font-size: 16px;
font-weight: bold;
}
#footer-hotline > .part input
{
vertical-align:middle;
}
#footer
{
margin-top: -25px;
height: 100px;
line-height: 25px;
background-color: white;
text-transform: uppercase;
border: 1px solid black;
}
#footer > .link
{
float: left;
border-right: 1px solid #000;
margin-top: 50px;
}
#footer > .link > div
{
margin-left: 5px;
margin-right: 5px;
}
And this is my html code:
<div id="page">
<div id="main">
<div id="inner">
<div id="page-title">
<img src="myLogo.png" alt="Schulz logo" />
<h1>Some title</h1>
</div>
<div id="content">RenderBody</div>
</div>
<div class="f-c"></div>
</div>
<div id="footer-hotline">
<div class="part">Hotline: 0800/888 888</div>
<div class="part"><input type="submit" class="button" id="callback-button" value="callback" name="callback-button" /></div>
</div>
<div class="f-c"></div>
<div id="footer">
<div class="link"><div>GTC</div></div>
<div class="link"><div>About</div></div>
<div class="link"><div>Help</div></div>
<div class="link"><div>Language</div></div>
</div>
Thanx for answers, suggestions and comments.
See http://jsfiddle.net/wqBEf/1/ for an update.
Noteworthy changes.
I added left align-left and right align-right classes set for float and for text alignment, respectively.
I set your links to display: inline because it is the easiest way to center a list of items horizontally.
Those were the main two changes. The rest of the changes were just to support the above two, such as removing/adding some margins.
You could use the :first-child pseudo-class for the issue of getting the two items to work together (this will only work if you have only two at any one time). It's also well supported going back to IE7
You also need to implement float:right, direction:rtl, and margin-right:
#footer-hotline > .part
{
float: right; width: 33%;
direction: rtl;
margin-right: 20px;
line-height: 50px;
font-size: 16px;
font-weight: bold;
}
#footer-hotline > .part:first-child
{
direction: ltr;
float: left;
margin-left: 20px;
}
Eli Gassert's answer should suffice for centering the nav
Source: http://jsfiddle.net/YZ2Uz/
Demo: http://jsfiddle.net/YZ2Uz/show