In the above image, Chrome is on the left and Safari is to the right. The wrapper (green) element in my code is being rendered with different heights in Chrome and Safari.
Other similar questions on stackoverflow direct to this stackoverflow question/answer. I applied the solution given there and added specific heights to all elements and made them display: flex.
What do I need to do to make the wrapper element to be rendered with the same height across Chrome and Safari ?
.block, .level-1, .super-wrapper, .wrapper, .wrapper-initial, .initial {
display: flex;
justify-content: center;
align-items: center;
}
.block {
border: 1px solid #c4c4c4;
height: 2em;
width: 4em;
}
.level-1 {
height: 3em;
}
.super-wrapper {
height: 3em;
font-size: 0.4em;
}
.wrapper {
background-color: #8fbc8f;
height: 3em;
width: 3em;
}
.wrapper-initial {
height: 2em;
}
.initial {
height: 2em;
}
<div class="block">
<div class="level-1">
<div class="super-wrapper">
<div class="wrapper">
<div class="wrapper-initial">
<div class="initial">X</div>
</div>
</div>
</div>
</div>
</div>
The problem is in using em without unifying the base (resetting), if you checked the computed styles tab in DevTools, you'll find that font-size: 0.4em; is computed to different px values,
You don't want to use px and still want to use em? you just can add:
html {
font-size: 16px; // or any value you want!
}
html {
font-size: 16px;
}
.block, .level-1, .super-wrapper, .wrapper, .wrapper-initial, .initial {
display: flex;
justify-content: center;
align-items: center;
}
.block {
border: 1px solid #c4c4c4;
height: 2em;
width: 4em;
}
.level-1 {
height: 3em;
}
.super-wrapper {
height: 3em;
font-size: 0.4em;
}
.wrapper {
background-color: #8fbc8f;
height: 3em;
width: 3em;
}
.wrapper-initial {
height: 2em;
}
.initial {
height: 2em;
}
<div class="block">
<div class="level-1">
<div class="super-wrapper">
<div class="wrapper">
<div class="wrapper-initial">
<div class="initial">X</div>
</div>
</div>
</div>
</div>
</div>
The problem is that Safari and Chrome use different font sizes for your elements. When you use em, it scales to the current element's font size.
To fix your problem, make sure that the element's font size is the same in every browser, or use rem as a unit instead. rem always uses the root font size of the document.
https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units
Related
I'm trying to contain an image inside the first div of this page and it's outside of it for some reason. All the assets are in a flexbox. It works completely fine when I put text inside that div but not an image.
I've circled in red which image and div I'm talking about. The code snippet won't show you what I'm talking about since it isn't the full code.
Here is the github repository if someone needs the full code: github.com/hiashley/Ashley-Yu-React-Portfolio
.landing {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.introWrapper {
width: 1000px;
}
.intro1 {
font-size: 25px;
text-align: center;
font-family: 'Yapari';
align-items: center;
justify-content: center;
margin-top: 23px;
}
.intro2 {
font-size: 25px;
text-align: center;
font-family: 'Yapari';
/* font-weight: 72; */
margin-top: 50px;
}
#introCircle {
border: 2px solid black;
border-radius: 50%;
width: 230px;
height: 70px;
margin: auto;
}
.icons {
border: 2px solid black;
height: 50px;
}
.icon1 {
width: 30px;
}
<div id='landing' className={styles.landing}>
<div className={styles.introWrapper}>
<div className={styles.icons}>
<img src={icon1} className={styles.icon1}/>
</div>
<div id={styles.introCircle}>
<h1 className={styles.intro1}>HELLO I'M</h1>
</div>
<LastName />
<h1 className={styles.intro2}>A FULL STACK DEVELOPER</h1>
</div>
</div>
As I checked the code, You have added Position "Absolute" to the "img" tag, That's why Image is going outside to your div. You must need to add class and then add CSS to image tag.
View Screenshot
Add style to className rather than add style to html tags directly.
Tag style is globally, module className style is locally.
I'm trying to implement a simple three vertical dot menu, and I'm encountering some rather strange behavior. Even though they all have a determined height and width, the three dots render as non-square, seemingly depending on the grandparent container's dimensions. I've tried using px, rem, em, and percentages to size them, but the issue persists.
I've also tried laying the dots out by setting the parent element's width and height explicitly and making it flexbox, as well as removing all the padding and margin both on the parent and dots, but nothing seems to alleviate the issue. The code looks like this:
.grandparent {
display: flex;
width: 100%;
margin-bottom: 10px;
align-items: center;
}
.item1 {
height: 50px;
width: 50px;
margin-left: 15px;
height: 50px;
width: 50px;
position: relative;
}
.item1 img {
border-radius: 50%;
height: 50px;
}
.item2 {
flex: 1 1;
}
.title {
text-align: left;
margin: 0 0 5px 13px;
font-size: 20px;
font-weight: 400;
}
.subtitle {
text-align: left;
margin-left: 13px;
margin-top: -9px;
font-size: 13px;
color: #808080;
}
.parent {
margin-right: 11px;
padding: 5px 8px;
cursor: pointer;
}
.dot {
width: 6px;
height: 6px;
margin-bottom: 4px;
border-radius: 50%;
background-color: #808080;
}
.no-appearance {
appearance: none;
border: 0;
background: none;
}
<div class="grandparent" style="width: 375px; height: 50px">
<div class="item1"><img src="https://picsum.photos/50/50" /></div>
<div class="item2">
<div class="title">Example text</div>
<div class="subtitle">Example text</div>
</div>
<button class="parent no-appearance">
<div class="dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</button>
</div>
Edit: I added some more code to the snippet to try to reproduce the issue, but unfortunately it does not seem to be reproducible even though it is consistently reproducible in my development environment.
Here's an example of how this renders in Chrome 88.0 when the grandparent is 410x50:
... and here's what it looks like when the grandparent is 375 x 50:
Any idea what might be at play here?
What about html-entitie ⋮?
https://www.w3schools.com/charsets/ref_html_entities_v.asp
.target {
position: relative;
width: 100%;
margin-bottom: 10px;
}
.target::after {
position: absolute;
right: 0;
top: 0;
font-size: 2em;
color: #808080;
content: '\0022EE';
}
.target:hover::after{
cursor: pointer;
}
<div class="target"></div>
There is a strange effect with the css setting that has come with the latest chrome version.
Do you've an idea why the second box is below the first one (see image) ?
display: inline-block;
some help is welcomed.
If you want the boxes to anchor to the top you can use the CSS vertical-align: top property.
Here is the example,
Please view it in a full screen mode so that the boxes appear side by side.
.ic3a-container {
width: 100%;
color: white;
}
.ic3a-mini-box-c {
display: inline-block;
width: 500px;
vertical-align:top;
}
.ic3a-mini-box {
height: 100px;
margin: 15px;
padding: 20px;
background-color:#990033;
}
.ic3a-mini-box i {
display: block;
height: 100%;
line-height:100px;
font-size: 60px;
width: 100px;
float: left;
text-align: center;
border-right: 2px solid rgba(255, 255, 255, 0.5);
margin-right: 20px;
padding-right: 20px;
color: white;
}
.ic3a-mini-box .value {
font-size: 2em;
}
.ic3a-mini-box .measure {
font-size: 1.5em;
}
.ic3a-mini-box .description {
margin-top: 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="ic3a-container">
<div class="ic3a-mini-box-c">
<div class="ic3a-mini-box">
<i class="ic3a-sep fa fa-cubes"></i>
<div class="value">$4 500</div>
<div class="measure">License</div>
<div class="description"><span class="diff">+23%</span>difference from previous quarter</div>
</div>
</div>
<div class="ic3a-mini-box-c">
<div class="ic3a-mini-box">
<i class="ic3a-sep">Icon</i>
<div class="value">Amount</div>
<div class="measure">AmountLabel</div>
<div class="description"><span class="diff">Amount2</span> Amount2Label</div>
</div>
</div>
</div>
Actually its working fine as expected only, when it is coming below means when container width reduce by the screen why because you given width: 100%; to the parent and given fixed width to the child elements, still you want that side by side only give white-space: nowrap; to the parent element.
There is an another way too, you can you give display: table; to the parent element and for child's give display: table-cell;. It wont come down anymore
Displaying inline block does exactly as it says, if in your markup you have any spaces it will render these spaces as well (the white space - it is supposedly a bug - i see it as a bug as inline should butt up next to each other), example is what you have displayed. With the width of both of the boxes and the space next to them will result in the boxes breaking down.
There are a few ways to remove this:
<div>Element</div><!--
--><div>Element 2<div>
or you can do:
<div>Element</div><div>Element</div>
Will result in the blocks showing inline next to one another. Another way to combat this is to use a negative margin:
.class{
margin-left: -3px;
}
There is also the workaround of setting the parent element to:
font-size: 0;
or
white-space: nowrap;
I would recommend using flexbox on the parent element personally, as this will stop your line break from happening.
You can read more on this here:
https://css-tricks.com/fighting-the-space-between-inline-block-elements/
.ic3a-container {
width: 100%;
color: white;
}
.ic3a-mini-box-c {
display: inline-block;
width: 500px;
}
.ic3a-mini-box {
height: 100px;
/* margin: 15px;*/
padding: 20px;
background-color:#990033
}
.ic3a-mini-box i {
display: block;
height: 100%;
line-height:100px;
font-size: 60px;
width: 100px;
float: left;
text-align: center;
border-right: 2px solid rgba(255, 255, 255, 0.5);
margin-right: 20px;
padding-right: 20px;
color: white;
}
.ic3a-mini-box .value {
font-size: 2em;
}
.ic3a-mini-box .measure {
font-size: 1.5em;
}
.ic3a-mini-box .description {
margin-top: 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="ic3a-container">
<div class="ic3a-mini-box-c">
<div class="ic3a-mini-box">
<i class="ic3a-sep fa fa-cubes"></i>
<div class="value">$4 500</div>
<div class="measure">License</div>
<div class="description"><span class="diff">+23%</span>difference from previous quarter</div>
</div>
</div>
<div class="ic3a-mini-box-c">
<div class="ic3a-mini-box">
<i class="ic3a-sep">Icon</i>
<div class="value">Amount</div>
<div class="measure">AmountLabel</div>
<div class="description"><span class="diff">Amount2</span> Amount2Label</div>
</div>
</div>
</div>
I just have removed margin:15px from ic3a-mini-box class.
You can check in browser and see you get the result as expected or not?
Hope this helps.
I have a page layout that I would like to make responsive. The page is currently split 50/50 down the middle vertically. I achieved this by making the Section div display as a table and the divs inside as cells. I also have an absolute positioned Title at the top-center of the page.
I would like to make is such that when the page is viewed on a smaller screen (e.g. tablet or mobile) the 50/50 split becomes horizontal, with all of the contained text centered horizontally and vertically, and with the Title remaining at the top-center of the page.
Here is my code:
html,
body,
section,
div {
height: 100%;
}
body {
color: #000000;
font-family: Cinzel, serif;
font-size: 1.25rem;
line-height: 150%;
text-align: center;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
div {
width: 50%;
padding: 1rem;
}
h1 {
font-size: 1.75rem;
}
.logo {
text-align: center;
color: red;
position: absolute;
width: 100%;
}
.container {
display: table;
height: 100%;
width: 100%;
}
.cell {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.left-half {
background: #FFFFFF;
color: #000000;
}
.right-half {
background: #000000;
color: #FFFFFF;
}
<body>
<section class="container">
<header class="logo">
<h1>Title</h1>
</header>
<div class="left-half cell">
<h1>First Half</h1>
</div>
<div class="right-half cell">
<h1>Second Half</h1>
</div>
</section>
</body>
Any help would be greatly appreciated.
Use media queries for smaller screens in which you change display: tableand display: table-cell to display: block in .container and .cell.
And definitely erase that div { width: 50%; } rule - that affects ALL divs, which you certainly won't want! (Write that 50% width into the .cell rule instead, and add a media query rule for it for smaller sizes that makes it 100%.
I've managed to use the preceding <span> method of centering items, which is all well, except for one little tiny issue illustrated in this image: http://imgur.com/UoKFW6P
how do i fix this? here is my css and html:
* {
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
text-align: center;
}
#font-face {
font-family: myfirstfont;
src: url(century-gothic.ttf);
}
body,
html {
height: 100%;
white-space: -0.125em;
background-color: rgb(0, 0, 0);
}
#wrapper {
height: inherit;
min-height: 100%;
}
.O1-3 {
color: white;
width: 100%;
height: 33.5%;
display: inline-block;
text-align: center;
font-family: myfirstfont;
}
div span {
height: 100%;
vertical-align: middle;
display: inline-block;
}
div a {
font-size: 35px;
display: inline-block;
font-style: italic;
text-decoration: none;
}
#media screen and (min-width:600px) {
.O1-3 {
height: inherit;
width: 33.3%;
}
}
</style>
</head>
<body>
<div id="wrapper">
<div class="O1-3" id="one">
<span></span>
<a id="n-textonly">Luis Rojas</a>
</div>
<div class="O1-3" id="two">
<span></span>
<a id="c-textonly">Contact</a>
</div>
<div class="O1-3" id="three">
<span></span>
<a id="rw-textonly">Recent Work</a>
</div>
</div>
</body>
</html>
There are multiple methods of centering in css, but without a definitive height, you're confined to a just few methods. Here are a few techniques I put together and commented out for you to take a look at: https://jsfiddle.net/73mtxgcc/3/
There are other techniques such as using flex or using display:table, but I find those, personally, either sloppy or not quite supported enough. As well, if you have something relative to the window, then you can always also use
.element{
display: inline-block;
margin: 0 auto;
}
with .element being the parent of the content you'd like to center.
If you have any more questions, or if you need any further clarifications, then please don't hesitate to ask!
You want to give all three columns the same padding with auto width, to get the text to be evenly spaced, then the wrapper centers the entire group. You get same amount of space on each side of the group, and then equal spacing in-between, so the center column ends up not being in the exact center of the page, but it has a very balanced visual effect for the page as a whole. You still need some adjustments with break-points though, I added one.
#wrapper {
width: auto;
height: inherit;
min-height: 100%;
}
.O1-3 {
padding: 1em;
color: white;
width: auto;
height: 33.5%;
display: inline-block;
text-align: center;
font-family: myfirstfont;
}
#media screen and (min-width:600px) {
.O1-3 {
padding: 2em;
height: inherit;
}
}
#media screen and (min-width:1000px) {
.O1-3 {
padding: 5em;
}
}
When it comes to formatting HTML content with CSS, you should really use Flexbox. It is becoming really popular and is widely supported. In the code below, I have added a display: flex; property to your #wrapper. This creates a flex-box out of the wrapper. From there, I added a flex-direction of row, which will automatically format it's three child elements horizontally. In the media query, I have changed the flex-direction property so that the wrapper's child elements are formatted vertically.
-- Hope this helps.
<html>
<head>
<style>
* {
padding: 0px 0px 0px 0px;
margin: 0px 0px 0px 0px;
text-align: center;
}
#font-face {
font-family: myfirstfont;
src: url(century-gothic.ttf);
}
body,
html {
height: 100%;
white-space: -0.125em;
background-color: rgb(0, 0, 0);
}
#wrapper {
height: inherit;
min-height: 100%;
display: flex;
flex-direction: row;
}
.O1-3 {
color: white;
width: 100%;
height: 33.5%;
text-align: center;
font-family: myfirstfont;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
div span {
height: 100%;
vertical-align: middle;
display: inline-block;
}
div a {
font-size: 35px;
display: inline-block;
font-style: italic;
text-decoration: none;
}
#media screen and (max-width:600px) {
.O1-3 {
height: inherit;
width: 100%
margin: auto;
}
#wrapper {
flex-direction: column;
}
}
</style>
</head>
<body>
<div id="wrapper">
<div class="O1-3" id="one">
<span></span>
<a id="n-textonly">Luis Rojas</a>
</div>
<div class="O1-3" id="two">
<span></span>
<a id="c-textonly">Contact</a>
</div>
<div class="O1-3" id="three">
<span></span>
<a id="rw-textonly">Recent Work</a>
</div>
</div>
</body>
</html>