CSS How can I make button show image - css

I have a question about making a button show image
For example, I have four buttons
I want Each button showing image in the same content for images
In other words:
When you press one of the buttons show you image
here is an example: https://jsfiddle.net/i5yal/yvCtQ/1/
<div id="section-container">
<div class="section-img-container"><a>images will appear here</a>
</div>
</div>
<div id="section-button-container"><div>
<div class="section-button1"><a>1</a>
</div>
<div class="section-button2"><a>2</a>
</div>
<div class="section-button3"><a>3</a>
</div>
<div class="section-button4"><a>4</a>
</div>
</div>
</div>
CSS code:
#section-container {
background-color: #C0C0C0;
width: 300px;
height: 300px;
margin:0 auto;
}
#section-button-container {
width: 300px;
height: 30px;
margin:0 auto;
}
.section-button1 {
background-color: #808000;
width: 30px;
height: 30px;
float: left;
display: block;
margin-left: 30px;
margin-right: 20px;
}
.section-button2 {
background-color: #808000;
width: 30px;
height: 30px;
float: left;
display: block;
margin-left: 20px;
margin-right: 20px;
}
.section-button3 {
background-color: #808000;
width: 30px;
height: 30px;
float: left;
display: block;
margin-left: 20px;
margin-right: 20px;
}
.section-button4 {
background-color: #808000;
width: 30px;
height: 30px;
float: left;
display: block;
margin-left: 20px;
margin-right: 20px;
}
.section-img-container {
background-color: #008080;
background-position: center center;
width: 270px;
height: 270px;
margin: 0 auto;
}

To avoid using JavaScript, it's possible to use CSS (albeit there has to be some minor adjustments to your HTML in order to do so); so given the amended HTML:
<div id="section-container">
<div class="section-img-container">
<input type="radio" name="images" id="img1" />
<img src="http://placekitten.com/300/300/" />
<input type="radio" name="images" id="img2" />
<img src="http://lorempixel.com/300/300/nightlife" />
<input type="radio" name="images" id="img3" />
<img src="http://lorempixel.com/300/300/people" />
<input type="radio" name="images" id="img4" />
<img src="http://dummyimage.com/300x300/000/f90.png&text=image+lorem+ipsum" />
</div>
</div>
<div id="section-button-container"><div>
<div class="section-button1">
<label for="img1">1</label>
</div>
<div class="section-button2">
<label for="img2">2</label>
</div>
<div class="section-button3">
<label for="img3">3</label>
</div>
<div class="section-button4">
<label for="img4">4</label>
</div>
</div>
</div>
And the following CSS:
#section-button-container label {
display: block;
text-align: center;
height: 100%;
line-height: 30px;
cursor: pointer;
}
input[type=radio],
input[type=radio] + img {
display: none;
}
input:checked + img {
display: block;
}
JS Fiddle demo.
This does require that the browser supports the :checked pseudo-selector and the CSS next-sibling + combinator, however; and takes advantage of the label being able to check/uncheck a radio input (so long as the for attribute of the label identifies the id of the relevant input).
References:
:checked pseudo-selector`.
:checked pseudo-selector compatibility.

For the animation portion investigate this library, used it myself and it works nicely => animate.css
for the changing of the image it is rather trivial here is one way to do it.
$(document).ready(function() {
var viewer = $('img.viewer');
$('a.section-button').click(function () {
viewer.attr('src', 'your new path to new image');
});
});
In the above I added the classes that would be attached to the main view area so you'd have:
<img class="veiwer" />.
You'd just hide this or load up a default image when the page loads.
Also using "section-button" class on each anchor. I didn't account for positioning in the list of choices there meaning 1, 2, 3, 4th picture and so on. It might be easiest to have data-attributes for that on the section buttons. So something like.
<a class="section-button" data-imgrc="path to the large image" data-number="1">1</a>
Note you could also if you just have numbers inside the section buttons just grabber the inner text however personally I prefer data-attributes.

Related

CSS Invisible radio button but highlight wrapping div

The following HTML is being generates radio_buttons as selectors from an image label
<div class='small-2 columns buttonselector'>
<label for="content_ki_id_1">
<input class="invisi-selector" type="radio" value="1" name="content[ki_id]" id="content_ki_id_1" />
<img src="/assets/circle.svg" />
<div></div>
</label>
</div>
The CSS properly makes the radio button invisible, but there is a gap in handling the wrapper and its visibility on radio_button selected
.buttonselector > div {
width: 100%;
height: 100%;
background: #fff;
}
.invisi-selector {
opacity: 0;
}
.invisi-selector:checked + div {
border-color: #ba53ad;
border-width: 4px;
}
the wrapper cannot logically take the selector's class for it would be invisible. How can the checked action be binded to the wrapping div?
It can't, but you can use absolute positioning to make it look like it is.
.buttonselector>label {
width: 100%;
height: 100%;
background: #fff;
display: block;
position: relative;
}
.invisi-selector {
opacity: 0;
position: absolute;
}
.invisi-selector~div {
z-index: -1;
position: absolute;
left: -4px;
top: -4px;
width: 100%;
height: 100%;
}
.invisi-selector:checked~div {
border: 4px solid #ba53ad;
}
<div class='small-2 columns buttonselector'>
<label for="content_ki_id_1">
<input class="invisi-selector" type="radio" value="1" name="content[ki_id]" id="content_ki_id_1" />
<img src="/assets/circle.svg" />
<div></div>
</label>
</div>

display table taking extra space on margin top

I tried to create one component that similar to input-group in bootstrap. The reason i was not using the default input-group class of bootstrap is in default I cannot add multiple buttons and input element in input group addon. so i decided to create custom input-group using display-table property but when I use this property some extra space added to top in buttons section.
I need to align the input and counter component in same line.
HTML Part
<div class="product-order-form" matAutocompleteOrigin #origin="matAutocompleteOrigin">
<div class="product-inputGroup tableElem">
<div class="tableRow">
<input class="form-control tableCell" type="text" matInput [formControl]="myControl" [matAutocomplete]="auto" [matAutocompleteConnectedTo]="origin">
<div class="counter tableCell">
<div class="counterContainer">
<div class="value-button" id="decrease" value="Decrease Value">-</div>
<input type="text" id="number" value="0" />
<div class="value-button" id="increase" value="Increase Value">+</div>
</div>
</div>
</div>
</div>
</div>
CSS:
.tableElem{
display:table;
width:100%;
}
.tableRow{
display:table-row;
width:100%;
}
.tableCell{
display:table-cell;
}
.product-order-form{
height: 30px;
}
.counterContainer {
width: 150px;
height:30px;
}
.value-button{
text-align: center;
height: 100%;
width: 50px;
background: lightgray;
padding: 5px;
box-sizing: border-box;
float: left;
}
.value-button:hover {
cursor: pointer;
}
input#number{
text-align: center;
height: 100%;
border: none;
width: 50px;
float: left;
box-sizing: border-box;
border-top: 0.5px solid lightgray;
border-bottom: 0.5px solid lightgray;
}
here is my stackblitz
There are two issues here:
.product-order-form sets a height of 30px which means it is shorter than some of it's children / siblings. That would cause issues (try adding overflow:hidden to see it in action)
.tableCell has no vertical-align which would mean it will position itself at the top o/t component. Try adding vertical-align: middle and it should work fine
TL;DR
.tableCell[_ngcontent-c2] {
display: table-cell;
vertical-align: middle;
}
.product-order-form[_ngcontent-c2]{
height: auto;
}
should do the trick :)

Main container is not showing scrollbar

Hello All I hope you are doing Fine! So actually I'm working a chatroom and Im having problem displaying the messages. You see what is actually happening is that when i enter a message the message box goes down. Instead what I want is that I want the messages at the top go behind the navbar and I want the container which shows the message to show a scrollbar so the message send box will stay in place
my index.php
body {
overflow: none;
}
.container {
border: 2px solid #dedede;
background-color: #f1f1f1;
border-radius: 5px;
padding: 10px;
margin: 10px 0;
overflow: auto;
}
.darker {
border-color: #ccc;
background-color: #ddd;
}
.container::after {
content: "";
clear: both;
display: table;
}
.container img {
float: left;
max-width: 60px;
width: 100%;
margin-right: 20px;
border-radius: 50%;
}
.container img.right {
float: right;
margin-left: 20px;
margin-right: 0;
}
.time-right {
float: right;
color: #aaa;
}
.time-left {
float: left;
color: #999;
}
<div class="container">
<p>
<div id="load_msg"></div>
</p>
<span class="time-right">11:00</span>
</div>
<div class="container darker">
<form method="POST" action="">
<input type="text" name="message" id="message_id" />
<button type="button" id="send_msg">Send</button>
</form>
</div>
You have two .container: One for the messages and another for the form. You need to separate the two, so give the container for the messages an id. TheN you set a height for the container with the id.
HTML
<div class="container" id="msg">...</div>
<div class="container">...</div>
CSS
#msg {
height: 100px;
}
Take a look at this link

CSS positioning query

I have a webpage with a background graphic that is 1024x768. My CSS and HTML is below. I also have a header graphic and a left side menu that is formatted text.
I want to create a template page. Everything is OK except...
I have a footer that I want to display at the bottom of the background area. How do I position that so that no matter what content I add the footer stays put? Not fixed as in position: fixed but placed in a preset position.
I have tried using a div tag to surround all but the footer with a width and height specified. I then added a div for the footer and expected it to position itself outside the first div. Clearly I have misunderstood.
JSFiddle with following HTML and CSS
HTML
<body>
<div id="allcontent">
<div id="header">
<img src="images/xxxxxxxxxxx.png" alt="xxxxxxxxx" />
<br /</div>
<div id="menu">
Home
<br />
<br />
Weddings
<br />
<br />
Portraits
<br />
<br />
Blog
<br />
<br />
Connect
</div>
</div>
<div id="footer">
<div id="phone">
tel. xxxxxxxx
</div>
<div id="email">
email: xxxx#xxxxxxxxxxxx.co.uk
</div>
<br />
<div id="copy">
© 2012, xxxxxxxxxxxxxx
<br />
Website constructed by <a class="footlink" href="http://xxxxxxxxxxx.co.uk" target="_blank">xxxxxxx</a>
</div>
</div>
</body>
CSS
body {
font-family: Arial,Helvetica,sans-serif;
font-size: large;
width: auto;
margin-left: auto;
margin-right: auto;
background-color: #451918;
color: #221b1b;
}
div#allcontent {
width: 1024px;
height: 768px;
margin-left: auto;
margin-right: auto;
background-image: url("images/web page background 1024x768.jpg");
background-repeat: no-repeat;
}
a {
text-decoration: none;
}
div#menu {
float: left;
}
div#header {
padding-top: 50px;
padding-left: 50px;
text-align: left;
}
div#footer {
bottom: 0;
height: 50px;
text-align: center;
font-size: 85%;
color: #221b1b;
}
div#copy {
font-size: 50%;
}
div#phone {
font-size: 85%;
margin-left: 40px;
float: left;
}
div#email {
margin-right: 40px;
font-size: 85%;
float: right;
}
a.footlink:link {
color: #221b1b;
}
a.footlink:visited {
color: #221b1b;
}
a.footlink:hover {
color: #226225
}
a:link {
color: #9c7f7f;
}
a:hover {
color: #221b1b;
}
a:visited {
color: #5f4d4d;
}
You'll have to clear the floats of any div that precedes the footer.
Go ahead and set clear:both to #footer to see if it addresses the issue.
If all is well, you won't need to set heights for any of the elements before the footer, nor apply any of the workarounds that you may have tried.
Refer to this fiddle
There float in your menu so you have to clear it. Give clear:both on #footer. Like this:
#footer {
clear:both
}
http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page
here is the trick. You can follow the link to a tutorial for positioning footer

Whitespace is being added to an overlay in IE9, but not in Fx5

I'm trying to overlay a "search box" over a Google Maps API V3. The overlay works fine in Fx5, but in IE9 it does not work quite right. Some white space is added by IE9 between the map and the gray div. To see the difference, go to:
http://www.trailheadfinder.com/trail_search/trail_map
The "search box" should be aligned with the Map/Sattelite/MyTopo buttons.
HTML
<div id="maplayers">
Select information to be shown:
Trails: <input type="checkbox" id="trailsbox" onclick="boxclick(this,'trails')" />
Campgrounds: <input type="checkbox" id="campgroundsbox" onclick="boxclick(this,'campgrounds')" />
Panoramio: <input type="checkbox" id="panoramiobox" />
</div>
<div>
<div id="mapsearchbar">
<input id="searchTextField" type="text" size="50">
</div>
<div id="map" style="width: 100%; height: 500px"></div>
</div>
CSS
<style type="text/css">
#mapsearchbar {
float: right;
position: relative;
right: 200px;
top: 5px;
z-index: 999;
}
#maplayers {
padding-top: 10px;
padding-bottom: 10px;
padding-left: 10px;
margin-top: 20px;
background-color: #C4C4C4;
}
</style>
The gap is there because you are giving it a position of relative and then offsetting is using top: 5px; right: 200px. This cause it to move but leave a gap in its origional position. Do as follows.
div
{
position: relative;
}
div#mapserachbar
{
position: absolute;
top: 5px;
right: 170px;
}
And remove float:right from it.

Resources