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>
Related
I have two links that I want to be on the right side of the navbar. I am not sure what I am missing here but if anyone can take a look at this I would greatly appreciate it. Here is my rep.it https://gregs-list.leezamartinez.repl.co/
I have tried to put them in a span and move the span to the top of the page but it just doesn't seem to work. I apologize if this is a stupid question I cannot seem to figure it out.
I want the Post and Account links to be in the right side of the navbar
https://gregs-list.leezamartinez.repl.co/
This is due to the fact that your h1 has a 100% width, the best approach here is to make the nav tag display:flex, justify-content:space-between and align-items:center to center everything vertically.
Example
html {
padding: 10px;
padding-right: 10px;
padding-left: 10px;
}
a {
text-decoration: none;
display: inline;
}
a::hover {
text-decoration-line: underline;
}
body {
box-sizing: border-box;
font-family: 'Nunito', sans-serif;
}
main {
padding: 5%;
margin: auto;
padding-top:86px;
}
nav {
position: fixed;
margin: -18px;
background-color: whitesmoke;
width: 100%;
height: 65px;
text-align: left;
display:flex;
justify-content:space-between;
align-items:center;
z-index:9;
}
li {
float: right;
color: purple;
list-style: none;
font-size: 20px;
padding: 8px;
margin-right: 8px;
}
ul {
display: inline;
padding: 5px;
}
span {
color:rgb(184, 179, 179);
text-decoration-style: none;
}
p {
color: blue;
font-weight: bold;
}
placeholder {
font-famiy: 'Nunito', sans-serif;
color:lightgrey;
}
#mag {
height: 31px;
width: 29.5px;
display: -webkit-inline-box;
position: absolute;
border: 1px solid #DDDDDD;
border-radius: 3px;
}
h1 {
font-famiy: 'Nunito', sans-serif;
font-size: 25px;
font-weight: 700;
padding: 10px;
margin: 5px;
}
input {
height: 33px;
font-color: whitesmoke;
font-size: 20px;
width: 400px;
padding: 5px;
border: 2px solid whitesmoke;
}
label {
font-weight: bold;
}
#button1 {
width: 102px;
height: 40px;
padding: 12px 28px;
border-radius: 4px;
float: left;
border: 1px solid rgb(228, 228, 228);
text-align: center;
font-size: 14px;
background-color: ghostwhite;
}
#button2 {
width: 155px;
height: 40px;
padding: 12px 28px;
border-radius: 4px;
float: left;
border: 1px solid rgb(228, 228, 228);
background-color: ghostwhite;
font-size: 14px;
}
#button3 {
width: 100px;
height: 40px;
padding: 12px 28px;
border-radius: 4px;
text-align: center;
font-size: 14px;
background-color: ghostwhite;
border: 1px solid rgb(228, 228, 228);
}
.container {
position: absolute;
padding-top: 10px;
}
form {
padding: 20px;
padding-right: 55px;
padding-left: 0;
}
<nav>
<h1>Greg's List</h1>
<ul>
<li> Account</li>
<li> Post</li>
</ul>
</nav>
<main>
<div class="box">
<label>Search jobs</label>
</div>
<form action="#">
<input id='search' type="search" name="search" placeholder="Search software jobs" /> <a href='#'> <img id='mag' src="https://tf-assets-prod.s3.amazonaws.com/tf-curric/WEB-DEV-001/2.4.6_challenge_design_to_code/magnifying-glass.png" alt="magnifying glass" /></a>
</form>
<button type="button" id="button1"> prev</button>
<button a href="#" type="button"id="button2">1 to 100 of 179</button>
<button type="button"id="button3"> next > </button>
<div class="container">
<p><span>June 22</span> Technical Project Manager <span> Midtwon East</span></p>
<p><span>June 21</span> Frontend Developer <span> SoHo</span></p>
<p><span>June 20</span> Senior Python Developer / Cofounder<span> Flatiron</span></p>
</div>
</main>
Also, bear in mind that you had a lot of markup errors in your HTML, I've corrected them in the snippet above. Plus you needed some padding for your main tag due to the fixed navigation bar (that also needed a z-index:9 in order to keep other things from showing above it).
Check this link (Demo 2)
https://codepen.io/912lab/pen/LsplC
html,
body {
font-family: 'Arial', sans-serif;
font-size: 16px;
}
/* border-box */
.search-container *,
.search-container *:after,
.search-container *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
/* search bar focus */
.search-container *:focus {
background: #fbfbfb;
color: #333333;
outline: 0;
}
/* search bar container */
.search-container {
display: table;
position: relative;
width: 51px;
}
/* search icon button */
.search-icon-btn {
background-color: aquamarine;
border: 1px solid aquamarine;
display: table-cell;
height: 50px;
position: relative;
text-align: center;
vertical-align: middle;
width: 50px;
z-index: 2;
}
/* search bar input container */
.search-input {
position: absolute;
left: 0;
z-index: 1;
}
/* search bar input */
.search-input input.search-bar {
border: 1px solid #cccccc;
height: 50px;
padding: 0px;
width: 50px;
}
.search-input input.search-bar:focus {
padding-left: 60px;
padding-right: 10px;
width: 200px;
}
/* transition effect */
.search-input input.search-bar,
.search-icon-btn {
-webkit-transition: all 0.5s;
-moz-transition: all 0.5s;
-ms-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s;
}
/* hover on search bar container */
.search-container:hover > .search-input input.search-bar {
padding-left: 60px;
padding-right: 10px;
width: 200px;
}
<h1>Expandable Search Form</h1>
<p>Pen by Prinzadi</p>
<h3>Demo 1</h3>
<form>
<input type="search" placeholder="Search">
</form>
<h3>Demo 2</h3>
<form id="demo-2">
<input type="search" placeholder="Search">
</form>
Is it possible to expand the search on demo 2 to the left, instead of the right though? I changed the padding and width, but it still expands to the left, instead of the right.
Again, I've tried it several different way but I guess I am missing something silly. I appreciate the help.
Thanks,
When you use the CSS property float: right, it expands from right to left.
Here is the code:
body {
background: #fff;
color: #666;
font: 90%/180% Arial, Helvetica, sans-serif;
width: 800px;
max-width: 96%;
margin: 0 auto;
}
a {
color: #69C;
text-decoration: none;
}
a:hover {
color: #F60;
}
h1 {
font: 1.7em;
line-height: 110%;
color: #000;
}
p {
margin: 0 0 20px;
}
input {
outline: none;
}
input[type=search] {
-webkit-appearance: textfield;
-webkit-box-sizing: content-box;
font-family: inherit;
font-size: 100%;
}
input::-webkit-search-decoration,
input::-webkit-search-cancel-button {
display: none;
}
input[type=search] {
background: #ededed url(https://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png) no-repeat 9px center;
border: solid 1px #ccc;
padding: 9px 10px 9px 32px;
width: 55px;
-webkit-border-radius: 10em;
-moz-border-radius: 10em;
border-radius: 10em;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
float: right;
margin-right: 701px;
}
input[type=search]:focus {
width: 120px;
background-color: #fff;
border-color: #66CC75;
float: right;
-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
box-shadow: 0 0 5px rgba(109,207,246,.5);
}
input:-moz-placeholder {
color: #999;
}
input::-webkit-input-placeholder {
color: #999;
}
/* Demo 2 */
#demo-2 input[type=search] {
width: 15px;
padding-left: 10px;
color: transparent;
cursor: pointer;
}
#demo-2 input[type=search]:hover {
background-color: #fff;
}
#demo-2 input[type=search]:focus {
width: 130px;
padding-left: 32px;
color: #000;
background-color: #fff;
cursor: auto;
}
#demo-2 input:-moz-placeholder {
color: transparent;
}
#demo-2 input::-webkit-input-placeholder {
color: transparent;
}
<h1>Expandable Search Form</h1>
<p>Pen by Prinzadi</p>
<h3>Demo 1</h3>
<div class="container">
<form>
<input type="search" placeholder="Search">
</form>
</div>
For some reason the input doesn't work in the Stack Snippet, so just copy it over in CodePen or whatever other platform you have chosen.
This isn't positioned how you want, so I set a margin-right property in CSS to change it back to what it was.
I also didn't fix it for the second demo because I want you to figure out how to make this change yourself by looking at the changes I made, then implementing them yourself. This way you will understand how to replicate this solution in the future and increase your knowledge of HTML/CSS in general.
Links: float documentation, tutorial on floats
Related tags: html, css, input, css-float, animation, layout
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;
}
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>
I would love to figure out how to create a button with CSS that has 'brackets' on each side. To clarify, not just the brackets you get by typing them, but larger brackets, like this:
You can use the before and after pseudo selectors with the content attribute:
button {
font-size: 15px;
font-weight: bold;
background: none;
border: none;
white-space: nowrap;
}
button::before {
content: "[ ";
font-size: 1.5em;
}
button::after {
content: " ]";
font-size: 1.5em;
}
button.bigtext {
font-size: 80px;
}
<button>Some Text</button>
<br />
<button class="bigtext">Some Text</button>
Here an approach where you can edit size thickness and length of the brackets involving box-shadow
.brackets {
width: 200px;
height: 50px;
box-shadow: inset 0px 0px 0px 5px black;
background: white;
position: relative;
}
.button {
height: 50px;
width: 80%;
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
border: none;
background: white;
font-size: 1.6em;
font-weight: bold;
}
<div class="brackets">
<button class="button">
Button
</button>
</div>
There are a few things you can do to achieve this.
First and easiest: Create a button background in Photoshop or whatever and use that as your button background.
Second: Type the brackets and button text you want and then style the separate pieces.
HTML:
<div class="button">
<p><span class="large">[</span>Button<span class="large">]</span></p>
</div>
CSS:
p {
font-size: 20px;
}
.large {
font-size: 40px;
}
Those are they straight forward ways I can think of that are really quick and easy.
Not sure I follow the question. Just put a bracket around it. Example below.
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252"><title>Title Here </title>
</head>
<body>
<br>
<center>Your Title</center>
<br>
Some Text Data Here
<style type="text/css">
#modernbricksmenu { padding: 0; width: 100%; background: transparent; voice-family: ''}''; voice-family: inherit; }
#modernbricksmenu ul { font: bold 11px Arial; margin:0; margin-left: 40px; /*margin between first menu item and left browser edge*/ padding: 0; list-style: none; }
#modernbricksmenu li { display: inline; margin: 0 2px 0 0; padding: 0; text-transform:uppercase; }
#modernbricksmenu a { float: left; display: block; color: white; margin: 0 1px 0 0; /*Margin between each menu item*/
padding: 5px 10px; text-decoration: none; letter-spacing: 1px; background-color: black; /*Default menu color*/ border-bottom: 1px solid white; }
#modernbricksmenu a:hover { background-color: gray; /*Menu hover bgcolor*/ }
#modernbricksmenu #current a { /*currently selected tab*/ background-color: #D25A0B; /*Brown color theme*/ border-color: #D25A0B; /*Brown color theme*/ }
#modernbricksmenuline { clear: both; padding: 0; width: 100%; height: 5px; line-height: 5px; background: #D25A0B; /*Brown color theme*/ }
#myform { /*CSS for sample search box. Remove if desired */ float: right; margin: 0; padding: 0; }
#myform .textinput { width: 190px; border: 1px solid gray; }
#myform .submit { font: bold 11px Verdana; height: 22px; background-color: lightyellow; } </style>
<div id="modernbricksmenu"> <ul> <li style="margin-left: 1px">
Home</li> <li>
New</li> <li id="current">
Revised</li> <li>
[Tools]</li> <li>
Forums</li> </ul>
</div>
<div id="modernbricksmenuline"> </div>
</body>
</html>
I didn't want to change my template, so I've come up with a pure CSS solution.
It'll also work with every background.
.btn {
position: relative;
border: none;
background: none;
padding: 8px 24px;
}
.btn::before,
.btn::after {
position: absolute;
top: 0;
bottom: 0;
width: 8px;
border: 2px solid #000;
content: "";
}
.btn::before {
left: 0;
border-right-width: 0;
}
.btn::after {
right: 0;
border-left-width: 0;
}
<a class="btn btn-primary">Buttton</a>