Need help getting images to display in HTML and SCSS - html

I am really new to HTML and CSS (SCSS in this case), and am having issues getting an Image to display properly on a localhost page I have been experimenting on. I will post my HTML lines, as well as my SCSS lines below. Maybe you guys can tell me what I am doing wrong so I can move ahead.
I have tried linking just the project folder directory path, all the way up to the WHOLE path through my computer to the image. I have quadruple checked the names on the files and the image as well. I believe it is probably just a Syntax error.
<!--HTML LINES:-->
<div id="Center.Logo">
<img src="sberube-portfolio-site-f29e4e843dc2\src\app\home\home\home.component.images\center-logo.png"
alt="Center Circle" style=" width: 250px; height: 250px;"> <!--Desired image -->
</div>
/* SCSS LINES: */
#Center.Logo {
img{
margin: auto;
align-content: center;
}
}
I expect the image to display in the CENTER of the page, instead, it simply gives me the ALT tag next to a little picture icon on the bottom left of the page.

I think your selector should be #Center.Logo in your code it's look like #center.Logo
And if you want looks like it centered try this
And if you can't getting images try working around with your project structure.
<img src="../assets/img/centered-logo.jpg"> etc not whole path or something.

The first thing I noticed is you use a dot inside the name of your id.
This is a problem, since in css the dot is part of a class selector.
The Rule #CSS.Logo {...} applies to an element that has both, an id of 'CSS' and a class of 'Logo'. Something like this:
<div id="CSS" class="Logo">
...
</div>
There is no element like that in your code, so the css rules are not applied.
Second, your original css code is not suitable to center an image within another container.
// This is your original code as you posted it:
img {
margin: auto;
align-content: center;
}
The rule align-content is only applicable in a flex box container. You could however use margins to center the image horizontally like this:
img {
display: block;
margin: 0 auto;
}
What you probably want instead is this:
<div id="center-logo">
<img src="your-image.png" alt="Center Circle">
</div>
body {
margin: 0; // making sure you have the whole page at your disposal
}
#center-logo {
height: 100vh; // using the full height of the viewport
// this is where the actual centering happens:
display: flex; // this is necessary for the following 3 rules (flex box)
flex-flow: row nowrap; // in this case this could also be column nowrap
align-items: center; // vertical center
justify-content: center; // horizontal center
img {
// set a width and height so the image does not stretch and to avoid repositioning
// the image (or other content if there is any) as soon as the image has been loaded
width: 250px;
height: 250px;
}
}
Notice I have used small letters for the id name, because it usually helps avoiding issues caused by misspelling the names afterwards.

I'm assuming it is a regular html and css.
You can compile with node.
npm init
npm install node-sass
Add this to your package.json (in scripts)
"scss": "node-sass --watch scss -o css"
Create two Folders.
CSS and SCSS.
Inside each one, the file style. (With the right termination)
css> style.css eg
and finally
npm run scss
Everything you type in scss, it converts to css.

Related

Why does the wrapper div only take some part of the page when it has all the components in it?

I am trying to style the background of a react app page. So, naturally, I style the main div that has all the components in it with the background property in CSS. This main div has a className named Wrapper in my app. However, when I do that, only part of the screen changes the background whereas I expect it to take the full screen. Here's the code and here's how it looks:
JSX:
render() {
return (
<div className="wrapper" >
<div>Inner content</div>
</div>
) }
CSS:
.wrapper {
overflow: hidden;
background: linear-gradient(#42275a, #734b6d);
}
As you can see only the top part changes color, but the rest of the page is still white.
I have tried adding to the wrapper: "height: 100%;", "min-height: 100%" and/or "height: 100vh;", "min-height: 100vh" but nothing has worked.
I also tried to change the body property in CSS like so
body {
background: linear-gradient(#42275a, #734b6d);
}
but what I get is an ugly line that seems to separate the wrapper from the body like this:
My question is, why is the main div (wrapper) taking up only a small part of the screen when actually it is the main div which contains all that content that seems to go off into the white screen. Why doesn't it take up the entire screen?
Also, why is body separate from wrapper or vice versa?
And lastly, how do I change the background without any kind of separation like that line? Because what is even more weird is that the body seems to be fragmented as well. See this image where you can see the body of the document seems to be fragmented (notice the line that separates colors):
Some more code as requested. I am not sure if this is useful but I guess this is all that is relevant.
This is the App.js file's code:
render() {
if (this.state.loading) {
return null;
}
else {
return (
<div className='app'>
{this.state.user ?
<LoggedIn /> :
(<HomePage />)}
</div >
);
}
}
.app {
height: 100%
}
This is the Index.js's and Index.css's code:
ReactDOM.render(
<Elements stripe={promise}>
<BrowserRouter>
<React.StrictMode>
<ScrollToTop>
<App />
</ScrollToTop>
</React.StrictMode>
</BrowserRouter>
</Elements>,
document.getElementById('root')
);
html,body
{
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
align-items: center;
}
Here's a screenshot of the Elements section from the Developer tools:
I guess I have included everything that is higher up in the DOM, I suppose. Please let me know if anything specific can be of any use. Thanks.
I have removed all the CSS properties from wrapper as suggested by Dan Zuzevich in the comments. It did remove the wrapper and the screen is, indeed, filled with the gradient as set in body's CSS. However, the screen is still divided by lines or fragmented if you will. Any idea why? I want one whole body with the gradient color. Here are some screenshots:
Since no one seems to have been able to help me get rid of the lines, I kept doing my own research and found my answer here - CSS3 gradient background set on body doesn't stretch but instead repeats?.
Basically, here's what helped get rid of the lines:
body {
background-image: linear-gradient(to bottom, #42275a, #734b6d);
margin: 0;
background-repeat: no-repeat;
background-attachment: fixed;
}
Hopefully, this will be helpful to someone in the future.
Happy coding.
Don.

CSS - How to fix border-bottom won't appear?

I'm following a tutorial on youtube to create a replica of LinkedIn with CSS + ReactJS. I've been following the tutorial exactly (using it as more of a learning opportunity than anything) yet sometimes when the tutorial adds certain code, it doesn't appear on my environment when I try to add it. I found a work around for one case, but when I try to add a border-bottom to css it just won't show up.
CSS:
.header{
position: sticky;
top: 0;
display: flex;
justify-content: space-evenly;
border-bottom: thin solid lightgray; /*this is a vscode shortcut*/
padding-top: 10px;
padding-bottom: 10px;
width: 100%;
z-index: 999;
}
JS:
function Header() {
return (
<div className ='Header'>
<div className="header__left">
<img src="https://www.flaticon.com/svg/static/icons/svg/174/174857.svg" alt=""/>
<div className="header__search">
<SearchIcon/>
<input type="text"/>
</div>
<div className="header__right">
<HeaderOption Icon= {HomeIcon} title="Home"/>
<HeaderOption Icon={SupervisorAccountIcon} title="My Network"/>
</div>
</div>
</div>
);
}
*HeaderOption is an imported JS function I created. It isn't conflicting with the CSS I believe because I have removed it and the border still won't appear.
Thank you in advance.
CSS is case insensitive.
But in HTML the class and ID are case sensitive
change
<div className ='Header'>
to
<div className ='header'>
First off, you might wanna check your classNames' spelling for case-sensitivity.
If that's not the issue, your divs are probably collapsing with each other, so it renders the pixels through approximation. This is usually the case if you try zooming in your page and the missing border magically appears.
I suggest setting a height for your header where the borders don't collapse with the other divs' borders. Also, I prefer setting a fixed measurement unit rather like px,rem,%, etc. rathen than using thin.

Placing inner divs in row

I have a div container which contains 3 different divs. I want to place inner divs in a row.
Here is html code:
This is what it should look like.
.partners {
display: inline-block;
display: flex;
flex-direction: row;
width: 100%
}
<div class="partners">
<div>
<img src="media/handshake.png" alt="handshake" class="handshake">
<h1>10+</h1>
<p>partners investing their time and effort to support our mission</p>
</div>
<div>
<img src="media/social-care.png" alt="social care" class="social-care">
<h1>150+</h1>
<p>members working hard to be able to support our mission</p>
</div>
<div>
<img src="media/respect.png" alt="respect" class="respect">
<h1>243+</h1>
<p>donors supporting our community and making impossible possible</p>
</div>
</div>
But the last inner div goes beyond the screen and when I inspect the page it shows that "partners" div contains only first and second inner divs.
How can I solve this?
This is what it looks like when I inspect.The third one is not included in "partners" div
This often happen if you forget to close a tag in html.
Please check the rest of your code to be sure you didn't forget to close any tag. You also can use online unclosed html tags checker like this one :
https://www.aliciaramirez.com/closing-tags-checker/
Did you tried to use something like metroui or even bootstrap ?
I.E.:
With metroUI you can use the grid system to do exactly what you want, see :
https://metroui.org.ua/grid.html#_media_columns
Here is a link explaining how to include metroui in your project :
https://metroui.org.ua/intro.html#_quick_start
This will fix your problem.
.partners{
justify-content:space-around;
display: flex;
width: 100%;
}
.partners div{
width:30%;
}
ypu can set up a max width to the children divs, using like .partners div { width: 30% } and to add some space between them, you can also use .partners { justify-content: space-between; } tip: display inline-block is canceled when you put another display: flex above, try use only flex

Image does not appear in my section if I try it to upload from css file, but it works when I try it from html

I have created a section and I named it class="sectionOne". Right now this section is empty, but I try to add a background with image and it does not appear there. However, if I add a style in <>. For example .section class="sectionOn" style="background: url();" my image appears, but very small, but if I do it in css it does not appear. I have linked my html file with css, any ideas where's the problem? My path is correct 100%
inspector
my structure
.sectionOne {
background: url(../images/kendall-henderson-Pj6TgpS_Vt4-unsplash.jpg);
max-width: 100%;
max-height: 100%;
}
<section class="sectionOne">
</section>

Having an issue with a div background img

CSS
.content {
background-image: url("Pics/GameLogoBackground.jpg");
width: 100%;
height: 600px;
position: absolute;
top: 0px;
left: 0px;
}
HTML
<div class="content" style="display:block;width:100%;height:600px">
I can't see the div background img, please help!
I have tried to solve the problem, with no success.
To reference a class, use the '.' prefix before "content" in the CSS.
So it would become:
.content {
...
}
EDIT:
As you now say the '.' was mistakenly missing from your CSS, some things to try:
Ensure that the file exists in the specified location.
Check that the div isn't behind anything else.
Check if file is present.Go to Your index page and try putting path to image into url. JPG and JPEG are not the same thing
Do not use just background-image , instead of that use for example : https://www.w3schools.com/cssref/css3_pr_background.asp
Also if you are not doing some CSS dark magic there is not reason to put CSS in tag and in style.
I checked Your code and it should be working. Problem is with Your picture. Try to pass more HTML code. There is a chance that some other DIV is covering it