CSS - resizing a div affects neighboring divs - html

I have a basic chat site. A chat box in the middle, users hit enter when sending messages. And there's an ajax populated list of the currently logged in users on the right-hand side.
.chat {
margin-top: 10px;
}
.chat .messages {
background-color: white;
border: 1px solid #ccc;
width: 300px;
height: 250px;
padding: 10px;
resize: both;
overflow: auto;
margin: 0 auto;
font-weight: bold;
}
.present {
float: right;
margin-top: -400px;
margin-right: 50px;
color: white;
}
.present .name {
text-align: center;
}
.name::before {
content: url("img/blue_dot.png");
margin-right: 10px;
}
<div class="chat">
<div class="messages"></div>
<input type="image" id="imgClick" src="css/img/arrow.png">
<textarea class="entry" placeholder="Enter or arrow to send
Shift+enter for new line"></textarea>
</div>
<div class="indexBoxes">
<form action="index.php" method="POST">
<input type="submit" class="btn btn-info" name="logout" value="Logout">
</form>
</div>
<div class="present">
</div>
Now, since I set the chatbox to be resizable (resize:both), when a user tries to change its size, the list of the present users on the right side of the screen <div class="present"></div> also moves with it. If the user changes the height - drags it downwards - the list also goes down. I tried to prevent it by giving the list the position: absolute to take it out of the flow and then move it back to the right, but it didn't work, still moves with the chat. I also tried not using margin: 0 auto to center the box, thinking that it would have any effects, but that didn't work either.
Any suggestions would be highly appreciated.
Thanks!

If I understand well you're attempting to fix the 'div' with the class 'present' in the top right corner, aren't you?
If I've understood well your problem then try to take a look in code snippet I've made for your problem.
.chat {
margin-top: 10px;
}
.chat .messages {
background-color: white;
border: 1px solid #ccc;
width: 300px;
height: 250px;
padding: 10px;
resize: both;
overflow: auto;
margin: 0 auto;
font-weight: bold;
}
.present {
float: right;
margin-right: 50px;
position: absolute; /*added*/
right: 0; /*added*/
top: 0; /*added*/
color: black;
}
.present .name {
text-align: center;
}
.name::before {
content: url("img/blue_dot.png");
margin-right: 10px;
}
<div class="chat">
<div class="messages"></div>
<input type="image" id="imgClick" src="css/img/arrow.png">
<textarea class="entry" placeholder="Enter or arrow to send
Shift+enter for new line"></textarea>
</div>
<div class="indexBoxes">
<form action="index.php" method="POST">
<input type="submit" class="btn btn-info" name="logout" value="Logout">
</form>
</div>
<div class="present">User123<br>User321</div>
Let me know if you need further explanation.

Related

Independant margin for the submit button and the text input

I don't know why, but my text input and my submit button margin are linked, so it's ugly and very annoying.
I have this on my main html file :
.banner {
width: 100%;
height: 100px;
display: inline-flex;
margin: 0px;
background-color: #1b2936;
}
.logo {
width: 200px;
height: 100px;
}
input[type=text] {
background-color: #10151b;
border: #10151b 5px solid;
border-radius: 7px;
height: 50px;
width: 500px;
color: white;
font-family: jetbrainsRegular;
}
.search {
width: 50px;
height: 50px;
}
.searchbtn {
margin-top: 0px;
border: #1fa2f3 5px solid;
border-radius: 30px;
background-color: #1fa2f3;
}
.nomargin {
margin-top: 0;
}
<div class="banner">
<img class="logo" src="logo.png">
<form action="query.php">
<label>
<input type="text" id="query" placeholder="Mot" class="nomargin">
</label>
<label>
<button type="submit" class="searchbtn"><img src="search.png" class="search"/></button>
</label>
</form>
</div>
I am searching for a way to unlink their margins...
There is no margin, it's an issue with your form. Try this:
form{
display:flex;
}
Or (but I don't recommend it):
input[type=text]{
float:left;
}
Flex gives you much more flexibility (pun intended) and it's much easier to work with. https://css-tricks.com/snippets/css/a-guide-to-flexbox/

The text on my buttons is stuck to the bottom right of their padding

While attempting to develop a clean sidebar for use on my website, I noticed that the text in my buttons was getting stuck to the bottom right of their padding. I also observed that when I removed the styling on their borders, the problem went away.
I've tried several potential solutions and found the same outcome.
body {
background-color: #ddd;
}
* {
font-family: sans-serif;
}
input[type=button] {
position: relative;
top: 20px;
left: 25px;
margin-bottom: 20px;
border-radius: 12.5px;
border: none;
padding-top: 15px;
padding-left: 100px;
transition-duration: 0.7s;
}
input[type=button]:hover {
background-color: #00aaff;
border-color: white;
color: white;
}
#sideBar {
background: linear-gradient(#5900ff, #8000ff, #ae00ff);
position: absolute;
left: 0px;
top: 0px;
width: 220px;
height: 100%;
}
<div id="main">
<div id="sideBar">
<input type="button" value="Test Button" />
<input type="button" value="Test Button" />
<input type="button" value="Test Button" />
</div>
</div>
Text inside the button element is centered by default. However if you apply padding only on one side, the text will appear pushed to the opposite side. Remove the padding, or add padding-right as well, to omit this effect.

How do I keep a button appended to an input even at a smaller page width?

I am trying to append a button to a text input.
It works when I am in desktop mode, but when you change the size to a mobile-viewing size the button separates from the input.
Here is my fiddle.
I am using purecss:
input {
font-size: 16px;
padding-right: 50px;
border-radius: 0px;
height: 30px;
}
.pure-button {
margin-left: -45px;
height: 30px;
width: 40px;
padding: 1px;
}
span {
cursor: pointer;
display: inline-block;
height: 11px;
width: 8px;
text-align: center;
white-space: nowrap;
align-self: flex-start;
background: red;
background-position: 0 0;
margin: 1px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/pure-min.css" rel="stylesheet"/>
<div class="pure-g">
<div class="pure-u-1">
<form class="pure-form">
<fieldset>
<input type="text" class="pure-input-1-2" />
<button type="submit" class="pure-button pure-button-primary">
<span></span>
</button>
</fieldset>
</form>
</div>
</div>
There is a media query that is applying tules to to the input and the button from 0px - 480px. If you remove or override these, your fields will behave the same way as > 480px screen widths.
The library you're using is adding display: block to the input in a media query. That's forcing the button to the next line.
Add this to your CSS:
input, button {
display: inline-block !important;
margin: 0 !important;
}
The !important is needed to override the PURECSS code. Otherwise, alter the code in the source.
I also removed all whitespace between the elements in the code:
<input type="text" class="pure-input-1-2" /><button type="submit" class="pure-button pure-button-primary"><span></span></button>
This is one method for removing spaces between inline-block elements.
revised fiddle
Please try the below code within your existing code, hope this will help you.
.pure-form fieldset{
position: relative;
width: 50%;
padding: 0 45px 0 0;
margin: 10px;
box-sizing: border-box;
}
input {
font-size: 16px;
border-radius: 0px;
height: 30px;
}
.pure-form .pure-input-1-2{
width: 100%;
}
.pure-button {
position: absolute;
right: 0;
top: 0;
height: 30px;
width: 40px;
padding: 1px;
margin: 0 !important;
}
span {
cursor: pointer;
display: inline-block;
height: 11px;
width: 8px;
text-align: center;
white-space: nowrap;
align-self: flex-start;
background: red;
background-position: 0 0;
margin: 1px;
}
<div class="pure-g">
<div class="pure-u-1">
<form class="pure-form">
<fieldset>
<input type="text" class="pure-input-1-2" />
<button type="submit" class="pure-button pure-button-primary">
<span></span>
</button>
</fieldset>
</form>
</div>
</div>

Why is this div completely broken?

I have no idea whats going on here. Have a form contained in a div, and the div has a background color.
It works on one part of my website, but just doesn't work at all on another. Here's a Jsfiddle of whats going on
Also the affected code posted here:
form {
text-align: center;
}
input {
font-family: 'Cabin', sans-serif;
}
.submit-button {
text-decoration: none;
width: 80%;
background-color: white;
text-align: center;
height: 35px;
border-radius: 10px;
display: inline-block;
}
.input-half {
width: 40%;
display: inline-block;
float: left;
margin-left: 5%;
margin-right: 5%;
}
.input-half-2 {
width: 40%;
display: inline-block;
float: right;
margin-left: 5%;
margin-right: 5%;
}
input[type=text]:focus {
background-color: lightblue;
}
.contact-contain {
background-color: lightgray;
max-width: 100%;
}
.image-back {
width: 100%;
}
#back-img {
width: 100%
}
.cont-textarea {
resize: none;
width: 80%;
height: 110px;
}
<div class="contact-contain" id="link-c"><br>
<h1>Contact Over The Horizon:</h1><br><br>
<form>
<div class="input-half">
<label for="contname">Your Name</label><br>
<input class="input-box" type="text" name="contname"><br>
<label for="eaddress">Your Email</label><br>
<input class="input-box" type="text" name="eaddress"><br>
<label for="subj">Message Subject</label><br>
<input class="input-box" type="text" name="subj">
</div>
<div class="input-half-2">
<label for="contactmsg">Message Content</label><br><br>
<textarea class="cont-textarea"></textarea><br><br>
<button class="submit-button" type="submit" name="submitq" value="Send"><span>Submit Quote</span></button><br>
</div>
</form>
</div><br>
Wild guess: You want your div to contain your form (which has zero height). Do this:
.contact-contain {
overflow: hidden;
}
Demo
Trust me you will get better with time, but I think, to achieve what you want you can simply set a custom body background-color like this
body {background-color: lightgray;}
and you should be good

Top/Bottom Padding inside Nested Divs with Percentages

I'm having a trouble dealing with the padding inside a nested div.
The problem is that I have a banner on top (Small Bar) and another one below that with more content called the Banner. The banner's height is 150px, and I wish to make that entire space padded at the top and bottom for 10%. I also have a "center" div included in the "bannerspace" div which centers all of the content into a straight line down the middle for organization.
However, whenever I apply padding-top: 10%, the padding is applied to the entire body element, making the padding much larger than I expected.
I have spent a few hours looking for solutions and even asked my web-dev friend, and I could not get a working answer. I've found that this may be an expected behavior for vertical padding, but I'm not sure if any of you have solutions.
I have tried changing the positioning of most elements as well as the box-sizing method, neither of which have helped. I also tried using a margin, but the same problem still applies.
Here is my HTML for the body (Head is irrelevant):
<body>
<div class="header">
<!--Header Bar (Top) - "Stats" on PD-->
<div class="center">
<div class="stat1">
Filler: <br>
Test
</div>
<div class="stat2">
Filler: <br>
Test
</div>
<div class="stat3">
Filler: <br>
Test
</div>
<div class="stat4">
Filler: <br>
Test
</div>
<div class="stat5">
Filler: <br>
Test
</div>
</div>
</div>
<div class="banner">
<!--Banner Bar (Middle) - "Banner" on PD-->
<div class="center">
<div class="bannerlogo">
Logo
</div>
<div class="bannerspace">
<div class="loginarea">
Filler
</div>
<div class="registerarea">
Filler
</div>
</div>
</div>
</div>
This will be the homepage!
<form name="input" action="LoginPage.html" method="get">
<input type="submit" value="Login">
</form>
<form name="input" action="AccountPage.html" method="get">
<input type="submit" value="Account">
</form>
<form name="input" action="OtherPage1.html" method="get">
<input type="submit" value="Other 1">
</form>
<form name="input" action="OtherPage2.html" method="get">
<input type="submit" value="Other 2">
</form>
<form name="input" action="OtherPage3.html" method="get">
<input type="submit" value="Other 3">
</form>
</body>
And my CSS:
html {
height: 100%;
width: 100%;
margin: 0px;
font-family: "Roboto Normal 400", "Roboto", sans-serif;
font-size: 20px;
padding: 0px;
margin: 0px;
}
body {
height: 100%;
width: 100%;
margin: 0px;
text-align: center;
background: #DAFFDA;
padding: 0px;
text-align: center;
padding: 0px;
margin: 0px;
}
.center {
width: 90%;
height: 100%;
margin-left: 5%;
margin-right: 5%;
position: absolute;
}
.header {
height: 50px;
width: 100%;
border: 0px solid black;
background-color: #7C7C7C;
margin: 0px;
text-align: center;
border-bottom-width: 2px;
border-bottom-color: #3D3D3D;
position: relative;
}
.banner {
height: 150px;
width: 100%;
border: 0px solid black;
background-color: #6EFF81;
margin: 0px;
text-align: center;
border-bottom-width: 2px;
border-bottom-color: #3D3D3D;
position: relative;
}
.bannerlogo {
margin-top: 15px;
margin-bottom: 15px;
margin-left: 2%;
margin-right: 2%;
height: 80%;
width: 36%;
text-align: center;
float: left;
display: table-cell;
line-height: 120px;
vertical-align: middle;
border-width: 1px;
border-color: black;
border-style: solid;
position: absolute;
}
.bannerspace {
height: 100%;
width: 60%;
float: right;
padding-top: 10%;
padding-top: 10%;
}
.loginarea{
height: 80%;
width: 50%;
float: left;
}
.registerarea {
height: 80%;
width: 50%;
float: left;
}
Sorry for the bother. If you could point me to any guides/tutorials that cover information then I would be grateful.
EDIT: Also, it is important to note that this behavior only occurs when I use percentage. When I use a pixel measurement (Up to 130px, since the font size is 20 px), the padding is added from the end of the "Banner" class div, which is correct.
Vertical padding or margin uses parent's width as référence when used width % value.
You may try using an extra element or pseudo element to fill the area where you want padding apllied, using height inheritance.
This would be with empty pseudo:
.banner {height:150px;}
.center, .bannerspace {height:100%;}
.bannerspace:before , .bannerspace:after {
content:'';
display:block;
height:10%;
}
Mind too the use of box-sizing.