How to resize a logo link inside a header - html

I made a header. It contains only a logo and a website title. The logo is a link to the main page. My problem is that I can't seem to get the logo to be all the way to the left in the header and I want it to resize so it fits into the header (instead of: header gets bigger because of logo). I placed the logo and the website name/title in two different divs.
Setting the with or height to 100% was something that often came by. I have tried to use this, but it wouldn't work.
"object-fit" should also be an option, but my IDE doesn't recognize this property.
When I use "float: left;" for the logo, it goes all the way to the left, but it also goes out of the header (well, it looks like it does) and pushes my other divs beneath the header/page content to the right.
the HTML:
<div class="header">
<a href="index.html" class="logo">
<img src="image.png">
</a>
<div class="header-right">
<h1>Website title/name</h1>
</div>
</div>
the CSS:
.header {
background-color: #f1f1f1;
padding: 20px;
text-align: center;
}
.logo{
display: block;
margin-left: auto;
max-width: 100%;
height: auto;
}

one way you can achieve this by having two images one for desktop version and other for mobile version. Using window.navigator you can identify whether you are in mobile or in desktop.
Sometimes resizing the logo may shrink and may not look good. Instead having two different logos (small one for mobile = small size) should serve your purpose.

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<style>
.header {
background-color: #f1f1f1;
padding: 20px;
text-align: center;
}
.logo{
float: left;
display: block;
margin-left: auto;
width:250px;
height: 50px;
height: auto;
}
</style>
</head>
<body>
<div class="header">
<a href="index.html" class="logo">
<img width="200px" height="150px" src="https://groceriesandveggies.in/wp-content/uploads/2017/09/gv_small_logo.jpeg">
</a>
<div class="header-right">
<h1>Website title/name</h1>
</div>
</div>
</body>
</html>

Related

Scroll-chain containing to div without property in CSS on mobile

I'm having an issue, primarily on mobile devices (in my case, an iOS device) where a div is seemingly preventing scroll-chaining; this is problematic because it's the first place you would touch to scroll (as opposed to a smaller div above it). Similarly for scrolling back up. I couldn't find anything online stating that there was a parameter or property default to mobile webkit that would contain a div. It seems though maybe this is behavior on iOS webkit, as notably, a second swipe on the final image after the "bounce" of the scroll of the div returns to normal positioning in the div allows a scroll (sometimes seemingly inconsistently?)
I've managed to recreate the issue with a test with minimum code repeated from my project (view on mobile! overscroll works fine on desktop)
https://codepen.io/hennigarj/pen/ZEjYrpW
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Website</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<style>
#container {
display: block;
width: 100%;
height: 100%;
padding-top: 4vh;
}
.flex-items {
width: 100%;
overflow: auto;
}
.flex-items:nth-child(1) {
display: block;
height: 10vh;
}
.flex-items:nth-child(2) {
display: block;
margin-top: 4vh;
margin-bottom: 4vh;
height: 64vh;
text-align: center;
}
.flex-items img {
max-width: 100%;
}
.flex-items:nth-child(3) {
display: block;
padding-bottom: 6vh;
}
</style>
</head>
<body>
<div id="container">
<div class="flex-items">
Div 1
</div>
<div class="flex-items">
<section id="highlights">
<div class="highlight">
<img src="https://placehold.jp/400x536.png" />
</div>
<div class="highlight">
<img src="https://placehold.jp/400x536.png" />
</div>
<div class="highlight">
<img src="https://placehold.jp/400x536.png" />
</div>
</section>
</div>
<div class="flex-items">
Div 3
</div>
</div>
</body>
</html>
Anyone have any ideas? I've tried all sorts of overflows and overscroll-behaviors on everything but nothing seems to fix this, and there is no value to specifically enable scroll-chaining through overscroll.
This is probably clear as day and I'm completely missing it.
Thank you :)
I've tried various different potential heights, overscroll-behaviors, overflows on divs (to no success). Ideally, hitting the end of the div would continue the scroll-chain past it, just as it does on desktop, but it contains. I've tried -webkit-overflow-scroling: auto as well.

Trouble with image in my html page being pushed off center

In my HTML page, I have some social media icons at the top of the page, and a logo that's supposed to be in the middle. But, after I added the icons, they're pushing the logo to the side a bit.
Here's an image of what's happening
The question mark symbol is supposed to be in the middle of the entire page (directly in between the "updates" and "archive" in the nav bar), but it's being pushed off. Is there a way I can make the logo in the center of the entire page?
In my HTML I have:
<img src="https://imgur.com/16OdDvD.png" class="sns-icon" id="ig">
<img src="https://imgur.com/nQ2aUYu.png" class="sns-icon" id="reddit">
<div class="center">
<img src="https://imgur.com/hQRzG5G.png" id="headerlg">
</div>
Then in my styles.css I have:
.center {
text-align: center;
}
#headerlg {
padding-top: 35px;
padding-bottom: 9px;
width: 80px;
position: relative;
}
.sns-icon {
width: 30px;
float: left;
margin-top: 13px;
margin-left: 13px;
padding: 1px;
}
I've also tried justify-content: center and margin: auto both of which didn't work
your source code didn't work for me, but here I write some code like yours, I solve your problem with flex box and add some visual style, I hope it's make sense to you.
.container {
width: 100%;
height: 50px;
display: flex;
justify-content: space-around;
align-items: center;
}
.container>div {
width: 33%;
height: 20px;
background-color: rgb(216, 216, 216, 0.4);
text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>HTML & CSS</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="container">
<div class="social-media">
<span>instagram</span>
<span>twitter</span>
</div>
<div class="logo">
icon logo
</div>
<div class="put-nothing">
</div>
</div>
</body>
</html>
I just created 3 div 1 of them contain social media ,another contain logo , and last one left empty. all of them have same width in all device (mobile, tablet, laptop).

CSS Box border bottom stick to top?

I am writing my own css, but the strange thing is that the my .content border-top and border-bottom are sticking together.
Here is my code for css:
body{
width: 100%;
margin: auto;
}
header{
position: relative;
margin: 20px;
min-width: 1200px;
min-height: 70px;
}
p{
font-family: courier;
font-size: 130%;
margin: 10%;
}
.content{
margin-top: 100px;
min-width: 1200px;
border-top: 3px solid orange;
border-bottom: 30px solid rgb(239, 98, 98);
}
.content .col-left{
width: 20%;
float: left;
}
.content .col-mid{
width: 60%;
float: left;
}
.content .col-right{
width: 20%;
float: left;
}
.footer{
margin-top: 20px;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>IEEI</title>
<!-- Custom styles for this template -->
<link href="css/reset.css" rel="stylesheet">
<link href="css/customized.css" rel="stylesheet">
</head>
<body>
<header>
<img src="http://via.placeholder.com/150x150">
</header>
<div class="content">
<div class="col-left"><img src="http://via.placeholder.com/100x150" style="width:100%"></div>
<div class="col-mid">
<p>
Instead of referencing the image directly, stick it within a DIV.
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
</p>
</div>
<div class="col-right"><img src="http://via.placeholder.com/100x150" style="width:100%"></div>
</div>
<div class="content">
<p>test footer</p>
</div>
<div class="footer">
<p>test footer</p>
</div>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
I am wondering how to move the red border bottom to the right position.
I have tried to put a new content box in the HTML, the position seems to be OK but messes up the output. I am new to the CSS, please help me out.
Your .content element only contains floated elements, which "don't count" concerning the borders and size of their container element. Add overflow: auto; to .content to make .content wrap its floating contents:
body{
width: 100%;
margin: auto;
}
header{
position: relative;
margin: 20px;
min-width: 1200px;
min-height: 70px;
}
p{
font-family: courier;
font-size: 130%;
margin: 10%;
}
.content{
margin-top: 100px;
min-width: 1200px;
border-top: 3px solid orange;
border-bottom: 30px solid rgb(239, 98, 98);
overflow: auto;
}
.content .col-left{
width: 20%;
float: left;
}
.content .col-mid{
width: 60%;
float: left;
}
.content .col-right{
width: 20%;
float: left;
}
.footer{
margin-top: 20px;
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>IEEI</title>
<!-- Custom styles for this template -->
<link href="css/reset.css" rel="stylesheet">
<link href="css/customized.css" rel="stylesheet">
</head>
<body>
<header>
<img src="http://via.placeholder.com/150x150">
</header>
<div class="content">
<div class="col-left"><img src="http://via.placeholder.com/100x150" style="width:100%"></div>
<div class="col-mid">
<p>
Instead of referencing the image directly, stick it within a DIV.
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
Instead of referencing the image directly, stick it within a DIV
</p>
</div>
<div class="col-right"><img src="http://via.placeholder.com/100x150" style="width:100%"></div>
</div>
<div class="content">
<p>test footer</p>
</div>
<div class="footer">
<p>test footer</p>
</div>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
Also would be a good idea to provide some height to the element of .content ID.

Unable to center footer in CSS

I am unable to center the footer on the page. All content is centered on the page and set to 1280px, so it does not take up the entire width of the page. The issue is that everything on the page is centered except the footer. It is the correct width, but the footer is pushed hard left. Any ideas what I am missing?
This is what the footer looks like currently:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="../Css/Style.css">
<link rel="icon" type="png" href="../Pictures/Icon.png">
<meta charset="utf-8"/>
<meta name="description" content="xxx">
<meta name="keywords" content="xxx">
<meta name="author" content="xxx">
<title>xxx</title>
</head>
<body>
<div id="container">
<div id="header">
<h1>xxx</h1>
<h2>xxx</h2>
</div>
<div>
<hr/>
</div>
<div id="menu">
<ul>
<li class="menuitem">Home</li>
<li class="menuitem">Manage Income</li>
<li class="menuitem">Manage Bills</li>
<li class="menuitem">View Calendar</li>
</ul>
<a id="signout" href="SignOut.html">Signout</a>
</div>
<div class="pie"></div>
</div>
</body>
<footer>
<a id="contact" href="xxx.html">Contact Us</a>
</footer>
</html>
footer{
display: block;
width: 1280px;
height: 35px;
text-align: center;
bottom: 0px;
position: fixed;
float: none;
margin: auto;
background-color: #B6B6B4;
}
Your example code appears to align correctly for me.
Note that your width of 1280px means that the text will be centered at exactly 640px (half of 1280px), and this is likely outside of your viewport at smaller widths, meaning it will seem as though your text is not central.
To remedy this, use a percentage-based width instead, such as 100% to indicate that your footer should occupy the full width available:
footer {
display: block;
width: 100%;
height: 35px;
text-align: center;
bottom: 0px;
position: fixed;
float: none;
margin: auto;
background-color: #B6B6B4;
}
<footer>
Test
</footer>
As you can see in the above example, the text is visible even though the viewport is narrow.
Note that it's also possible that your footer's CSS is being overridden by a selector with higher specificity. You can use the F12 Debugger to ensure that your rules are being applied correctly.
Hope this helps! :)

background-image for header not working

Im trying to use a full screen image as my headers background but for some reason the image is not showing up and I cant figure out what im doing wrong. Can someone help? The image is in the same folder as the html and css files btw.
CSS
body {
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
}
#header{
background-image:url(headerbackground.png);
width: 100%;
height: auto;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
display: inline-block;
float: right;
}
HTML
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, width=device-width">
<title>Test</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<header>
<div id="header">
<ul class="col-4">
<li>SOBRE</li>
<li>TRABALHOS</li>
<li>CONTACTO</li>
</ul>
</div>
</header>
</body>
</html>
Since you've given your header div (#header) no explicit height and floated the only child it has, it collapses and acts like it has no content. Either give it a height or add overflow:auto to the CSS rules for it.
Agree with #j08691.
Working with html layout and css, it's always helpful, for me at least, to add following css:
border: 1px solid green; //or any color you like
so that we can see clearly how is the layout.
additional, in case you have issue with src image size, you may use
background-size: cover;