Why do CSS div dimensions differ from Devtools dimensions? - css

I am testing responsiveness in my react app and I have come across a pretty confusing issue while working with my devtools console. The width of the element I am working with is 768px. These are the same dimensions for a tablet screen. However, the element width only covers part of the screen as shown in the screenshot below.
Where is this extra space on the right coming from? I believe the element should cover the entire width of the screen since the dimensions are equal. I have also in my CSS file:
html, body {
margin: 0;
padding: 0;
}
My full CSS file looks like this:
#import url("https://fonts.googleapis.com/css?family=Akaya+Telivigala&display=swap");
.projects {
display: inline-block;
width: 500px;
font-size: 1.7em;
color: white;
width: 100%;
height: 100vh;
}
.indivProject {
display: grid;
grid-template-columns: 900px 120px;
}
.projImage img {
width: 450px;
height: 450px;
margin-top: 150px;
}
#media screen and (min-width: 320px) {
.projects {
width: 100%;
margin-left: 60px;
height: 100%;
}
}
#media screen and (min-width: 768px) {
.projects {
width: 100%;
margin-left: 60px;
height: 100%;
}
}
.project-text {
color: white;
font-size: 0.8em;
margin-left: 180px;
margin-top: 240px;
}
.tech {
margin-left: 250px;
font-size: 0.7em;
color: rgb(9, 150, 79);
}
#media screen and (min-width: 320px) {
.project-text {
margin-left: 80px;
font-size: 1.7em;
width: 100%;
}
}
#media screen and (min-width: 768px) {
.project-text {
text-align: center;
}
}
#media screen and (min-width: 320px) {
.projImage img {
display: none;
}
}
a {
text-decoration: none;
color: rgb(9, 150, 79);
}
a:hover {
color: saddlebrown;
}
h4 {
color: rgb(15, 89, 102);
text-align: center;
font-size: 1.2em;
}
The corresponding markup looks like this:
import React from 'react';
import './styles.css';
import nutri from '../../images/nutri.png';
import akan from '../../images/akan.png';
import convo from '../../images/convo.png';
function Projects(){
return (
<div className="projects">
<h4>HIGHLIGHTED PROJECTS</h4>
<div data-aos="zoom-out" className="indivProject">
<div data-aos="zoom-out" className="project-text">
<p>
<h3>TEXTR</h3>
This is a mobile-responsive messaging app built using React and leverages the use of ChatEngine to provide an interactive communication experience. Hosted on Netlify.
</p>
<ul className="tech">
<li>React</li>
<li>Chat Engine</li>
<li>React Testing Library</li>
</ul>
</div>
<div className="projImage"><img src={convo} alt=""></img></div>
</div>
<div data-aos="zoom-out" className="indivProject">
<div data-aos="zoom-out" className="project-text">
<p>
<h3>NUTRIAPP</h3>
This is an application that acts more like a remote doctor. By inputing some personal data such as Weight, Height and Physical activity, the user reveives ther caloric intake recommendation and is able to evaluate their health status.
</p>
<ul className="tech">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
<div className="projImage"><img src={nutri} alt=""></img></div>
</div>
<div data-aos="zoom-out" className="indivProject">
<div data-aos="zoom-out" className="project-text">
<p>
<h3>AKAN NAMES</h3>
Akan names are derived from Ghanian culture. Frequently in Ghana, children are given their first name as a 'day name' which corresponds to the day in the week they were born. This application will help you identify an Akan name based on the time you were born.
</p>
<ul className="tech">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
<div className="projImage"><img src={akan} alt=""></img></div>
</div>
</div>
)
}
export default Projects;
I have tried restarting my devtools but still no resolve.

Related

CSS Block that goes to the end of the page but doesn't activate scroll

Look at the picture below, the purple square that I have created needs to go to the end of the page always and it cannot activate horizontal scroll or push the screen. The version I have is with a fixed width, but that doesn't work response wise, example: the laptop resolution pushes the content to the right because of it (look here: https://i.imgur.com/BXCYUx1.png ). For mobile xs version I have hidden it, so it's just for screens md, lg and xl.
I used Bootstrap for the grid creation. Here is the code for the right section (where the purple is):
<div class="col-xl-6 col-sm-12 job-details">
<div class="job-title"> Some title <div class="bgendsqaure"></div>
</div>
<div class="inner-job">
<div class="job-timelocation"> Subtitle </div>
<div class="job-info">
- Designing web applications & mobile apps <br>
- Developing responsive websites using HTML, CSS, JavaScript <br>
- Execution of sql queries in microsoft sql server <br>
- Development of apps using git <br>
- Project management using jira with everyday team meetings <br>
</div>
</div>
</div>
SCSS:
.job-details {
margin-top: 25px;
}
.job-title {
padding: 20px;
background: $maincolor;
color: white;
font-weight: bold;
font-size: 1.3rem;
text-align: center;
}
.bgendsqaure {
width: 50px;
height: 50px;
background: yellow;
width: 394px;
height: 71px;
background: #cf9bff;
position: absolute;
right: -378px;
top: 0;
display:none; /* hide */
}
.job-timelocation {
padding: 20px;
background: #4454cf14;
text-align: center;
}
.job-info {
display: flex;
justify-content: center;
padding: 20px;
}
#include xl {
.job-timelocation {
margin-left: 33px;
margin-right: 33px;
}
.bgendsqaure {
display: inline;
}
.job-hide {
display: none;
}
}
#include xs {
.explist {
text-align: center;
}
.stitle {
text-align: center;
}
}
JSFiddle: https://jsfiddle.net/n4qeodk1/

How can I keep all my navbar icons in one row when viewing from a mobile device in React?

I am making a pretty simple bottomnav for a project I am working on, and I am having difficulty with the view in mobile mode. From standard desktop, I have a pretty simple, bottomnav with 4 icons, however when I inspect the page in mobile view, it only shows you either the first, or the first and 2nd icon. all of my styling for this component is:
/* Place the navbar at the bottom of the page, and make it stick */
.navbar {
background-color: rgb(75, 90, 72);
overflow: hidden;
position: absolute;
bottom: 0;
min-width:800px;
height:64px;
/* width: 100%; */
}
.navCont {
text-align: center;
position: fixed;
bottom: 0;
width: 100%;
}
.navButton {
margin-left:10vh;
margin-right:10vh;
min-width:10px;
}
.navButtonLeft {
margin-left:10vh;
margin-right:10vh;
min-width:10px;
}
/* Style the links inside the navigation bar */
.navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Change the color of links on hover */
.navbar a:hover {
background-color: #ddd;
color: black;
}
/* Add a color to the active/current link */
.navbar a.active {
background-color: #4CAF50;
color: white;
}
img {
width:32px;
height: auto;
float:left;
margin-bottom: 20px;
}
#media screen and (max-width: 100px) {
.navbar {
display: inline-block;
height:64px;
}
.navCont {
display: flex;
align-content: space-between;
}
.navButton,
.navButtonLeft {
padding: none;
display: inline-block;
}
img {
display: inline-block;
}
}
Any advice or tips would be greatly appreciated!
edit: Here is the component i am working with.
import React from "react";
import home from "./home.png"
import post from "./post.png"
import profile from "./profile.png"
import search from "./search.png"
import "./Footer.css";
class Footer extends React.Component {
render() {
return (
<div class="navCont">
<div class="navbar">
<img src={home} alt="home icon"/>
<img src={profile} alt="home icon"/>
<img src={post} style={{width:"44px", height: "auto"}} alt="home icon"/>
<img src={search} style={{width:"44px", height: "auto"}} alt="home icon"/>
</div>
</div>
);
}
}
export default Footer;
I've revamped your css to use flexbox for laying out the icons in a row; got rid of all the floats and some other rules that seemed unnecessary. I'm not sure this does exactly what you're trying to do (since I don't know exactly what you're trying to do) but I think this is at least a better starting point.
.navCont {
position: fixed;
left: 0;
right: 0;
bottom: 0;
width: 100%;
background-color: rgb(75, 90, 72);
}
.navbar {
height: 64px;
display: flex;
justify-content: center;
}
/* Style the links inside the navigation bar */
.navbar > * {
flex: 0 0 auto;
padding: 14px 16px;
}
/* Change the color of links on hover */
.navbar a:hover {
background-color: #ddd;
color: black;
}
img {
width: 32px;
max-width: 100%;
height: auto;
}
<div class="navCont">
<div class="navbar">
<a href="/" class="navButton">
<img src="https://via.placeholder.com/64x64.png/fff/000/?text=A" />
</a>
<a href="Profile" class="navButton">
<img src="https://via.placeholder.com/64x64.png/fff/000?text=B" />
</a>
<a href="Post" class="navButton">
<img src="https://via.placeholder.com/64x64.png/fff/000?text=C" />
</a>
<a href="Search" class="navButton">
<img src="https://via.placeholder.com/64x64.png/fff/000?text=D" />
</a>
</div>
</div>

CSS Grid - Why is my text being cut off when I resize to smaller screens?

Like the title says, it is only the text at the far right off the screen that is cut off, when I inspect and view smaller device sizes.
Here is my HTML:
* {
margin: 0;
}
body {
overflow-x: hidden;
}
.wrapper1 {
display: grid;
grid-template-columns: 6fr 3fr;
border: 2px solid #6cccb0;
overflow: hidden;
height: 30px;
background-color: #6cccb0;
width: 1700px;
}
<div class="wrapper1">
<div>
<p class="item1">SHIPPED for free | GUARANTEED TO LAST</p>
</div>
<div>
<p class="item2">LOG IN | REGISTER | CUSTOMER SERVICE | 1-800-692-8259 </p>
</div>
</div>
Thanks
Why not remove the hard-set width and the overflow: hidden properties? These are causing your content to be both offscreen and also cut.
* {
margin: 0;
}
.wrapper1 {
display: grid;
grid-template-columns: 2fr 1fr;
align-items: center;
border: 2px solid #6cccb0;
background-color: #6cccb0;
}
<div class="wrapper1">
<div>
<p class="item1">SHIPPED for free | GUARANTEED TO LAST</p>
</div>
<div>
<p class="item2">LOG IN | REGISTER | CUSTOMER SERVICE | 1-800-692-8259 </p>
</div>
</div>
You could use
width: 100%;
instead of
width: 1700px;
So your item2 text will not disappear.
Edit 1:
In case you want to keep your text in one line, I suggest using #media queries to change your font-size. so your css must be something like this.
* {
margin: 0;
}
.wrapper1 {
display: grid;
grid-template-columns: 2fr 2fr;
border: 2px solid #6cccb0;
height: 30px;
background-color: #6cccb0;
font-size: 1em;
color: orange;
}
#media only screen and (max-width: 440px) {
.wrapper1 {
font-size: 0.4em;
color: yellow;
}
}
#media only screen and (min-width: 440px) {
.wrapper1 {
font-size: 0.5em;
color: aqua;
}
}
#media only screen and (min-width: 560px) {
.wrapper1 {
font-size: 0.6em;
color: green;
}
}
#media only screen and (min-width: 728px) {
.wrapper1 {
font-size: 0.8em;
color: blue;
}
}
#media only screen and (min-width: 1024px) {
.wrapper1 {
font-size: 1em;
color: red;
}
}
I put color rules to help you understand what's happening. You can delete them. I hope it would help you.

How to set media queries for high resolution screens in html

I have a query. How to set media queries for high-resolution screens like 4k, 5k, retina display etc. As I have been reading about it, I understood we can use resolution specific media queries. But I have a query of how to understand the breakpoints for 4k 5k screens and how to know they reliability towards future high-resolution screens.
Can anyone suggest how to use CSS for high res screens?
If you will use relative units (em, or rem) it will give you a possibility to equal scaling for elements, and to write a minimum media queries.
EDITED:
You can see how to use em on this example:
.parent {
background: red;
font-size: 20px;
padding: 1em;
}
.child {
margin: 1em;
font-size: 15px;
}
.childOfChild {
margin-left: 1em;
font-size: 2em;
}
<div class="parent">
<h2 class="child">
Hello World!
<span class="childOfChild">Some Text</span>
</h2>
</div>
You can see how to use rem on this example:
html {
font-size: 16px;
}
.child {
font-size: 1rem;
padding: 1rem;
background: blue;
color: white;
}
.childOfChild {
font-size: 0.8rem;
margin-left: 1.2rem;
}
#media (min-width: 2000px) {
html {
font-size: 20px;
}
}
#media (max-width: 1200px) {
html {
font-size: 14px;
}
}
#media (max-width: 768px) {
html {
font-size: 12px;
}
}
<div class="parent">
<h2 class="child">
Hello World!
<span class="childOfChild">Some Text</span>
</h2>
</div>

How to modify responsive timeline?

http://codepen.io/kjohnson/pen/azBvaE
My friend and I are thinking of using that timeline in our website. But the problem is we've 5 sections that needs to be added to timeline, whereas the original timeline have only 3 sections.
I've tried to add two more sections to that code, but it's losing its shape and responsiveness.
Is it possible to extend that timeline and maintain its responsiveness?
HTML
<!-- STEPS -->
<section id="Steps" class="steps-section">
<h2 class="steps-header">
Responsive Semantic Timeline
</h2>
<div class="steps-timeline">
<div class="steps-one">
<img class="steps-img" src="http://placehold.it/50/3498DB/FFFFFF" alt="" />
<h3 class="steps-name">
Semantic
</h3>
<p class="steps-description">
The timeline is created using negative margins and a top border.
</p>
</div>
<div class="steps-two">
<img class="steps-img" src="http://placehold.it/50/3498DB/FFFFFF" alt="" />
<h3 class="steps-name">
Relative
</h3>
<p class="steps-description">
All elements are positioned realtive to the parent. No absolute positioning.
</p>
</div>
<div class="steps-three">
<img class="steps-img" src="http://placehold.it/50/3498DB/FFFFFF" alt="" />
<h3 class="steps-name">
Contained
</h3>
<p class="steps-description">
The timeline does not extend past the first and last elements.
</p>
</div>
</div><!-- /.steps-timeline -->
CSS
$outline-width: 0;
$break-point: 500px;
#import url(http://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic);
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
font-family: lato;
}
$gray-base: #999999;
$brand-primary: #3498DB; //Zen Blue
.section-header {
color: $brand-primary;
font-weight: 400;
font-size: 1.4em;
}
.steps-header {
#extend .section-header;
margin-bottom: 20px;
text-align: center;
}
.steps-timeline {
outline: 1px dashed rgba(red, $outline-width);
#media screen and (max-width: $break-point) {
border-left: 2px solid $brand-primary;
margin-left: 25px;
}
#media screen and (min-width: $break-point) {
border-top: 2px solid $brand-primary;
padding-top: 20px;
margin-top: 40px;
margin-left: 16.65%;
margin-right: 16.65%;
}
&:after {
content: "";
display: table;
clear: both;
}
}
.steps-one,
.steps-two,
.steps-three {
outline: 1px dashed rgba(green, $outline-width);
#media screen and (max-width: $break-point) {
margin-left: -25px;
}
#media screen and (min-width: $break-point) {
float: left;
width: 33%;
margin-top: -50px;
}
}
.steps-one,
.steps-two {
#media screen and (max-width: $break-point) {
padding-bottom: 40px;
}
}
.steps-one {
#media screen and (min-width: $break-point) {
margin-left: -16.65%;
margin-right: 16.65%;
}
}
.steps-two {
}
.steps-three {
#media screen and (max-width: $break-point) {
margin-bottom: -100%;
}
#media screen and (min-width: $break-point) {
margin-left: 16.65%;
margin-right: -16.65%;
}
}
.steps-img {
display: block;
margin: auto;
width: 50px;
height: 50px;
border-radius: 50%;
#media screen and (max-width: $break-point) {
float: left;
margin-right: 20px;
}
}
.steps-name,
.steps-description {
margin: 0;
}
.steps-name {
#extend .section-header;
#media screen and (min-width: $break-point) {
text-align: center;
}
}
.steps-description {
overflow: hidden;
#media screen and (min-width: $break-point) {
text-align: center;
}
}
If you a novice I'd recommend you LEARN first. Copy templates/snippets is good to save your time when you know what you are doing.
I found a perfect tutorial for you here
Just to emphasize that's my opinion, I hope it helps in a certain way..
EDIT: If still want to develop in that way here's a codepen snippet with a fully responsive horizontal timeline. Just have to put more <li> inside the <ul>

Resources