Text within span pushing buttons to the right [duplicate] - html

This question already has answers here:
How can I align one item right with flexbox?
(5 answers)
How to center-align one flex item and right-align another using Flexbox [duplicate]
(2 answers)
Center one and right/left align other flexbox element
(11 answers)
Closed 1 year ago.
I am trying to build a navbar with a logo to left and some buttons in the middle, but i have some trouble putting the logo. The span with the text is attaching right next to my buttons and if i take it out of my nav the logo is too far to the right and pushing my buttons to the left. This is the CSS:
:root {
--nav-button-color: #ffc300;
--nav-button-transparent: #ffc40093;
--font-color-unselected: #737373;
--font-color-selected: #fff;
--roboto: "Roboto", sans-serif;
--poppins: "Poppins", sans-serif;
--font-bold-600: 600;
--font-bold-700: 700;
--font-bold-800: 800;
--font-bold-900: 900;
}
* {
font-family: var(--roboto);
}
.navigation {
display: flex;
justify-content: center;
}
.btn {
margin: 5px;
width: 110px;
height: 30px;
border: none;
}
.btn-nav {
width: auto;
height: auto;
color: var(--font-color-unselected);
font-size: 16px;
font-weight: var(--font-bold-600);
padding: 10px 15px;
border-radius: 5px;
background: none;
transition: 0.4s;
cursor: pointer;
}
.btn-nav-selected {
color: var(--font-color-selected);
background-color: var(--nav-button-color);
}
.logo {
font-family: var(--poppins);
color: var(--font-color-unselected);
font-weight: var(--font-bold-800);
font-size: 30px;
}
/*=============================*/
.btn-nav:hover {
color: var(--font-color-selected);
background-color: var(--nav-button-transparent);
}
<div class="nav-container">
<nav class="navigation">
<span class="logo">Logo</span>
<button class="btn btn-nav btn-nav-selected">Home</button>
<button class="btn btn-nav">Shop</button>
<button class="btn btn-nav">What We Do?</button>
</nav>
</div>

You can try with css grid:
:root {
--nav-button-color: #ffc300;
--nav-button-transparent: #ffc40093;
--font-color-unselected: #737373;
--font-color-selected: #fff;
--roboto: "Roboto", sans-serif;
--poppins: "Poppins", sans-serif;
--font-bold-600: 600;
--font-bold-700: 700;
--font-bold-800: 800;
--font-bold-900: 900;
}
* {
font-family: var(--roboto);
}
.navigation {
display: grid;
grid-template-columns: auto 1fr;
justify-items: center;
align-items: center;
}
.btn {
margin: 5px;
width: 110px;
height: 30px;
border: none;
}
.btn-nav {
width: auto;
height: auto;
color: var(--font-color-unselected);
font-size: 16px;
font-weight: var(--font-bold-600);
padding: 10px 15px;
border-radius: 5px;
background: none;
transition: 0.4s;
cursor: pointer;
}
.btn-nav-selected {
color: var(--font-color-selected);
background-color: var(--nav-button-color);
}
.logo {
font-family: var(--poppins);
color: var(--font-color-unselected);
font-weight: var(--font-bold-800);
font-size: 30px;
justify-self: flex-start;
}
/*=============================*/
.btn-nav:hover {
color: var(--font-color-selected);
background-color: var(--nav-button-transparent);
}
<>
<div class="nav-container">
<nav class="navigation">
<span class="logo">Logo</span>
<div class="menu">
<button class="btn btn-nav btn-nav-selected">Home</button>
<button class="btn btn-nav">Shop</button>
<button class="btn btn-nav">What We Do?</button>
</div>
</nav>
</div>
</>

Related

How to not push other elements away when increasing margin on the same line

How to not push other elements away when increasing margin on the same line. I have <a> elements and a button element. When I try to increase the left-margin of button, the <a> margin gets pushed away. I just want the button to go to the right of the page. Tried using float but I don't want it to go to the extreme left (leave some space).
a {
font-family: Arial;
font-size: 12px;
align-items: center;
margin-right: 50px;
color: black;
text-decoration: none;
}
nav {
margin-top: 30px;
}
.chat {
width: 100px;
height: 35px;
background-color: white;
border-style: solid;
border-color: black;
border-width: 1px;
font-family: Arial;
font-weight: 600;
cursor: pointer;
margin-left: 0px;
}
<nav>
<div class="navbar" align='center'>
Home
Works
About
Projects
<button class='chat'>Let's chat</button>
</div>
</nav>
I just want the button to go to the right of the page.
Use flex-box. Wrap your links inside a container and set display of it's parent element to flex and remove the width property of the button.
a {
font-family: Arial;
font-size: 12px;
align-items: center;
margin-right: 50px;
color: black;
text-decoration: none;
}
nav {
margin-top: 30px;
}
.chat {
height: 35px;
background-color: white;
border-style: solid;
border-color: black;
border-width: 1px;
font-family: Arial;
font-weight: 600;
cursor: pointer;
}
.navbar {
display: flex;
justify-content: space-around;
align-items: center;
}
<nav>
<div class="navbar" align='center'>
<div class="links">
Home
Works
About
Projects
</div>
<button class='chat'>Let's chat</button>
</div>
</nav>
If you want to use float you need to set a width on nav and then float button right and navbar float left.
a {
font-family: Arial;
font-size: 12px;
align-items: center;
margin-right: 50px;
color: black;
text-decoration: none;
}
nav {
margin-top: 30px;
width: 600px;
}
.navbar{
float:left;
}
.chat {
width: 100px;
height: 35px;
background-color: white;
border-style: solid;
border-color: black;
border-width: 1px;
font-family: Arial;
font-weight: 600;
cursor: pointer;
margin-left: 0px;
float:right;
}
<nav>
<div class="navbar" align='center'>
Home
Works
About
Projects
</div>
<button class='chat'>Let's chat</button>
</nav>

Trying to make div move to another div

So I am trying to make it look like this
However, it currently looks like this
As, you can see the top section with the logo and register have their own section. I want it to stay on top of the background image. I do not want to use position: absolute; or position : fixed; since i want it to say in its own section. I have also tried using a negative margin and it does not work. Any help is appreciated.
.top-firstsection {
display: flex;
}
.logo-header {
height: 80px;
}
.nav-list {
margin-left: auto;
list-style: none;
display: flex;
}
.leftandright {
display: flex;
justify-content: space-between;
}
.login {
font-family: Helvetica;
font-size: 13px;
color: #000000;
letter-spacing: 0.98px;
text-align: center;
text-decoration: none;
line-height: 26px;
cursor: pointer;
}
.register {
font-family: Helvetica;
font-size: 13px;
color: #0972D7;
letter-spacing: 0.98px;
text-align: center;
text-decoration: none;
line-height: 26px;
}
.first-left {
padding-top: 220px;
padding-left: 171px;
}
.first-left h1 {
font-family: Poppins-Regular;
font-size: 40px;
color: #000000;
letter-spacing: 0;
line-height: 50px;
}
.sectionOne-textbox {
border: 1px solid #EBEBEB;
border-radius: 4px;
font-family: Helvetica;
font-size: 14px;
color: #000000;
letter-spacing: 1.05px;
line-height: 52px;
width: 80%;
}
.sectionOne-button {
background: #1F8FFB;
border-radius: 4px;
border: 1px solid;
padding: 16px 25px;
font-family: Helvetica;
font-size: 13px;
color: #FFFFFF;
letter-spacing: 1.3px;
text-align: center;
margin-top: 24px;
}
<section class="first-section">
<div class="top-firstsection">
<img src="logo.svg" alt="logo" class="logo-header">
<ul class="nav-list flex">
<li>
LOGIN
</li>
<li>
REGISTER
</li>
</ul>
</div>
<div class="leftandright">
<div class="first-left">
<h1>Open marketplace <br> for ordering & purhasing <br> scientific experiments</h1>
<input type="text" id="" class="sectionOne-textbox" placeholder="Discover new experiments...">
<button class="sectionOne-button">GET STARTED NOW!</button>
</div>
<div class="first-right">
<img src="firstsectionbackground.png" alt="main graphic" class="main-graphic">
</div>
</div>
</section>

Why is the automatic line break not working with flex display? [duplicate]

This question already has answers here:
Why are flex items not wrapping?
(2 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 2 years ago.
Good night, I am developing a project and I need that after the text "Malha Suprema - Judas" he should wrap the line for the text "ACERT" to go down, but for some reason the n works. I use the flex display and when I press it for some reason my text "Acert" loses the css. Does anyone know how I can solve this problem?
#import url("https://fonts.googleapis.com/css2?family=Oswald:wght#300;500&display=swap");
:root {
--dark: #333;
--lightDark: #444;
}
*{
margin: 0;
padding: 0;
}
body{
background: var(--dark);
touch-action: none;
}
div.musicPhoto img{
border-radius: 100%;
width: 180px;
height: 180px;
}
.btnPlayer{
display: flex;
align-items: center;
margin-left: auto;
}
div.btnPlayer .playerImg{
font-size: 80px;
color: #FFF;
}
div.btnPlayer .playerBtn{
cursor: pointer;
outline: none;
border: none;
background: transparent;
}
div.musicData{
display: flex;
align-items: center;
margin-left: 15px;
}
div.musicData p{
font-family: "Oswald", sans-serif;
}
div.musicData p:nth-child(1){
font-size: 40px;
font-weight: 500;
color: #FFF;
}
div.musicData p:nth-child(2){
font-weight: 300;
font-size: 33px;
color: #ebebeb;
}
div.musicItem{
cursor: pointer;
border-radius: 15px;
background: var(--lightDark);
width: 93%;
display: flex;
flex-wrap: nowrap;
flex-direction: row;
padding: 15px;
margin: 2% auto;
}
<html>
<head>
<title>SpotCode</title>
<meta charset="utf-8" />
</head>
<body>
<div class="musicItem">
<div class="musicPhoto">
<img src="assets/images/3348986.jpg">
</div>
<div class="musicData">
<p>Malha Suprema - Judas</p>
<p>ACERT</p>
</div>
<div class="btnPlayer">
<button class="playerBtn">
<span class="playerImg">
<i class="far fa-play-circle"></i>
</span>
</button>
</div>
</div>
</body>
</html>

A button is inside the navigation bar, but the btn doesnt belong in the div class of the nav bar

So I made a post similar to this one, since I didn't get a precise answer and didn't understand the instructions. So I am once again asking for your support.
There are a couple of issues regarding my nav bar that I am unable to fix. One of them is a button sticking inside of the nav bar, but it doesn't even belong in the div class.
Navigation Bar
The second issue is that I can't line the logo/text [SINUS] and the links together in one line.
Any help would be appreciated!
/*====================
The CSS File
Section 1:
Buttons
=====================*/
button {
background-color: #358cf0;
border: none;
border-radius: 18px;
text-align: center;
text-decoration: none;
opacity: 0.8;
font-size: 14px;
color: rgb(255, 255, 255);
padding: 12px 48px;
transition: 0.3s;
outline: none;
}
button:hover {
opacity: 1;
}
ul li {
display: inline-block;
padding: 10px;
font-size: 20px;
font-family: raleway;
}
ul li:hover {
color: orange;
}
/*====================
The CSS File
Section 2:
Alerts
=====================*/
.container {
position: fixed;
top: 74%;
right: 0;
left: 77%;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
font-family: basic;
}
.modal {
width: 40%;
min-width: 20rem;
background-color: #ffffff;
border-radius: 12px;
}
.modal-header {
display: flex;
align-items: center;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
background-color: #358cf0;
padding: 8px 10px;
color: #fff;
font-size: 110%;
font-weight: 600;
font-family: basic;
}
.modal-content {
padding: 1rem;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
.modal-footer {
text-align: center;
}
/*====================
The CSS File
Section 3:
Body etc.
=====================*/
body {
background-color: #252036;
}
#navigation-container {
width: 1200px;
margin: 0 auto;
height: 70%;
}
.navigation-bar {
background-color: #1c172c;
position: fixed;
width: 100%;
left: 0;
top: 0;
text-align: right;
}
.navigation-bar ul {
padding: 0px;
margin: 0px;
text-align: right;
display: inline-block;
vertical-align: top;
}
.navigation-bar li {
list-style-type: none;
padding: 0px;
display: inline;
text-align: right;
}
.navigation-bar li a {
color: black;
font-size: 16px;
font-family: basic;
text-decoration: none;
line-height: 70px;
padding: 5px 15px;
opacity: 0.7;
}
#menu {
float: right;
}
/*====================
The CSS File
Section 4:
Text
=====================*/
#font-face {
font-family: basic;
src: url(Helmet-Regular.ttf);
}
h1 {
font-family: basic;
color: white;
font-size: 390%;
text-align: left;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="sccp.css">
<title>Sinus - 【Home】</title>
<link rel="icon" href="titl.ico">
<link rel="apple-touch-icon" href="titl.ico" />
</head>
<body>
<div class="navigation-bar">
<div id="navigation-container">
<h1>SINUS</h1>
<ul>
<li>Home</li>
</ul>
</div>
</div>
<button>Download</button>
<div class="container" role="alert">
<div class="modal">
<div class="modal-header">
UPDATE! Sinus 1.0v
</div>
<div class="modal-content">
Here new stuff go gogogo
<br>Read more...
</div>
<div class="modal-footer">
</div>
</div>
</div>
</body>
</html>
To align the logo and links, use flex on the #navigation-container:
#navigation-container {
display: flex;
justify-content: space-between;
align-items: center;
}
justify-content: space-between will put the maximum space between the contents - in this case your logo and ul that contain the links. align-items:center lines them up vertically.
https://codepen.io/doughballs/pen/RwPrYoX
Not sure what your issue with the button is but because your nav has position:fixed, it is being taken out of the flow of the page, so the button doesn't 'know' it is there. If you wanted it to sit under the nav, you need to add a container with margin-top to push it down. But I'm not sure what your issue is with it, clarify and I'll amend the codepen.

How to make text overflow and overlap another div?

I'm making a interactive periodic table of elements and I've run into an issue.
In my example below the Potassium and 39.0983 is below 2,8,8,1 that is in a separate div.
I need it so that the numbers 2,8,8,1 overlay above Potassium so that it doesn't push it down.
.base {
margin: -1px;
height: 75px;
width: 75px;
padding: 0px;
}
.element {
text-align: center;
border: 1px solid white;
cursor: pointer;
display: flex;
flex-direction: column;
}
div.element > div {
display: flex;
justify-content: space-between;
}
div.element > div code {
background-color: transparent;
font: 10px arial, sans-serif;
}
div.element > div abbr {
font-size: 140%;
font-weight: bolder;
}
div.element > div ed {
font: 10px arial, sans-serif;
}
div.element span,
p {
font: 12px arial, sans-serif;
}
div.element span {
display: block;
text-align: center;
}
div.element p {
display: block;
font: 10px arial, sans-serif;
position: relative;
top: 1px;
text-align: center;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-1 base">
<div id="4_1" class="base element" style="background-color: rgb(255, 153, 0);">
<div>
<code>19</code>
<abbr>K</abbr>
<ed>
2
<br>8
<br>8
<br>1
</ed>
</div>
<span>Potassium</span>
<p>39.0983</p>
</div>
</div>
https://jsfiddle.net/fau2Lk3k/
It's not really clear how you want the image to appear. But a quick google search of periodic table elements yields this common layout:
Source: Google (image terms permit use)
Using your original code, here's a revised version:
.base {
height: 75px;
width: 75px;
padding: 0 0 0 2px;
font-family: arial, sans-serif;
font-size: 12px;
background-color: rgb(255, 153, 0);
}
.element {
display: flex;
flex-direction: column;
position: relative;
cursor: pointer;
}
div.element > code {
font-size: 140%;
font-weight: bold;
}
div.element > abbr {
font-size: 175%;
font-weight: bold;
}
div.element > ol {
position: absolute;
top: 2px;
right: 2px;
padding: 0;
margin: 0;
list-style-type: none;
}
<div class="base element">
<code>19</code>
<abbr>K</abbr>
<ol>
<li>2</li>
<li>8</li>
<li>8</li>
<li>1</li>
</ol>
<span>Potassium</span>
<span>39.0983</span>
</div>