My submit button moves when I resize the page. This behavior is bad (obviously). What is the correct way to make it so that my button is left aligned to my textarea?
#chatboxTranscript {
width: 31.25em;
/* padding: 0em; */
background-color: #36393f;
color: #fff;
display: flex;
border: 0.125em solid #000;
/* Increase border width */
border-radius: 0.3125em 0.3125em 0 0;
/* Round the border */
box-sizing: border-box;
margin: 0 auto;
height: 12.5em;
/* Maintain the height */
}
#chatboxInput {
top: -0.125em;
height: 3.35em;
left: -2.2em;
width: 37.3em;
/* Keep the width the same */
background-color: #36393f;
/* Keep the color the same */
border: 0.15em solid #000;
border-radius: 0 0 0.3125em 0.3125em;
/* Round the border */
padding-bottom: 1.5em;
box-sizing: border-box;
margin: 0 auto;
display: flex;
/* border-top: none; */
position: relative;
}
.input-group {
display: flex;
justify-content: space-between;
}
button[type="submit"] {
position: relative;
display: inline-block;
width: 4em;
top: -0.1em;
height: 3em;
margin: 0 -2em;
border: 0.125em solid #000;
background-color: #36393f;
border-radius: 0.3125em;
}
<div id="chatbox" class="chatbox" data-role="chatbox">
<div id="chatboxTranscript" class="chatbox-transcript"></div>
<div class="input-group">
<!-- <form action="#" onsubmit="handleChatboxFormSubmit(event);"> -->
<textarea type="text" name="chatboxInput" id="chatboxInput" /> </textarea>
<button type="submit">Submit</button>
<!-- </form> -->
</div>
</div>
I tried multiple ways of fixing using absolute positioning (still same behavior), display (did nothing), margin (moves my textarea to the left) and asking chatgpt (output nonsensical CSS that didn't work).
Is this what you're trying to achieve?
I've removed all position layout styles since they don't help much in your particular layout.
The main issue was the .input-group since it didn't have a width and you're using flex for the layout. The content would take the entire width from its parent (#chatbox) therefore the button went to the right-hand side of the screen.
To fix this, I simply added a width for the .input-group as well as a margin of auto so it now aligns nicely with #chatboxTranscript div.
#chatboxTranscript {
width: 31.25em;
background-color: #36393f;
color: #fff;
display: flex;
border: 0.125em solid #000; /* Increase border width */
border-radius: 0.3125em 0.3125em 0 0; /* Round the border */
box-sizing: border-box;
margin: 0 auto;
height: 12.5em; /* Maintain the height */
}
#chatboxInput {
height: 3.35em;
width: 37.3em; /* Keep the width the same */
background-color: #36393f; /* Keep the color the same */
border: 0.15em solid #000;
border-radius: 0 0 0.3125em 0.3125em; /* Round the border */
padding-bottom: 1.5em;
box-sizing: border-box;
margin: 0 auto;
display: flex;
}
.input-group {
display: flex;
justify-content: space-between;
width: 31.25em;
margin: 0 auto;
}
button[type='submit'] {
display: inline-block;
width: 4em;
height: 3em;
border: 0.125em solid #000;
background-color: #36393f;
border-radius: 0.3125em;
}
#chatboxTranscript {
width: 31.25em;
/* padding: 0em; */
background-color: #36393f;
color: #fff;
display: flex;
border: 0.125em solid #000; /* Increase border width */
border-radius: 0.3125em 0.3125em 0 0; /* Round the border */
box-sizing: border-box;
margin: 0 auto;
height: 12.5em; /* Maintain the height */
}
#chatboxInput {
top: -0.125em;
height: 3.35em;
left: -2.2em;
width: 37.3em; /* Keep the width the same */
background-color: #36393f; /* Keep the color the same */
border: 0.15em solid #000;
border-radius: 0 0 0.3125em 0.3125em; /* Round the border */
padding-bottom: 1.5em;
box-sizing: border-box;
margin: 0 auto;
display: flex;
/* border-top: none; */
position: relative;
}
.input-group {
display: flex;
justify-content: space-between;
}
button[type="submit"] {
position: fixed;
display: inline-block;
width: 4em;
top: -0.1em;
height: 3em;
margin: 0 -2em;
border: 0.125em solid #000;
background-color: #36393f;
border-radius: 0.3125em;
}
I edited position of button from "reletive" to "fixed". It will work in page.
Related
I have an input element which has a padding of 1em on both the left and the right side. But I have applied "box-sizing: border-box" to it. However, It's width is still more than the other elements. I think it might be because I need to remove some piece of code but I'm not sure. The input element is definitely the one issue as the other element is properly center aligned.
Below is the code:
:root {
--main-color: #00308f;
--secondary-color: #7cb9e8;
--dark-color: #444;
--light-color: #fafafa
}
body {
font-family: Montserrat, sans-serif;
background-color: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin-top: 70px;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
padding: 1em
}
.my-contacts-div {
align-items: center
}
.contacts-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center
}
.contact-card {
width: 288px;
margin: .5em;
border-radius: .5em;
box-shadow: var(--secondary-color) 1px 1px 10px;
padding: 0 .75em;
word-wrap: break-word
}
.contact-form {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: grid;
align-self: center;
width: 350px;
z-index: 1;
background-color: var(--secondary-color);
border-radius: 1em;
padding: 1em;
box-shadow: 1px 1px 1.5em var(--main-color);
visibility: hidden
}
.contact-form:target {
visibility: visible
}
.input-field {
margin: .5em 0;
border: solid 1px var(--secondary-color);
border-radius: .5em;
padding: 0 1em;
height: 40px;
box-sizing: border-box
}
.searchbar {
margin: .5em;
width: 100%
}
#media screen and (max-width:687px) {
.my-contacts-div {
padding: 0
}
.contact-card {
width: 100%
}
}
#media screen and (max-width:614px) {
body {
margin-top: 130px
}
}
<div class="my-contacts-div">
<h2>Heading</h2>
<form><input class="input-field searchbar" type="text" placeholder="Search here..."></form>
<div class="contacts-list">
<div class="contact-card">
<h3>Other component</h3>
</div>
</div>
</div>
What is wrong with it?
The issue was most likely that when you were using '.input-field' in the CSS, it was maybe not correctly using it so I just put 'form input.input-field' and also added some CSS to the form element. Now it is looking completely aligned.
:root {
--main-color: #00308f;
--secondary-color: #7cb9e8;
--dark-color: #444;
--light-color: #fafafa
}
body {
font-family: Montserrat, sans-serif;
background-color: var(--light-color);
color: var(--dark-color);
text-align: justify;
margin-top: 70px;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
padding: 1em
}
.my-contacts-div {
align-items: center
}
.contacts-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center
}
.contact-card {
width: 288px;
margin: .5em;
border-radius: .5em;
box-shadow: var(--secondary-color) 1px 1px 10px;
padding: 0 .75em;
word-wrap: break-word
}
.contact-form {
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: grid;
align-self: center;
width: 350px;
z-index: 1;
background-color: var(--secondary-color);
border-radius: 1em;
padding: 1em;
box-shadow: 1px 1px 1.5em var(--main-color);
visibility: hidden
}
.contact-form:target {
visibility: visible
}
form input.input-field {
margin: .5em 0;
border: solid 1px var(--secondary-color);
border-radius: .5em;
padding: 0 1em;
height: 40px;
box-sizing: border-box;
}
form {
box-sizing: border-box;
padding: 0 0.5em;
}
.searchbar {
margin: .5em;
width: 100%
}
#media screen and (max-width:687px) {
.my-contacts-div {
padding: 0
}
.contact-card {
width: 100%
}
}
#media screen and (max-width:614px) {
body {
margin-top: 130px
}
}
<div class="my-contacts-div">
<h2>Heading</h2>
<form><input class="input-field searchbar" type="text" placeholder="Search here..."></form>
<div class="contacts-list">
<div class="contact-card">
<h3>Other component</h3>
</div>
</div>
</div>
Add display: flex in the tag. It will solve the overflowing issue.
display: flex fills the entire container taking margin and padding into consideration. That's why it didn't overflow.
display: block is at 100% width by default and then adds margin and padding after causing the overflow.
I need help with what is the best way to fully centre the contact form in the middle of the background image no matter what view the contact form is in(desktop, tablet, mobile). I would like for there to be a smallish amount of space between the bottom and top of the contact form, however, I would like the sides of the form to be further away from the edges of the image.
I hope yous understand what I'm asking for and thanks in advance.
The contact form can be seen on the live url: http://nathan-bayne.co.uk/index1
#contact-section {
background-color: #bce4b8; /* Previous colour that Aileen liked (#A74CAB) */
border-bottom: 1px solid #000;
text-align: center;
padding: 100px 0 0;
min-height: 800px;
width: 100%;
} /* Adjusts section sizing, padding and text alignment */
.contact-section-content {
margin-left: 14%;
margin-right: 14%;
margin-top: 2%;
}
::-webkit-input-placeholder {
text-align: center;
}
.bg-img {
/* The image used */
background-image: url("https://images.pexels.com/photos/807598/pexels-photo-807598.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
min-height: 750px;
border-radius: 35px;
margin-top: 2%;
margin-bottom: 3%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
border: 1px solid black;
} /* Sets background image behind contact form, sets sizing, positioning and styles the image */
.contact-section-content .container {
max-width: 60%;
padding: 2%;
background-color: white;
border-radius: 35px;
background-color: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(15px);
border: 1px solid white;
margin-top: 1%;
} /* Sets sizing, styling and positioning of the contact form container */
.container label {
font-size: 2em;
color: white;
} /* Sets sizing of the contact form titles */
.container textarea {
height: 125px;
width: 100%;
border-radius: 35px;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
} /* Sets sizing, positioning and styling of the contact form text area */
input[type="text"] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
border-radius: 35px;
} /* Sets sizing, positioning and styling of the input tags for the contact form */
input[type="tel"] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
border-radius: 35px;
} /* Sets sizing, positioning and styling of the input tags for the contact form */
.contact-section-content button {
font-size: 2em;
padding: 0.6% 6%;
border-radius: 35px;
color: #fff;
background-color: #339a9a;
border: 1px solid black;
cursor: pointer;
text-align: center;
/* clear: both; May not need this included */
margin-left: 0%;
margin-top: 1%;
} /* Styles the contact form submission button */
.contact-section-content button:hover {
color: rgb(255, 255, 255);
background-color: #004e4f;
border: 2px solid white;
} /* Styles the contact form submission button when you hover over it */
.container input::-webkit-input-placeholder {
font-size: 1.5em;
line-height: 2;
} /* Sets sizing of the contact form input placeholders */
.container textarea::placeholder {
font-size: 1.5em;
line-height: 2;
} /* Sets sizing of the contact form textarea placeholders */
#media only screen and (max-width: 1606px) {
.contact-section-content {
margin-left: 2.5%;
margin-right: 2.5%;
margin-bottom: 6%;
}
::-webkit-input-placeholder {
text-align: center;
}
.bg-img {
/* The image used */
background-image: url("https://images.pexels.com/photos/807598/pexels-photo-807598.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
min-height: 750px;
border-radius: 35px;
margin-top: 2%;
margin-bottom: 3%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
} /* Sets background image behind contact form, sets sizing, positioning and styles the image */
.contact-section-content .container {
max-width: 70%;
padding: 2%;
background-color: white;
border-radius: 35px;
background-color: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(15px);
border: 1px solid white;
margin-top: 1.5%;
} /* Sets sizing, styling and positioning of the contact form container */
.container label {
font-size: 2em;
color: white;
} /* Sets sizing of the contact form titles */
.container textarea {
height: 125px;
width: 100%;
border-radius: 35px;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
} /* Sets sizing, positioning and styling of the contact form text area */
input[type="text"] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
border-radius: 35px;
} /* Sets sizing, positioning and styling of the input tags for the contact form */
input[type="tel"] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
border-radius: 35px;
} /* Sets sizing, positioning and styling of the input tags for the contact form */
.contact-section-content button {
padding: 1% 8%;
font-size: 1.8em;
} /* Styles the contact form submission button */
}
#media only screen and (max-width: 815px) {
.contact-section-content {
margin-left: 2.5%;
margin-right: 2.5%;
margin-top: 10%;
margin-bottom: 15%;
}
::-webkit-input-placeholder {
text-align: center;
}
.bg-img {
/* The image used */
background-image: url("https://images.pexels.com/photos/807598/pexels-photo-807598.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
min-height: 670px;
border-radius: 35px;
margin-top: 2%;
margin-bottom: 3%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
} /* Sets background image behind contact form, sets sizing, positioning and styles the image */
.bg-img form {
margin-bottom: 7.5%;
} /* Sets background image behind contact form, sets sizing, positioning and styles the image */
.contact-section-content .container {
max-width: 85%;
padding: 2%;
background-color: white;
border-radius: 35px;
background-color: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(15px);
border: 1px solid white;
margin-top: 1.5%;
} /* Sets sizing, styling and positioning of the contact form container */
.container label {
font-size: 2em;
color: white;
} /* Sets sizing of the contact form titles */
.container textarea {
height: 125px;
width: 100%;
border-radius: 35px;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
} /* Sets sizing, positioning and styling of the contact form text area */
input[type="text"] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
border-radius: 35px;
} /* Sets sizing, positioning and styling of the input tags for the contact form */
input[type="tel"] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
border-radius: 35px;
} /* Sets sizing, positioning and styling of the input tags for the contact form */
.contact-section-content button {
padding: 1% 8%;
font-size: 2em;
margin-bottom: 4%;
} /* Styles the contact form submission button */
.container input::-webkit-input-placeholder {
font-size: 1.5em;
line-height: 2;
} /* Sets sizing of the contact form input placeholders */
.container textarea::placeholder {
font-size: 1.5em;
line-height: 2;
} /* Sets sizing of the contact form textarea placeholders */
}
<link rel="stylesheet" href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css' media="screen" />
<section id="contact-section">
<div class="contact-section-content">
<div class="bg-img"><br><br>
<form action="/action_page.php" class="container">
<label for="psw"><b>Name</b></label>
<input type="text" placeholder="Enter Name" name="psw" required>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="number"><b>Mobile Number</b></label>
<input type="tel" name="contact_number" placeholder="Mobile Number" pattern="[0-9]{11}"/>
<label for="psw"><b>Contact Summary</b></label>
<textarea name="subject" placeholder="Write a short summary about what you're in need of help with.." required></textarea>
<button type="submit">Submit Form</button>
</form>
</div>
</div>
Just add this to.bg-img :
display: flex; align-items: center;
And set margin-top: 0 for .container
Try to add this to your .bg-image class
.bg-img {
background-image: url("https://images.pexels.com/photos/807598/pexels-photo-807598.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
min-height: 750px;
border-radius: 35px;
margin-top: 2%;
margin-bottom: 3%;
display : flex ;
flex-direction : row;
align-items : center;
justify-content: center;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
border: 1px solid black;
}
what I added is display:flex and justify-content/align-items : center to center any element inside that container
I'm new to CSS and web development and trying to build my own and first website. I've read a few articles related to displaying and positioning elements however I still unable to get elements positioned perfectly while resizing the browser window!.
What I am trying to accomplish is in the codepen link in the first comment below
https://codepen.io/letsimoo/pen/XWNGoGa
HTML CODE
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="UTF-8">
</head>
<body class="mainBody">
<header class="mainHeader">
<div class="headerStuff">
<div class="social-list">
<div class="fb">
FB
</div>
<div class="twitter">
Twitter
</div>
<div class="instagram">
Instagram
</div>
</div>
<ul class="navigation">
<li> <b>My Projects</b> </li>
<li> <b>Gallery</b> </li>
<li> <b> About </b> </li>
<li> <b>Contact</b> </li>
</ul>
<div class="logoDiv">
<h2>Logo</h2>
</div>
</div>
<div class="HeaderLine"></div> <!-- Header Separator Line -->
</header>
</body>
CSS CODE
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.mainBody {
background-color: gray;
background-size: cover;
background-repeat: no-repeat;
color: white;
margin: 0px 0px 0px 20px;
/*width: 100%;*/
}
.mainHeader {
height: 80px;
}
.headerStuff {
height: auto;
display: flex;
position: relative;
align-items: bottom;
vertical-align: baseline;
width: 100%;
}
.social-list {
display: inline-flex;
position: absolute;
margin-top: 20px;
left: -10px;
}
.social-list div {
margin-left: 12px;
}
.navigation {
position: absolute;
right: 175px;
text-align: right;
height: 30px;
padding: 0px;
margin: 0px;
margin-top: 30px;
display: flex;
}
.navigation li {
background-color: #22385b;
display: inline-block;
margin-left: 5px;
padding: 7px 5px 7px 5px;
border-radius: 7px;
font-size: 20px;
width: 90px;
color: white;
}
.navigation li:hover {
background-color: #446291;
}
.navigation li a {
color: white;
font-size: 14px;
font-family: "Chakra Petch", sans-serif;
text-align: center;
text-decoration: none;
display: block;
}
ul li .prayer-window {
background-color: rgba(237, 239, 242, 0.9);
margin-top: 20px;
width: 400px;
height: 400px;
position: relative;
z-index: 1;
opacity: 0;
box-shadow: 0px 0px 100px black;
transition: 1s opacity, 5s width, 5s height;
}
.prayer-time:hover {
color: hotpink;
}
.prayer-time:active ~ .prayer-window {
opacity: 1;
}
.logoDiv {
position: absolute;
right: 0px;
}
.logoDiv img {
width: 150px;
}
.HeaderLine {
box-sizing: border-box;
height: 2px;
margin-top: 68px;
margin-right: 175px;
text-align: center;
background-color: pink;
box-shadow: 2px 2px 4px black, 0 0 30px red, 0 0 5px darkblue;
}
Please have a look to my code in the above link and try to resize the browser window to the minimum size
What the problem I'm facing?
Definitely you've notices how is the navigation elements jumped over the social media dev after resizing the browser window
So how can avoid this ugly act from the headerStuff div!??
Also please help me to improve my question if there are something wrong in my description or in the mentioned tags
Your .navigation .sosial-list are positioned absolute. That means they are out of the order of the other elements and does not take space by the other content.
As absolute positioned element .navigation is allways relative to the next parent element which is not positioned static. In your project it is .header-stuff. At the same time the margin-top moves it down from the top edge of header-stuff ...
So, if the screen becomes narrow your .header-stuff becomes narrow also. And your navigation keeps still in place: 175px from right edge of .header stuff and 30pxmargin from top ... that make it layered above your socials.
If you want to keep your structure enlarge the margin-top for .navigation so the navigation has still place enough to move below the social information.
But if you are open to change your sturcture you don't need an absolute positioning. Use a structure with block elements so socials and navigations are still beneath and don't layer over each other.
Just easy DEMO code structure example to explain the idea:
// css structure DEMO
nav {
display: block;
}
ul {
/* align ul to right */
margin-right: 0;
margin-left: auto;
}
li {
/* align li's into a line */
display: inline-block;
}
header hr {
... style your subheader line ...
}
// html structure DEMO
<header>
<div class="top-header>
... your socials ...
</div>
<nav>
<ul>
<li></li>
...
</ul>
</nav>
<hr>
</header>
Here's your updated updated CSS:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
.mainBody {
background-color: gray;
background-size: cover;
background-repeat: no-repeat;
color: white;
/* margin: 0px 0px 0px 20px; */
}
.headerStuff {
height: 80px;
display: flex;
position: relative;
vertical-align: baseline;
width: 100%;
justify-content: space-between;
align-items: center;
}
.social-list {
display: inline-flex;
}
.social-list div {
margin-left: 12px;
}
.navigation {
margin: 0;
}
.navigation li {
background-color: #22385b;
display: inline-block;
padding: 7px 5px 7px 5px;
border-radius: 7px;
font-size: 20px;
width: 90px;
color: white;
}
.navigation li:hover {
background-color: #446291;
}
.navigation li a {
color: white;
font-size: 14px;
font-family: 'Chakra Petch', sans-serif;
text-align: center;
text-decoration: none;
display: block;
}
ul li .prayer-window {
background-color: rgba(237, 239, 242, 0.9);
margin-top: 20px;
width: 400px;
height: 400px;
position: relative;
z-index: 1;
opacity: 0;
box-shadow: 0px 0px 100px black;
transition: 1s opacity, 5s width, 5s height;
}
.prayer-time:hover {
color: hotpink;
}
.prayer-time:active ~ .prayer-window {
opacity: 1;
}
.logoDiv h2 {
margin: 0;
}
.logoDiv img {
width: 150px;
}
.HeaderLine {
box-sizing: border-box;
height: 2px;
margin: 0 auto;
text-align: center;
background-color: pink;
box-shadow: 2px 2px 4px black, 0 0 30px red, 0 0 5px darkblue;
}
You can adjust css properties for specific screen sizes via media queries.
#media only screen and (max-width: 796px) {
//
}
PS. align-items:bottom is not really a thing. Probably you meant align-items:baseline
In the left part of the following picture you can see an object which has been positioned on the right edge of the container. Part of the object is cut off according to the overflow property and can be displayed by scrolling horizontally to the right.
In the right part of the picture you can see the object after scrolling to the right. The shadow on the right edge of the object is cut off. When scrolling, only the extent (width) of the object without the shadow was taken into account.
Setting a margin or padding value for the object did not change the behavior. Experiments with the css property scrolling-margin or scrolling-padding have also failed.
The behavior was tested under Chrome (79.0.3945.88), Opera and Edge in the latest versions under Mac OS.
I don't want to create another container around the object to create a space. Is there any other way to avoid cutting off the shadow?
The relevant CSS for the container:
margin: 4px;
box-sizing: border-box;
overflow: auto;
The relevant CSS for the object:
background: lightgreen;
background-clip: padding-box;
box-sizing: border-box;
border-width: 1px;
border-style: solid;
border-color: darkslategray;
border-radius: 50%;
box-shadow: 2px 2px 4px gray;
position: absolute;
How about this. Put something in the ::after of the divs and position that slightly to the right.
It sounds like a bit of a kludge, but of all the things I tried, this is the only trick I could get to work.
/* Change line 34 to see the beauty of flex-design ;-) */
body {
width: 100vw;
height: 100vh;
margin: 0;
background-color: white;
overflow: hidden;
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
align-items: stretch;
}
nav {
box-sizing: border-box;
background-color: yellow;
opacity: 0.9;
display: flex;
align-items: center;
user-select: none;
flex: 0 0 35px;
padding: 5px;
border-bottom: 4px solid #ddd;
}
main {
box-sizing: border-box;
flex: 1 1 auto;
align-self: stretch;
display: flex;
flex-direction: row; /* row, row-reverse, column, column-reverse */
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
align-items: stretch;
}
article {
--raster: 25px;
--raster-color: #ddd;
margin: 4px;
box-sizing: border-box;
overflow: scroll;
background-attachment: local;
background-image: linear-gradient(var(--raster-color) 1px, transparent 1px), linear-gradient(90deg, var(--raster-color) 1px, transparent 1px), linear-gradient(var(--raster-color) 0.5px, transparent 0.5px), linear-gradient(90deg, var(--raster-color) 0.5px, transparent 0.5px);
background-size: var(--raster) var(--raster), var(--raster) var(--raster), 5px 5px, 5px 5px;
flex: 3 1 75%;
align-self: auto;
position: relative;
}
section {
box-sizing: border-box;
background-color: #ddd;
flex: 0 0 4px;
cursor: col-resize;
}
aside {
box-sizing: border-box;
background-color: lightgray;
overflow: scroll;
flex: 1 1 calc(25% + 10px); /* resizing */
align-self: auto;
margin: 4px;
padding: 5px;
}
article div {
position: absolute;
border: 1px solid black;
border-radius: 50%;
box-shadow: 4px 4px 8px gray;
width: 100px;
height: 100px;
background-color: lightgreen;
color: white;
}
/* Trick goes here */
article div::after {
position: absolute; bottom:-8px; right: -8px;
display: inline; content: '\00A0';
}
article div:nth-child(1) {
left: 500px;
top: 50px;
}
article div:nth-child(2) {
left: 350px;
top: 10px;
}
article div:nth-child(3) {
left: 175px;
top: 125px;
}
<nav>
navigation bar
</nav>
<main>
<article>
<div>
first
</div>
<div>
second
</div>
<div>
third
</div>
</article>
<section></section>
<aside>
input area
</aside>
</main>
I have the following HTML to place a button inside an input (JSFiffle Example):
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
form {
border: 1px solid green;
max-width: 400px;
}
input {
border: 1px solid red;
background-color: white;
display: inline-block;
font-size: 18px;
line-height: 1;
margin: 0;
margin-right: -80px;
padding: 12px;
vertical-align: middle;
width: 100%;
}
button {
background-color: white;
border: none;
cursor: pointer;
display: inline-block;
font-size: 28px;
line-height: 1;
margin: 0;
outline: 0;
vertical-align: middle;
}
i {
display: block;
line-height: 1;
margin: 0;
padding: 0;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<form>
<input type="text">
<button><i class="fa fa-search"></i></button>
</form>
Problem
The JSFiddle Example I posted works great ...
But in my application when the negative margin right value is bigger then the icon width the input moves right and gets outside of the container with a space on the left:
I am not able to replicate this on JSFiddle but I wonder if someone has any idea what to look for because I have been trying everything and not able to solve it.
I'd suggest something more along these lines:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
form {
border: 1px solid green;
max-width: 400px;
}
.search-input {
display: flex;
flex-flow: row nowrap;
height: 40px;
border: 1px solid red;
background-color: white;
font-size: 18px;
line-height: 1;
}
.search-field {
flex: auto;
border: none;
padding: 10px;
}
.search-button {
width: 40px;
height: 40px;
font-size: 24px;
cursor: pointer;
border: none;
background: transparent;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<form>
<div class="search-input">
<input class="search-field" type="text">
<button class="search-button" type="submit"><i class="fa fa-search"></i></button>
</div>
</form>
Since you said you didn't want a flex solution, how about removing the negative margin-right and replacing width: 100% with width: 88%.
That being said and since I'm a big fan of flexbox, the following is a different flex solution from James' offering:
form {
border: 1px solid green;
max-width: 400px;
display: flex; /* Added */
justify-content: flex-end; /* Added */
}
input {
border: 1px solid red;
background-color: white;
display: inline-block;
font-size: 18px;
line-height: 1;
margin: 0;
/* margin-right: -80px; */ /* Removed */
padding: 12px;
vertical-align: middle;
/* width: 100% */ /* Removed */
flex: 0 1 100%; /* Added */
}
You can make the input's container position: relative and the button position: absolute. Then you can move the button wherever you want relative to the container. I would suggest using something other than the form element, so that you can have more than one element in the form. I've added a simple wrapping div.
Then you set right to a little more than 0 so that the border(s) can be seen, and the top to half way down, less half the height of the button so it's centered vertically.
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
form {
border: 1px solid green;
max-width: 400px;
}
.search {
/* Making the container relative... */
position: relative;
}
input {
border: 1px solid red;
background-color: white;
display: inline-block;
font-size: 18px;
line-height: 1;
margin: 0;
padding: 12px;
vertical-align: middle;
width: 100%;
}
button {
background-color: white;
border: none;
cursor: pointer;
display: inline-block;
font-size: 28px;
line-height: 1;
margin: 0;
outline: 0;
vertical-align: middle;
/* means you can absolutely position the button relative to that */
position: absolute;
/* make it one pixel off the right for the border */
right: 1px;
/* make it 50% - half its height to center it vertically */
top: calc(50% - 14px);
}
i {
display: block;
line-height: 1;
margin: 0;
padding: 0;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
<form>
<div class="search">
<input type="text">
<button><i class="fa fa-search"></i></button>
</div>
</form>