I am making a search bar for an idea of mine and I'm still very new to CSS.
My search button is below my text bar and my on hover button and I can't figure out the solution or find the reason why!
I have tried changing the margins, padding, and top/bottom percentages but to no avail
HTML
<div class="search-box">
<div class="location">
<input name="location" type="text"
placeholder="location"/>
</div>
<div class="dropdwn">
<button class="dropbtn">dropdown</button>
<div class="dropdwn-content">
<img src="../Media/sunny.png" alt="Sunny"
width="50" height="50">
<img src="../Media/partly_cloudy.png"
alt="partly_cloudy" width="50"height="50">
<img src="../Media/rain_s_cloudy.png" alt="rain_s_cloudy"
width="50"height="50">
</div>
</div>
<div class="searchbtn">
<button type="button">Search</button>
</div>
</div>
CSS
.search-box
{
width: 40%;
box-sizing: border-box;
border-radius: 3px;
border-style: solid;
position: absolute;
left: 35%;
top: 20%;
}
.location input
{
box-sizing: inherit;
width: 50%;
float:left;
}
.dropdwn
{
position: relative;
display: inline-block;
}
.searchbtn button
{
float: right;
}
.dropdwn-content
{
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
I am expecting my searchbtn to be top right of the box instead of the bottom right
When using display: inline-block, the whitespace matters. This can mess up %-based layouts and indentation a bit (see below).
The other issue I see is with your rules around setting input width, as this will affect the child element instead -- telling it to fill 50% of .location instead of .search-box.
I've simplified your code to highlight these changes, and added some %'s so that the input and buttons will stretch (or shrink) to fill their parents, who will in turn fill .search-box. A simple float: right on the .searchbtn element now sends it to the right, without a new line.
* {
box-sizing: border-box;
}
.search-box
{
box-sizing: border-box;
border-radius: 3px;
border-style: solid;
left: 35%;
top: 20%;
width: 60%;
}
.search-box > div {
display: inline-block;
}
.search-box button, input {
width: 100%;
}
.location {
width: 50%;
}
.searchbtn {
float: right;
}
<div class="search-box">
<div class="location">
<input name="location" type="text" placeholder="location"/>
</div><div class="dropdwn">
<button class="dropbtn">dropdown</button>
</div><div class="searchbtn">
<button type="button">Search</button>
</div>
</div>
Related
I have manged to piece together enough html/css from sources online to almost be able to do what I want. I am trying to display n (currently 4) images with buttons in the center next to each other horizontally across the top of the page. I have the four images loading with a button in the middle. I have them surrounded by a box. I have them acting responsively to the size of the browser (within reason).
Unfortunately, for a reason that is unclear to me, the images will only spread about half way across the box:
Here is what I believe to be the relevant html:
<div id ="buttonWrapper">
<div class="container" id="position1">
<img src="images/originals/mountainclimber.jpg" alt="Mountain Climber">
<button class="btn" id="mountainHtmlButton">The Mountain Climber</button>
</div>
<div class="container" id="position2">
<img src="images/originals/fuchun.jpg" alt="Fuchun">
<button class="btn" id="fuchunHtmlButton">Dwelling in the Fuchun Mountains</button>
</div>
<div class="container" id="position3">
<img src="images/originals/palace.jpg" alt="Palace">
<button class="btn" id="palaceHtmlButton">Amailenborg Palace Square</button>
</div>
<div class="container" id="position3">
<img src="images/originals/udnie.jpg" alt="Udnie">
<button class="btn" id="udnieHtmlButton">Udnie</button>
</div>
</div>
And the corresponding relevant CSS:
/* Container needed to position the button. Adjust the width as needed */
.container {
position: relative;
width: 25%;
}
/* Make the image responsive */
.container img {
width: 100%;
height: auto;
}
/* Style the button and place it in the middle of the container/image */
.container .btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 16px;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
}
.container .btn:hover {
background-color: black;
}
/*
**********
Section for button alignment/positioning stuff
**********
*/
#buttonWrapper {
background-color: black;
border-radius: 10px;
}
#position1 {
float: left;
/*width: 25%; */
overflow: hidden;
}
#position2 {
overflow:hidden;
}
#position3 {
overflow:hidden;
}
#position4 {
overflow:hidden;
}
The only 50% references I see appear to be tied to the button placement. But I clearly do not fully understand what is happening here. Again, my ideal outcome here is that the 4 images are displayed side by side horizontally all the way across the black background (assuming the window size is something reasonable). I know that will still look slightly strange because of the different aspect ratios of the images.
thank you for any help
#buttonWrapper {
display:flex;
}
/* ↑ i added above code ↑ */
.container {
position: relative;
width: 25%;
}
/* Make the image responsive */
.container img {
width: 100%;
height: auto;
}
/* Style the button and place it in the middle of the container/image */
.container .btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 16px;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
}
.container .btn:hover {
background-color: black;
}
/*
**********
Section for button alignment/positioning stuff
**********
*/
#buttonWrapper {
background-color: black;
border-radius: 10px;
}
#position1 {
float: left;
/*width: 25%; */
overflow: hidden;
}
#position2 {
overflow:hidden;
}
#position3 {
overflow:hidden;
}
#position4 {
overflow:hidden;
}
<div id ="buttonWrapper">
<div class="container" id="position1">
<img src="https://picsum.photos/300/700" alt="Mountain Climber">
<button class="btn" id="mountainHtmlButton">The Mountain Climber</button>
</div>
<div class="container" id="position2">
<img src="https://picsum.photos/300/700" alt="Fuchun">
<button class="btn" id="fuchunHtmlButton">Dwelling in the Fuchun Mountains</button>
</div>
<div class="container" id="position3">
<img src="https://picsum.photos/300/700" alt="Palace">
<button class="btn" id="palaceHtmlButton">Amailenborg Palace Square</button>
</div>
<div class="container" id="position3">
<img src="https://picsum.photos/300/700" alt="Udnie">
<button class="btn" id="udnieHtmlButton">Udnie</button>
</div>
</div>
Follow this in your CSS.
Give your container float:left; width: 25%; and position:relative;
.container img { width: 100%; object-fit: cover; height: auto;}
last thing from your html , make correction in ID names. You can not repeat ID name, You have repeated position3 ID twice.
I'm designing a hybrid mobile app and I have a simple form that has a clickable icon inside it. For the icon to stay always in the same place, regardless of screen sizes, someone suggested I added the property width: fit-content. This makes the icon stay where it's supposed to stay. However, now my form doesn't take 100% width anymore. If I change width: fit-content to width: 100%, then the icon loses it's spot.
This is what I need it to look like:
And I manage this width width: 100%
This is what it's looking like now:
And this is what it looks like with width: fit-content
Here's my code:
.wallet-body {
width: fit-content;
margin: 0 auto;
float: left;
}
.form-group {
position: relative;
}
.form-group input,
.pin-input {
border: 1px solid #2C2C2C;
height: 48px;
}
.qr-scanner-img {
width: 11%;
position: absolute;
top: 50%;
right: 2%;
transform: translateY(-50%);
}
<div class="wallet-body">
<form class="form-pagar">
<div class="form-group">
<input type="amount" class="form-control" id="amount" placeholder="Monto">
</div>
<div class="form-group">
<input type="IDuser" class="form-control" id="IDuser" placeholder="Email del destinatario">
<a href="#">
<img class="qr-scanner-img" src="img/qr.svg" alt="qr"></a>
</a>
</div>
<button type="button" class="btn btn-block btn-confirmar" data-toggle="modal" data-target="#modalConfirmation">Confirmar</button>
</form>
</div>
If I understood correctly you can use the position absolute for the icon.
you should add width:100% for .wallet-body and .pin-input
`
.wallet-body {
width: 100%;
margin: 0 auto;
float: left;
}
.form-group input,
.pin-input {
border: 1px solid #2C2C2C;
height: 48px;
width: 100%;
}
`
HTML :: Remove class from image and add in a tag
<a href="#" class="qr-scanner-img">
<img class="" src="img/qr.svg" alt="qr"></a>
CSS::
.qr-scanner-img {
width: 11%;
position: absolute;
top: 50%;
right: 2%;
transform: translateY(-50%);
text-align: right;
}
Hope will work.
I have tried to make a tag that completely covers a div element and when clicked, the button element would disappear.
HTML:
I have tried setting height and width to 100%, but this does not fill the area entirely... how do I fix this?
#startstorybutton {
height: 100%;
width: 100%;
position: absolute;
top: 7.5vw;
right: 20vw;
z-index: 10;
background-color: #f4511e;
color: white;
Font-size: 50px;
font-style: italic;
transition: all 0.6s;
cursor: url(cursors/select.PNG), pointer;
}
#story {
background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Three_little_pigs_%28geograph_4633727%29.jpg/1200px-Three_little_pigs_%28geograph_4633727%29.jpg");
background-size: 100%;
height: 40%;
width: 80%;
margin: 0 auto;
}
<div id="story">
<div>
<p id="storytitle">The Three Little Pigs</p>
<div>
<p id="storybox"></p>
</div>
<div id="storybuttonsection">
<button type="button" id="backbutton"><span>Go back</span></button>
<p id="pagenumber">121212</p><button id="continuebutton"><span>Continue</span></button>
</div>
</div>
<button type="button" id="startstorybutton">Start the story!</button>
</div>
You have to position the button element on top of the "hidden element", if you set the main element position to relative you can then position the child element absolute over it (top: 0; right: 0) with the height and width to 100%.
For hide the button, the easy way is to add a listener event to the button and then hide it (or remove it) with javascript.
#startstorybutton {
height: 100%;
width: 100%;
position: absolute;
top: 0;
right: 0;
z-index: 10;
background-color: #f4511e;
color: white;
Font-size: 50px;
font-style: italic;
transition: all 0.6s;
cursor: url(cursors/select.PNG), pointer;
}
#story {
background-image: url("https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Three_little_pigs_%28geograph_4633727%29.jpg/1200px-Three_little_pigs_%28geograph_4633727%29.jpg");
background-size: 100%;
height: 40%;
width: 80%;
margin: 0 auto;
position: relative;
}
<div id="story">
<div>
<p id="storytitle">The Three Little Pigs</p>
<div>
<p id="storybox"></p>
</div>
<div id="storybuttonsection">
<button type="button" id="backbutton"><span>Go back</span></button>
<p id="pagenumber">121212</p><button id="continuebutton"><span>Continue</span></button>
</div>
</div>
<button type="button" id="startstorybutton" onclick="this.style.display = 'none'">Start the story!</button>
</div>
I am not very sure of your HTML structure. But as you described your problem I have created an example for you.
You need t make changes in your HTML to make it simple and straightforward.
The story div contains the button, which will be absolutely positioned to fit the entire div.
I have thrown in a small bit of jQuery to show how it will look like.
$(function(){
$("button.overlay").click(function(){
$(this).hide();
});
});
.story{
width: 250px;
height: 100px;
border: 1px solid black;
text-align:center;
position: relative;
}
.overlay{
position: absolute;
top:0px;
left:0px;
height: 100%;
width:100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="story">
Here goes the story!
<button class="overlay">read story button</button>
</div>
The issue I am having is that when I change the size of the font in my button, the button then resizes. As of now, I would like to keep the buttons at one specific size. So, I have fixed my buttons to a specific size but now I cannot change the font size. I am currently running my program on Chrome.
Here is the HTML chunk:
<div class="file-input-wrapper">
<button class="btn-file-input">Upload Documents</button>
<input type="file" name="filesToUpload[]" id="filesToUpload" multiple="" onChange="makeFileList();" />
</div>
<p>
<strong>Files You Selected:</strong>
<ul id="fileList">
<li>No Files Selected</li>
</ul>
<div class="file-input-wrapper1">
<button class="btn-file-input1">Upload Documents</button>
<input type="submit" value="Upload!" />
</div>
</p>
<style type="text/css">
.file-input-wrapper {
width: 400px;
height: 125px;
overflow: hidden;
position: relative;
}
.file-input-wrapper>input[type="file"] {
font-size: 200px;
position: absolute;
top: 0;
right: 0;
opacity: 0;
}
.file-input-wrapper>.btn-file-input {
display: inline-block;
width: 400px;
height: 125px;
}
.file-input-wrapper:hover>.btn-file-input {
background-color: #aaa;
}
.file-input-wrapper1 {
width: 400px;
height: 125px;
overflow: hidden;
position: relative;
}
.file-input-wrapper1>input[type="submit"] {
font-size: 200px;
position: absolute;
top: 0;
right: 0;
opacity: 0;
}
.file-input-wrapper1>.btn-file-input1 {
display: inline-block;
width: 400px;
height: 125px;
}
.file-input-wrapper1:hover>.btn-file-input1 {
background-color: #ffff00;
}
</style>
You can set the button font size with the following:
button {
font-size: 40px;
}
Since your buttons have a defined height and width, it should not change their dimensions.
Add an additional class to all your buttons. Even if you have some "buttons" that are not actually buttons, but instead input type="submit" or input type="button", add this class to all of those things.
Then do this in your CSS:
.some_class_added_to_all_buttons{
width: some-width;
height: some-height;
font-size: some-font-size;
}
if you have a button that already has a class, add an additional one like this
<button class="btn-file-input1 additional_class">Upload Documents</button>
I've come up with what seems like a very hacky, non-semantic way to code a design that I'd like to use. Basically, it's a set of 4 equal-sized circles, distributed so their centers are the same as those of equilateral triangles. I've used a bunch of presentational divs to solve two issues: (1) to get the spacing of the circles right, I need their bounding boxes to overlap; and (2) to vertically space text in the circles without changing their size, it seems like I need to use display:table in my CSS.
It works, but I hate it, and I feel like there has to be a better way. I am new to CSS, and this method is the result of a fair amount of research about how to solve this design problem.
The design is at this codepen: http://codepen.io/bhagerty/pen/rejEPZ
(I put borders on a bunch of the elements just to show the structure.)
Here is the HTML:
<body>
<h1 id="home_title">test</h1>
<div id="container_1">
<div id="picture" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/%22In_Which_We_Serve%22_Advertisement_1943.jpg/1024px-%22In_Which_We_Serve%22_Advertisement_1943.jpg" width=100%; />
</div>
</div>
</div>
</div>
<div id="dog" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
dog
</div>
</div>
</div>
</div>
<div id="shoes" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
shoes
</div>
</div>
</div>
</div>
<div id="dance" class="box">
<div class="circle_outer">
<div class="circle_inner">
<div class="inner-text">
dance
</div>
</div>
</div>
</div>
<div id="footer_1">
Footer<br>
test
</div>
</div>
</body>
Here is the CSS:
* {
box-sizing: border-box;
padding: 0;
margin: 0;
font-size: 16px;
}
h1#home_title {
text-align: center;
font-size: 3rem;
margin: 0;
padding: .1rem 0 .5rem 0;;
background-color: grey;
}
div#container_1 {
border: green solid 5px;
width: 320px;
margin: auto;
position: relative;
}
div.box {
border: red solid 1px;
position: absolute;
width: 53.6%;
text-align: center;
background-color: transparent;
}
/*pseudo-element to give relative height,
per http://jsfiddle.net/simevidas/PFPDU/
and http://www.mademyday.de/css-height-equals-width-with-pure-css.html */
div.box::before {
content: "";
display: block;
padding-top: 100%;
height: 0;
}
/* if inner text has position relative, it influences the size of the containing box */
/*setting all of the positions to zero forces it inside the circle for some reason */
.circle_outer {
position: absolute;
overflow: hidden;
border: black solid 2px;
border-radius: 50%;
/* to create breathing room all around, set top and left to 1/2 of 100% - width (where width = height) */
top: 5%;
left: 5%;
width: 90%;
height: 90%;
}
.circle_inner {
/* border: grey solid 5px; */
display: table;
width: 100%;
height: 100%;
}
.inner-text {
display: table-cell;
/* border: green solid 2px; */
font-size: 2em;
vertical-align: middle;
}
/*First bounding box is at upper left corner */
div#picture {
overflow: hidden;
left: 0;
margin-top: 0;
}
/*Percent positions all based on W, derived from fact
that bounding boxes circumscribe tangent circles, and
circle centers are connected by equilateral triangles */
div#dog {
left: 46.4%;
margin-top: 26.8%;
}
div#shoes {
left: 0;
margin-top: 53.6%;
}
div#dance {
left: 46.4%;
margin-top: 80.4%;
}
div#footer_1 {
border: red solid 2px;
position: relative;
width: 100%;
left: 0;
margin-top: 137%;
text-align: center;
background-color: blue;
}
I much appreciate any thoughts or help. Thanks!
Well, IMO what you've done is really good. I wouldn't be too concerned about the extra divs.
But, it can be done with fewer divs, making use of float and margins.
Codepen is here
html {
font-size: 16px;
}
h1#home_title {
text-align: center;
font-size: 3rem;
margin: 0;
padding: .1rem 0 .5rem 0;;
background-color: grey;
}
div#container_1 {
border: green solid 5px;
width: 320px;
margin: auto;
position: relative;
box-sizing: border-box;
}
div.box {
border: red solid 1px;
position: relative;
float:left;
width: 53.6%;
text-align: center;
background-color: transparent;
box-sizing:border-box;
margin-bottom:-27%;
}
div.box:nth-child(2n) {
float:right;
}
div.box:nth-child(2n+1) {
float:left;
}
/*pseudo-element to give relative height,
per http://jsfiddle.net/simevidas/PFPDU/
and http://www.mademyday.de/css-height-equals-width-with-pure-css.html */
div.box::before {
content: "";
display: block;
padding-top: 100%;
height: 0;
}
/* if inner text has position relative, it influences the size of the containing box */
/*setting all of the positions to zero forces it inside the circle for some reason */
.featuring {
position: absolute;
overflow: hidden;
border: black solid 2px;
border-radius: 50%;
/* to create breathing room all around, set top and left to 1/2 of 100% - width (where width = height) */
top: 5%;
left: 5%;
width: 90%;
height: 90%;
font-size: 2em;
}
.featuring:before {
content:'';
margin-left:-0.25em;
display:inline-block;
vertical-align:middle;
height:100%;
}
/*Percent positions all based on W, derived from fact
that bounding boxes circumscribe tangent circles, and
circle centers are connected by equilateral triangles */
div#footer_1 {
border: red solid 2px;
position: relative;
width: 100%;
left: 0;
margin-top: 137%;
text-align: center;
background-color: blue;
clear:both;
}
<body>
<h1 id="home_title">test</h1>
<div id="container_1">
<div id="picture" class="box">
<div class="featuring">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/%22In_Which_We_Serve%22_Advertisement_1943.jpg/1024px-%22In_Which_We_Serve%22_Advertisement_1943.jpg" width=100%; />
</div>
</div>
<div id="dog" class="box">
<div class="featuring">
dog
</div>
</div>
<div id="shoes" class="box">
<div class="featuring">
shoes
</div>
</div>
<div id="dance" class="box">
<div class="featuring">
dance
</div>
</div>
<div id="footer_1">
Footer<br>
test
</div>
</div>
</body>