How to get elements inlined in the header? - html

I'm working on creating a custom header. I'm not sure how to properly perfectly inline my elements in my header. For example, these elements should be where the red arrows are pointing:
How can I get these elements in the header, align them perfectly, and put them where the red arrows are pointing (picture above).
https://jsfiddle.net/af5caL8p/3/
body {
margin: 0;
}
.header {
height: 45px;
width: 100%;
background-color: royalblue;
color: white;
padding: 10px;
margin-top: auto;
margin-bottom: auto;
line-height: 11px;
display: inline-block;
}
button.signup {
background-color: #2FA034;
border-radius: 10px;
color: white;
font-size: 20px;
font-weight: 300;
}
/* Material style */
button {
border: none;
cursor: pointer;
color: black;
width: 130px;
padding: 10px;
border-radius: 2px;
font-size: 19px;
background: royalblue;
/* Ripple magic */
position: relative;
overflow: hidden;
}
<div class="header">
<h1>Logo</h1>
Link 1
<button class="signup">Signup</button>
<button class="signup">Login</button>
</div>

With display: flex. I updated your JS example: https://jsfiddle.net/af5caL8p/4

display: inline-block display simply makes elements with block/inline default properties use extra properties e.g a <span> by default an inline element and can only use padding and not margin.
Making it display inline-block allows it to use properties that apply to block elements such as a paragraph taking on margin.
body {
margin: 0;
}
.header {
height: 45px;
width: 100%;
background-color: royalblue;
color: white;
padding: 10px;
margin-top: auto;
margin-bottom: auto;
line-height: 11px;
/*use flex instead of display: inline-block; explanation is above*/
display: flex;
}
button.signup {
background-color: #2FA034;
border-radius: 10px;
color: white;
font-size: 20px;
font-weight: 300;
}
/* Material style */
button {
border: none;
cursor: pointer;
color: black;
width: 130px;
padding: 10px;
border-radius: 2px;
font-size: 19px;
background: royalblue;
/* Ripple magic */
position: relative;
overflow: hidden;
}
<div class="header">
<h1>Logo</h1>
Link 1
<button class="signup">Signup</button>
<button class="signup">Login</button>
</div>

Related

How to position buttons in css without this happening? [duplicate]

This question already has answers here:
Why does position:relative; appear to change the z-index?
(2 answers)
Closed 1 year ago.
Here is the CSS and HTML code, the problem is told below.
* {
box-sizing: border-box;
font-family: Georgia, 'Times New Roman', Times, serif;
}
body {
margin: 0;
font-family: Georgia, 'Times New Roman', Times, serif;
}
.topnav {
overflow: hidden;
background-color: #F5CB5C;
list-style-type: none;
text-align: center;
margin: 0;
padding: 0;
position: fixed;
top: 0;
width: 100%;
}
.topnav li {
display: inline-block;
font-size: 20px;
padding: 20px;
}
.topnav a {
color: #242423;
text-align: center;
text-decoration: none;
}
.topnav li:hover {
background-color: #E8EDDF;
color: black;
}
.topnav li:active {
background-color: #E8EDDF;
color: black;
}
/* ITEM ABOVE DOES NOT WORK, FIX ASAP! */
.content {
background-color: #242423;
padding: 10px;
color: #E8EDDF;
}
.footer {
background-color: #F5CB5C;
padding: 10px;
color: #242423;
text-align: center;
}
.card {
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
width: 20em;
border-radius: 10px;
border-color: #FFFFFF;
max-width: 100%;
height: auto;
object-fit: cover;
margin: 1em;
}
.card-button {
background-color: #ddd;
position: relative;
border: none;
color: black;
padding: .5em 1em;
text-align: center;
text-decoration: none;
float: right;
left: .5em;
bottom: .5em;
cursor: pointer;
border-radius: 16px;
font-size: 16px;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
.container {
padding: 2px 16px;
}
.card img {
border-radius: 10px 10px 0 0;
}
.text-center {
text-align: center;
}
.center {
right: 50%;
}
.title {
margin-top: 2em;
text-align: center;
}
.grid-gallery {
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.spacer {
width: 100%;
height: 2em;
}
and here is HTML,
<div class="card">
<img src="https://d3vjn2zm46gms2.cloudfront.net/blogs/2016/05/27005442/Roman-cup_w1280px_h720px.png" alt="Silver Cup" style="width:100%">
<div class="container">
<h4><b>Roman Silver Cup</b></h4>
<button class="card-button">Buy Now</button>
<p>$89.99</p>
</div>
</div>
and here is the problem the buttons are showing over the fixed navigation bar. Can anyone explain why?
I would look into the CSS z-index property, which allows you to specify that some item (such as the top nav bar) should always be above other items (or that other items should be below the top nav bar).
https://www.w3schools.com/cssref/pr_pos_z-index.asp
I think you're searching for z-index.
It allows you to set the z-order of a positioned element (meaning that you need to provide a position to your element otherwise it won't work).
You can find more information here.
So in your case, you should add something like z-index: 999;.
This is happening because your button has position: relative; property. Use z-index property. Add z-index: 1000; to your class .topnav. So that navbar stays at top of all.
.topnav {
// other
z-index: 1000;
}
Or add z-index: -1; to your .card-button class.
.card-button {
// other
z-index: -1;
}

How to make sure that an element is not covered by another (CSS)?

I am new at web developing.
Trying to make site logo look good.
Have two elements, one of them is covered by another so user can't click on first of them.
Help me please making them one above another.
How can I do this stuff using only CSS?
Codepen: https://codepen.io/h071/pen/YOeXaw
This is HTML part:
<header>
<link rel="stylesheet" type="text/css" href="/a/www/css/style_header.css">
<nav class="container-fluid">
<a class="logo" href="/a/www/index.php">
<span>Sitename</span>
</a>
<p id="reg-auth-title">Login|Registration</p>
And this is CSS:
header {
width: 100%;
height: 5em;
position: relative;
}
nav {
width: 100%;
}
.logo {
display: block;
float: left;
position: absolute;
margin-top: 0.4em;
margin-left: 1em;
}
.logo span {
font-size: 5em;
color: black;
display: inline-block;
/*line-height: 1em;*/
}
#reg-auth-title {
/* width: 20%; */
padding: 0;
margin: 0;
float: left;
}
#reg-auth-title a.top-auth {
font: bold 15px sans-serif;
text-decoration: none;
padding-left: 8px;
padding-right: 8px;
padding-top: 4px;
padding-bottom: 4px;
border: 1px solid red;
border-radius: 5px; /*other browsers*/
-webkit-border-radius: 5px; /*safari*/
-moz-border-radius: 5px;
cursor: pointer;
color: black;
}
#reg-auth-title a.top-auth:hover {
text-decoration: none;
}
#reg-auth-title a {
font: 15px sans-serif;
font-weight: bold;
text-decoration: none;
color: #58ACFA;
margin-left: 1em;
border-bottom-style: dashed;
border-bottom-color: #58ACFA;
border-bottom-width: 1px;
}
You need to put your link above logo using z-index.
#reg-auth-title {
z-index: 10;
position: relative; // z-index works only with non-static positioned elements
}

text field and button in same line

I want to put text field and button on the same line.
I used display: inline; but it's not working. Where am i making a mistake?
.listBar {
position: absolute;
left: 40px;
top: 210px;
box-sizing: border-box;
}
#input {
width: 100%;
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;
}
#add {
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: left;
}
#add,
#input {
display: inline;
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
</div>
it's because you have width: 100% on the input. It makes it take all the place and there is none left for your button. It will work if you remove the width there or set it to auto. Also, be careful with the second float, that one should be right, not left.
.listBar{
position: absolute;
left: 40px;
top: 210px;
box-sizing: border-box;}
#input{
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;}
#add{
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: right;}
#add, #input{
display: inline;}
You don't need the floats to do that, your input has a width of 100% that's why display inline didn't work, And the h2 is also block by default so you need to set it's display to inline or inline-block as well
.listBar {
position: absolute;
left: 40px;
top: 210px;
box-sizing: border-box;
}
#input {
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
}
#add {
color: black;
border: none;
background-color: lightgrey;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
}
#add, #input {
display: inline;
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
It was right that if the input text field takes 100% of the parent's width, there will be no room for the button. In addition, there is no need of display: inline. You can put the text field and a button in the same line just by adding the float: left in both elements classes and by increasing the width of the main div class element :) .....
.listBar{
position: absolute;
left: 40px;
top: 210px;
width: 30%;
box-sizing: border-box;
}
.header {
color: whitesmoke;
text-align: left;
}
/* add button */
#add{
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: left;
}
#add:hover{
background-color: rgb(85, 78, 78);
}
/* input text field */
#input{
width: 75%;
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;
}
here is snippet
The problem here is that input takes width: 100%; of its parent. So there is no more room for a button on its side.
Here is a working snippet with comments:
(That's how I'll do to correct the problem if it was for myself)
body { /* Added only for snippet */
background: #ddd;
}
.listBar {
position: absolute;
background: #bbb; /* Added only for snippet */
left: 40px;
top: 20px; /* Modified only for snippet */
box-sizing: border-box;
}
#input {
width: auto; /* Modified, you could also simply remove this line */
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;
}
#add {
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: right; /* Floating on the right */
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
</div>
Second proposal after comments:
(That's not what I'll do, but that's funny anyway!)
You could play with the transform property to move the element:
body {
background-color: #ddd; /* Added only for snippet */
}
.listBar {
position: absolute;
background: #bbb; /* Added only for snippet */
left: 40px;
top: 20px; /* Modified only for snippet */
box-sizing: border-box;
}
#input {
width: 100%;
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
float: left;
}
#add {
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
float: right; /* Floating on the right */
transform: translate(100%, -50%); /* Added with funny values, just for demo. Waiting for your answer to my comment. :) */
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
</div>
Note that currently, because of the padding of the input, the input goes outside of its parent.
You may want to correct that.
Documentation about transform: https://www.w3schools.com/css/css3_2dtransforms.asp
When using translate() with percentages, it takes a percentage of the size of the element.
It's quite handy.
Hope it helps.
Put a wrapper around the input and button and than use display: flex;
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Did this help?
.listBar {
position: absolute;
left: 40px;
box-sizing: border-box;
}
.listBar__forms {
display: flex;
}
#input {
width: 100%;
font-size: 16px;
border: none;
background-color: aliceblue;
padding: 14px;
}
#add {
color: whitesmoke;
border: none;
background-color: inherit;
padding: 14px 20px;
font-size: 16px;
cursor: pointer;
}
<div class='listBar'>
<h2 class='header' style='margin:5px'> List </h2>
<div class="listBar__forms">
<input type='text' id='input' placeholder="Title">
<button id='add'> Add </button>
</div>
</div>

Elements are not appearing next to each other

The problem is that the elements are not appearing next to each other as I want them to.
all three elements are already on float left and in the right order but they are still not lining up in the right way.
(so probably, the problem is that some elements are position:absolute or relative while they don't need to. The problem is: you can't change that without disrupting the drop-up menu of #Timer. That)
green_button {
background-color: #027fed;
color: white;
border-radius: 2px;
cursor: pointer;
float: right;
position: relative;
}
.green_button:active {
background-color: #eee;
color: black;
}
.keuze {
position: absolute;
width: 100px;
height: 100px;
float: left
}
#timer {
color: black;
background: #eee;
border: none;
padding-left: 10px;
font-size: 12px;
border-radius: 2px;
float: left;
padding: 12px 12px;
cursor: pointer;
list-style-type: none;
position: Relative;
margin-top: -14px;
width: 80px;
}
#timer:hover {
color: white;
background: #027fed;
}
li {
background-color: #eee;
font-size: inherit;
width: 150px;
position: relative;
float: left;
bottom: 31px;
left: 0;
display: block;
font-size: 12px;
text-decoration: none;
font-family: tahoma;
color: black;
width: 50px;
height: auto;
border: 1px solid #;
border-width: 1px 1px 0 0;
background: #eee;
background-color: rgb(238, 238, 238);
padding-left: 10px;
line-height: 38px;
border-radius: 2px;
height: auto;
line-height: 1em;
padding: 5px 10px;
width: 129px;
margin-bottom: 1px;
margin-left: 431px;
}
li:hover {
cursor: pointer;
background-color: #027fed;
color: white
}
.list {
display: none;
list-style-type: none;
position: absolute !important;
}
.keuze:hover .list {
display: block
}
.messages_compose {
padding: 10px;
margin-bottom: auto;
}
.messages_textarea_container {
display: inline-block;
width: 400px;
margin-left: 10px;
}
.messages_textarea {
border: 3px solid lightgray;
margin-top: 0;
margin-bottom: 10px;
padding: 5px;
width: 400px;
height: 40px;
resize: none;
float: left;
border-radius: 2px;
position: absolute;
}
.button {
border: none;
font-size: 12px;
padding: 12px 12px;
height: 40px text-align: center;
}
<div class="messages_compose">
<div class="vraag">CV</div>
<div class="messages_textarea_container">
<textarea class="messages_textarea"></textarea>
<button class="button green_button">Stuur</button>
<ul class="keuze">
<button id="timer">1 Jaar</button>
<div class="list">
<li id="jaar">jaar</li>
<li id="maand">maand</li>
<li id="week">week</li>
<li id="dag">dag</li>
</div>
</ul>
</div>
<script>
document.getElementById("jaar").onclick = function() {
jaar()
};
document.getElementById("maand").onclick = function() {
maand()
};
document.getElementById("week").onclick = function() {
week()
};
document.getElementById("dag").onclick = function() {
dag()
};
</script>
<script src="../scripten.js"></script>
</div>
If you want them side by side (if width allows), to make things simpler, make sure they are inline elements.
textarea and button are inline elements by default and unsorted-list are block element by default
Inline Elements
Block Elements
So basically, all you need is to change your ul to display: inline-block;
* {
padding: 0;
margin: 0;
vertical-align: text-top;
}
green_button {
background-color: #027fed;
color: white;
border-radius: 2px;
cursor: pointer;
}
.green_button:active {
background-color: #eee;
color: black;
}
.keuze {
display: inline-block; /* added */
width: 100px;
list-style: none;
}
.keuze li {
width: 100%;
}
#timer {
color: black;
background: #eee;
border: none;
padding-left: 10px;
font-size: 12px;
border-radius: 2px;
padding: 12px 12px;
cursor: pointer;
list-style-type: none;
width: 80px;
}
<div class="messages_compose">
<div class="vraag">CV</div>
<div class="messages_textarea_container">
<textarea class="messages_textarea"></textarea>
<button class="button green_button">Stuur</button>
<ul class="keuze">
<button id="timer">1 Jaar</button>
<div class="list">
<li id="jaar">jaar</li>
<li id="maand">maand</li>
<li id="week">week</li>
<li id="dag">dag</li>
</div>
</ul>
</div>
</div>
In addition, I have removed all your float and position from your css which I think as #Temani Afif says, you were just trying fix the issue by adding more to it.
I also have added followings just to make it tidier which is irrelevant to your issue. (That is to remove the default margin, padding and vertical align from all html elements to make it tidier and avoid unexpected behavior of different browsers)
* {
padding: 0;
margin: 0;
vertical-align: text-top;
}

Image moving when adding new content to <h1>

First website here (just a heads up)!
My problem is that I'm trying to put my content (Flying Fish Painting & Maintenance with Service link below) all in the h1 category without moving the images! I would really like for the two images (on the left and right) to stay in the top left and top right corner respectively when I add the Services href link. Any ideas? Here is my code:
.round1 {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
width: 70px;
height: 70px;
}
.round2 {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
width: 70px;
height: 70px;
}
.linkto {
color: white;
font-size: 60%;
font-family: Arial;
}
.linkto:hover {
color: blue;
}
body {
padding: 20px 20px 20px 20px;
}
h1 {
color: white;
border: 6px solid black;
border-radius: 25px;
text-align: center;
font-family: Forte;
font-weight: bold;
background-color: black;
font-size: 180%;
padding-bottom: -50px;
}
<h1>
Flying Fish Painting &amp Maintenance</br>
<img class="round1" src="https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=300&h=291" align=left>
<img class="round2" src="https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=300&h=291" align=right>
<a class="linkto" href="C:\Users\CE User\Desktop\services.html">Services</a>
</h1>
First of all, Instead of cramming everything inside an H1 tag, you could put the content in separate divs and then use flex-box to align them. Why not in H1 tag? It's meant for headings
There's so many ways how to accomplish what you're aiming for, this is just one of them
/*
More about box-sizing:
https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
https://www.paulirish.com/2012/box-sizing-border-box-ftw/
*/
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
.wrapper {
background: black;
border-radius: 25px;
text-align: center;
padding: 1rem;
margin: 0 auto;
display: flex;
justify-content: center;
/* could be any number you want */
max-width: 780px;
}
.image-wrapper {
flex-basis: 70px;
}
img {
max-width: 100%;
}
h1 {
text-align:center;
font-family:Forte;
font-weight:bold;
color: white;
margin: 0 1rem 0 1rem;
}
a {
color: white;
text-decoration: none;
font-size: 1.5rem;
font-family:Arial;
}
a:hover { color: blue }
<div class="wrapper">
<div class="left image-wrapper">
<!-- removed the align attribute -->
<img src="https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=300&h=291">
</div>
<div>
<h1> Flying Fish Painting &amp Maintenance</h1>
<a class ="linkto" href="C:\Users\CE User\Desktop\services.html">Services</a>
</div>
<div class="right image-wrapper">
<img src="https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=300&h=291">
</div>
</div>
I hope this helps.
.linkto {
color: white;
font-size: 60%;
font-family: Arial;
}
.linkto:hover {
color: blue;
}
body {
padding: 20px 20px 20px 20px;
}
h1 {
color: white;
border: 6px solid black;
border-radius: 25px;
text-align: center;
font-family: Forte;
font-weight: bold;
background-color: black;
font-size: 180%;
position: relative;
}
h1:before {
position: absolute;
content: url('https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=50,h=50');
left: 0;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
width: 70px;
height: 70px;
background-color: black;
}
h1:after {
position: absolute;
content: url('https://flyingfishpainting.files.wordpress.com/2013/04/flying_fish_logo_hressmall.png?w=50,h=50');
right: 0;
top: 0;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
width: 70px;
height: 70px;
background-color: black;
}
<h1>
Flying Fish Painting &amp Maintenance <br/>
<a class="linkto" href="C:\Users\CEUser\Desktop\services.html">Services</a>
</h1>