Why is chrome rendering this CSS in such a way - html

I was trying to create a circle with i icon in it for with CSS. However, when page is first rendered the circle looks like an inverted egg and covers the border around it slightly. (Zoom in the browser to see issue in more details)
The tricky part is, if you open Dev Tools and change any value related to it's position(width, height, whatever), everything will snap back to normal and it will become a circle.
https://jsfiddle.net/2yjashje/
<div class="round-egg">
i
</div>
.round-egg {
font-size: 14px;
background: white;
color: #8DC641;
border-radius: 10px;
cursor: help;
border-bottom: none !important;
border: 4px solid #8DC641;
width: 20px;
height: 20px;
text-align: center;
}
What is going on here?

I put the letter "i" in its own span and increased the margin from top to vertically centre it. As for the circle, I modified the border-radius property, and then removed the border-bottom: none; property as well. Assuming you want a circle, you need the bottom border.
https://jsfiddle.net/2yjashje/3/
<div class="round-egg">
<span class="icon">i</span>
</div>
.round-egg {
font-size: 14px;
background: white;
color: #8DC641;
border-radius: 30px;
cursor: help;
border: 4px solid #8DC641;
width: 20px;
height: 20px;
text-align: center;
display: table-cell;
}
.icon {
display: block;
margin-top: 2px;
}

Related

Border bottom and the header move together

In my nav, I am separating my section with some text and a horizontal line. For each section this repeats. I am doing this as shown below:
.navSectionHeader {
font-size: 1em;
color: #fff;
margin-left: 5px;
margin-bottom: 10px;
font-family: "Roboto";
font-weight: 700 !important;
border-bottom: 2px solid #6c6c6c;
}
/*.navSectionHeader::after {
content: ' ';
display: block;
border: 2px solid;
border-color: #6c6c6c;
margin-left: 0px !important;
}*/
The issue is, my text is now pretty much stuck to the left of the parent div. It should be with some margin to the left while keeping the bottom border start from 0px to the left. When I try to move it with margin-left: 5px; it ends up moving the border-bottom as well. I tried this with ::after as shown in the commented bit, adding !important to the end but nothing changes. Am I doing this the wrong way? Sorry, I'm a front-end noob!
Edit: The section header is in a <span> if it makes a difference.
Use padding instead of margin.
.navSectionHeader {
padding-left: 5px;
}
An example to see difference,
div {
display: inline-block;
width: 100px;
height: 20px;
border-bottom: 1px solid black;
background: red;
color: white;
}
.padding {
padding-left: 5px;
}
.margin {
margin-left: 5px;
}
<div class="margin">margin</div><br>
<div class="padding">padding</div>

CSS: Curved corner + extension

How can I get the element in the attached pic?
I need a line + curve to right at top + extension.
I can use div's, span or another idea if you have.
I tried to use 2 divs with round borders. But they don't connect in a pretty way in the corner.
I assume you mean the dot in the corner. It's not particularly robust to change, and it will currently only work on a white background. However, with some SCSS and variables, it would be a lot cleaner.
The biggest issue I have with it is that the surrounding box is required to have a relative position, which might affect layout elsewhere.
.fancy {
position: relative;
padding: 12px;
border: 3px solid #ccc;
border-radius: 8px;
}
.fancy::after {
position: absolute;
bottom: -11px;
left: -11px;
content: "";
height: 14px;
width: 14px;
display: inline-block;
border: 4px solid white;
border-radius: 11px;
background-color: gray;
}
p {
font-family: Arial;
font-size: 14px;
}
<p class="fancy">
Some text
</p>
The padding around the dot is given by the border-width (4px).
The colour of the dot is defined by the background-color.
The places where 11px is used are computed by the border-width + the [height (or width) / 2] and used to keep the dot circular and in the corner.
It's a little ambiguous what you want. If you wanted the title block in there too, then add this:
.fancy {
position: relative;
padding: 12px;
border: 3px solid #ccc;
border-radius: 8px;
}
.fancy .title {
display: table;
margin-top: -2.2em;
margin-bottom: 0.2em;
padding: 6px 8px;
border: 6px solid white;
border-radius: 12px;
background-color: #99ccff;
}
p {
font-family: Arial;
font-size: 14px;
}
<p class="fancy">
<span class="title">A fancy title</span>
Some text with a fancy title.
</p>

Why does box-sizing: padding-box look different on a mac?

#map-search-button {
display: inline;
float: right;
border-style: solid;
border-image: url(https://i.imgur.com/r35pKjB.png) 8 8 8 8;
border-width: 5px 5px 5px 5px;
height: 50px;
width: 125px;
background-color: #00ACC8;
background-clip: padding-box !important;
font-size: 1.5em;
text-align: center;
line-height: 40px;
color: white;
}
<div id="map-search-button">Find us!</div>
On Chrome on Windows, the button looks the way I expected:
But on Chrome on a Mac, the button looks like this:
Why is this? Is there anything in the CSS I can change that would keep the border image solid?
I’d highly recommend creating a rounded button with border-radius rather than trying to implement a border-image. See inline example below.
As for a technical explanation of why yours doesn’t look right, you may want to look into best practices for producing a border-image if you want to further pursue that route. Your Mac may have a Retina display and be improperly scaling your image.
Using border-radius:
body {
font-family: impact, sans-serif;
letter-spacing: .02em;
}
#map-search-button {
width: 125px;
height: 50px;
line-height: 50px;
background-color: #00ACC8;
border: 5px solid #00ACC8;
border-radius: 8px;
font-size: 1.5em;
text-align: center;
color: white;
}
<div id="map-search-button">FIND US!</div>

Attempting to position font awesome icon in the middle of a div

I have a basic div with an icon and some text. If I don't try and change the size of the icon it lines up perfect.
But I want the icon to be bigger but still sit centred in the text. The problem is the icon doesn't sit centred in the div, it seems to move up so the text ends up lined to the bottom of the icon and the icon sits higher in the div. I expect the text to be centred in the icon as the icon would be centred in the div....
You can see it on this fiddle;
http://jsfiddle.net/8mjN7/1/
Pulling in
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
CSS
div {
border: 1px solid red;
line-height: 40px;
padding: 10px 0px;
font-size: 14px;
}
i {
margin-left: 10px;
font-size: 30px;
}
HTML
<div>
<i class="fa fa-globe"></i>
Foo bar
</div>
The simplest solution is to use the vertical-align property as follows:
i {
margin-left: 10px;
font-size: 30px;
height: 30px;
vertical-align: middle;
}
see demo at: http://jsfiddle.net/audetwebdesign/9ATq8/
Note: It is necessary to specify height: 30px for the i element and line-height: 40px of the parent container, otherwise, any default values may not work as expected.
CSS table-cell also works but the added complexity is not needed in this case.
I use this to make sure the icon is in the middle. The padding & line-height i think are the two most important.
background: rgba(143, 211, 157, 1);
border-radius: 100%;
color: #FFFFFF;
display: inline-block;
font-size: 55px;
height: 45px;
width: 45px;
padding: 40px 45px 40px 35px;
line-height: 45px !important;
transition: .5s;
Did you try to display the div like a table like this?
div {
display:table;
border: 1px solid red;
line-height: 40px;
font-size: 14px;
}
i {
display:table-cell;
text-align:center;
vertical-align:middle;
font-size: 30px;
}
Do you want something like this Link
CSS:
div {
border: 1px solid red;
line-height: 40px;
padding: 10px 0px;
font-size: 14px;
display:table;
vertical-align:middle;
width:100%;
}
i {
margin-left: 10px;
font-size: 30px;
height: 30px;
display:table-cell;
vertical-align:middle;
}

Sidebar not moving up despite nothing in it's way?

I'm working on a page located here: http://www.fusionhost.co.uk/newsite2/
I'm trying to get the right sidebar that contains "UK Servers, Money Back etc" to move up so it is directly below the client reviews box. Using firebug I see that nothing is in the way and it should be moving up without a problem, but it isn't.
It seems to move up and down with the height of the Fuse with us box, despite that box's height not covering the portion above it.
You have the welcome and testimonials divs, which are block elements.
if you move the rpanel immediately after testimonials and float it right, the panel will move up.
Try swapping this style in your css:
Replace this:
.rpanel .box {
border: 1px solid #E9E9E9;
color: #AEAEAE;
float: left;
font-family: tahoma;
font-size: 11px;
margin-bottom: 20px;
padding: 15px;
width: 178px;
}
With this:
.rpanel .box {
border: 1px solid #E9E9E9;
color: #AEAEAE;
float: left;
font-family: tahoma;
font-size: 11px;
margin-bottom: 20px;
padding: 15px;
position: relative; /* ADDED */
top: -120px; /* ADDED */
width: 178px;
}