I would like two create two buttons that overlay a div using HTML like the following:
*Both the same DIV with two buttons overlapping each side. So one div with two buttons overlapping.
I would like the buttons to be transparent and overlay the div but I am not sure how.
I have created my Div:
<div class="container">
<div id="slides">
<img src="img/example-slide-1.jpg" alt="Photo by: Missy S Link: http://www.flickr.com/photos/listenmissy/5087404401/">
</div>
</div>
The div I would like to overlay is called "container" and the two buttons are:
<i class="icon-chevron-left icon-large"></i>
<i class="icon-chevron-right icon-large"></i>
Is there any way in CSS or HTML to do this?
You have to place your buttons absolutely on top of your image. To do so, first make .container take a position: relative; and then put your buttons as siblings of your .slides div and place them absolutely.
.container {
position: relative;
}
.slidesjs-navigation {
position: absolute;
top: 0;
display: block;
width: 50%;
height: 100%;
background: rgba(0,0,0,0); /* Added in case you want to transition this */
}
.slidesjs-navigation:hover {
background: rgba(0,0,0,0.25); /* Makes the hovered button visible */
}
.slidesjs-previous {
left: 0;
}
.slidesjs-next {
right: 0; /* left: 50%; works too */
}
.slides img {
display: block; /* Avoids the space usually seen under inline images */
width: 100%; /* Ensures the image takes up the whole width */
}
<div class="container">
<div id="slides" class="slides">
<img src="https://c1.staticflickr.com/5/4147/5087404401_d24513119a_b.jpg" alt="Photo by: Missy S Link: http://www.flickr.com/photos/listenmissy/5087404401/"><!-- original `src`: "img/example-slide-1.jpg" -->
</div>
<i class="icon-chevron-left icon-large"></i>
<i class="icon-chevron-right icon-large"></i>
</div>
Here is a simple way to do it. Put both buttons inside a div with a height:100%, width:50% and float:left;. This way each button takes up the full height of the div but only half of its width. The float:left; will then put them side by side in the div, hopefully achieving what you want!
.box {
border:1px solid black;
height:200px;
width:400px;
background-color:#005680;
}
.button1 {
width:50%;
height:100%;
float:left;
background-color: rgba(0,0,0,0);
border:0px solid black;
}
.button2 {
width:50%;
height:100%;
float:left;
background-color: rgba(0,0,0,0);
border:0px solid black;
}
.button1:hover {
background-color: rgba(10,10,10,0.1);
}
.button2:hover {
background-color: rgba(10,10,10,0.1);
}
<div class="box">
<button class="button1"></button>
<button class="button2"></button>
</div>
This can be your code.
.d {
position:relative;
}
.b1 {
float:left;
height:100px;
width:75px;
}
.b2 {
position:absolute;
left:75px;
height:100px;
width:75px;
}
<div class="d">
<button class="b1"></button>
<button class="b2"></button>
</div>
So basically you would like to create something similar to a toggle button or on/off switch? You could try something like:
HTML:
<div id="toggle">
<a id="left-side" href="">Left</a>
<a id="right-side" href="">Right</a>
</div>
CSS:
<script type="text/css">
DIV#toggle {
width:100px;
height:50px;
margin:0px;
padding:0px;
}
DIV#toggle>A {
display:block;
width:50%;
height:100%;
padding:0px;
text-size:10pt;
text-align:center;
}
DIV#toggle>A#right-side {
margin:0px auto 0px 0px;
background-color:#ff0000;
}
DIV#toggle>A#left-side {
margin:0px 0px 0px auto;
background-color:#00ff00;
}
</script>
Since you mentioned that the buttons are in the div, you can simply position them using position: absolute. By adding position: relative to the container, you can position them within that container rather than within the document as a whole.
/* -------------------------------------------------- --
The part that you actually need
-- -------------------------------------------------- */
/* Allow elements to be positioned relative to the container */
.container {
position: relative;
}
/* Let the buttons both cover the (left) half of the div */
.container .slidesjs-navigation {
position: absolute;
top: 0;
left: 0;
width: 50%; /* Of .container, its positioning parent */
height: 100%; /* Of .container */
}
/* Make an exception for the second button to move it to the right half */
.container .slidesjs-next {
left: 50%;
}
/* -------------------------------------------------- --
The part that's just for the demonstration.
-- -------------------------------------------------- */
/* Make the content large to show that the buttons scale */
#slides {
padding: 50px;
}
/* Make the div red, as in the question */
.container {
background-color: red;
}
/* Have white, semi-transparent buttons with a border, so you see where they are */
.container .slidesjs-navigation {
background-color: white;
border: 1px dashed black;
box-sizing: border-box;
opacity: 0.5;
}
/* Make the buttons opaque on hover to show that they respond */
.container .slidesjs-navigation:hover {
opacity: 1;
}
<div class="container">
<i class="icon-chevron-left icon-large"></i>
<i class="icon-chevron-right icon-large"></i>
<div id="slides">
<img src="img/example-slide-1.jpg" alt="Photo by: Missy S Link: http://www.flickr.com/photos/listenmissy/5087404401/">
</div>
</div>
Hope this is what you were looking for. Happy to explain or help in a better solution if needed.
.container {
width: 100vw;
height: 50vh;
background-image: url('https://c1.staticflickr.com/5/4147/5087404401_d24513119a_n.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
margin: 0;
padding: 0;
}
.container a{
width: 49.5%;
height: 50vh;
margin: 0;
padding: 0;
display: inline-block;
}
.container a:hover{
width: 49.5%;
height: 50vh;
background: rgba(255,255,255,0.4);
margin: 0;
padding: 0;
display: inline-block;
}
<div class="container">
<i class="icon-chevron-left icon-large"></i>
<i class="icon-chevron-right icon-large"></i>
</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.
Here is the effect I am trying to achieve:
Example
I know how to make the triangle, my issue is that is is being created INSIDE of the box. If I set "left" to 100%, the box will disappear behind the right side of the box instead of going outside of the box over the next one.
Here is the Pen I am working on to try and get this to work:
My Code
HTML:
<div class="square title">
<div class="content">
<div class="table">
<div class="table-cell ">
<ul>This demo shows you can center multiple types of content :
<li>Text</li>
<li>Images</li>
<li>Lists</li>
<li>... (you can also do it with forms)</li>
</ul>
</div>
</div>
</div>
</div>
<div class="square">
<div class="content">
<div class="table">
<div class="table-cell ">
<p>Hello World!</p>
</div>
</div>
</div>
</div>
CSS:
body {
font-family: sans-serif;
color: #fff;
font-size: 20px;
text-align: center;
}
.square {
float:left;
position: relative;
width: 33%;
padding-bottom : 33%; /* = width for a 1:1 aspect ratio */
/* margin:1.66%; */
background-color:#1E1E1E;
overflow:hidden;
/* border: solid 1px red; */
margin: 5px;
}
.content {
position:absolute;
height:90%; /* = 100% - 2*5% padding */
width:90%; /* = 100% - 2*5% padding */
padding: 5%;
}
.table{
display:table;
width:100%;
height:100%;
}
.table-cell{
display:table-cell;
vertical-align:middle;
}
/* For list */
ul{
text-align:left;
margin:5% 0 0;
padding:0;
list-style-position:inside;
}
li{
margin: 0 0 0 5%;
padding:0;
}
.title::after {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
border-left: 50px solid green;
left: 95%;
/* top: 45%; */
/* z-index: 999; */
}
I tried making a whole new div around the square and setting that to have the triangle, but it made the triangle go all the way to the right of the screen, even without setting anything for the left or right.
I also tried z-index but that didn't do anything either.
You can easily achieve this with only background:
.box {
display: inline-block;
width: 150px;
height: 150px;
background: grey;
}
.box:last-child {
background:
linear-gradient(to top right,grey 49.8%,transparent 50%) 0 calc(50% - 15px),
linear-gradient(to bottom right,grey 49.8%,transparent 50%) 0 calc(50% + 15px),
#000;
background-size:30px 30px;
background-repeat:no-repeat;
}
<div>
<div class="box">
</div>
<div class="box">
</div>
</div>
This question already has answers here:
CSS3 curved cutout from div?
(2 answers)
Closed 6 years ago.
I'm trying to create the following layout in CSS.
This would usually be easy to do, however because the background is an image (illustrated in my image as a gradient), I can't simply add a absolute positioned div at the top and color the 'cut away'. I've been struggling to work out how to do this for the last few hours.
I've looked up some examples using the ::before and ::after pseudo selectors, however can't work out how do it while keeping the border radius on the main content div (blue).
<div class="content">
<div class="header">
<a class="left" href="#">LINK 1</a>
<!--
Stuck with how to position this so it clips
<img class="logo" src="https://placehold.it/100x100">
-->
<a class="right" href="#">LINK 2</a>
</div>
<p>Some text content</p>
.content {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-radius: 20px;
background-color: blue;
height: 300px;
width: 400px;
padding: 20px;
}
.header {
position: relative;
top: -50px;
padding: 0 20px;
}
.header .right {
float: right;
}
Demo: http://jsbin.com/saxunecidu/1/edit?html,css,output
Radial gradient for rescue!
#test{
padding:10px;
background:rgb(100,100,240);
color:white;
font-size:25px;
-webkit-mask-image: radial-gradient(circle at top, transparent 30px, black 31px);
border-radius:15px;
width:600px;
height:150px;
margin:10px;
}
body{
background: radial-gradient(lightgrey,black);//just an example gradient
}
<div id="test">Something there</div>
You may use a pseudo and a hudge box shadow to paint background-color and cut off a curve.
For the nav on top, flex can easily do it.
.cut {
margin: 1em auto 1em;
padding :40px 1em 1em;
color:white;
height: 75vh;
/* demo purpose */
width: 70vw;
/*demo purpose */
border-radius: 1em;
overflow: hidden;
position:relative;
}
.cut:before {
content:'';
width:80px;
border-radius:50%;
height:80px;
display:block;
margin:-80px auto 0;
box-shadow:0 0 0 3000px #2D3E50
}
.rd {
display: flex;
/* demo purpose */
width: 70vw;
margin: 1em auto -45px;;
border-radius: 50%;
}
.rd img {
margin :0 auto ;
flex-shrink:0;
border-radius:50%;
}
.rd a {
margin: 0 auto auto; /* put links at top */
}
body {
background:linear-gradient(to top, #ccc,#999);
<nav class="rd"><a href >link</a> <img src="http://dummyimage.com/60x60/464646/&text=image" /><a href >link</a>
</nav>
<div class="cut">
content in here to set away from curve
</div>
I've got a tile containing a title, a category, a link to the category, a picture and a global link to the picture. As it is, this global link is only active in a piece of the picture area. I would like it to be global.
Here is the HTML :
<div id="article">
<div class="block-module">
<a class="view-full-module" href="http://www.cosmos.com/Common/Images/Destinations/machupicchu3.jpg">
<img class="image" src="http://www.cosmos.com/Common/Images/Destinations/machupicchu3.jpg"/>
</a>
<div class="block-about">
<h2 class="block-title">Title</h2>
<span class="block-stats">Category Date</span>
</div>
</div>
</div>
Here is the CSS :
.view-full-module { cursor: pointer; top: 0px; left: 0px; z-index: 2; background: none repeat scroll 0% 0% rgba(31, 32, 33, 0); width: 100%; height: 100%; }
.image { width: 100%; }
.block-module { width: 100%; position:relative; margin:0; padding:0; cursor:pointer; border-radius:10px; z-index:4; }
.block-about { position:absolute; bottom:0; left:0; right:0; padding:4em 1em 1em 1em; background-image:-webkit-linear-gradient(transparent, rgba(0,0,0,0.55), rgba(0,0,0,0.8)); background-image:linear-gradient(transparent, rgba(0,0,0,0.55), rgba(0,0,0,0.8)); }
.block-about a { position:relative; z-index:5; }
.block-title { max-width:100%; margin:0 0 0; color: white !important;font-size:1.625em; }
.block-stats { width:100%; margin-top:0.35714em; font-size:0.875em; color:rgba(255,255,255,0.55) !important; }
.author-link { color:#659dae; }
#article { top:0; margin: 0; padding:20px; -moz-column-gap: 20px; -webkit-column-gap: 20px; column-gap: 20px; -moz-column-width: 260px; -webkit-column-width: 260px; column-width: 260px; }
Here is a demo : http://jsfiddle.net/5qwejk20/4/
One option would be to add pointer-events: none to the element .block-about.
In doing so, you can essentially click through the element:
Updated Example
.block-about {
pointer-events: none;
}
Browser support for the pointer-events property can be found here.
Another option would be to move the anchor element and then absolutely position it relative to the parent in order to take the full dimensions.
The reason you need to move the anchor element in the DOM is because if it wraps the img element, then you can't have your background fading at the bottom since the anchor needs to be positioned above it in order for the click event to work anywhere within the element.
Updated Example
.view-full-module {
cursor: pointer;
position: absolute;
top: 0; right: 0;
bottom: 0; left: 0;
z-index: 2;
}
<div id="article">
<div class="block-module">
<img class="image" src="http://www.cosmos.com/Common/Images/Destinations/machupicchu3.jpg" />
<div class="block-about">
<h2 class="block-title">Title</h2>
<span class="block-stats">Category Date</span>
</div>
<a class="view-full-module" href="http://www.cosmos.com/Common/Images/Destinations/machupicchu3.jpg"></a>
</div>
</div>
As a side note, you may want to add vertical-align: top to the img element in order to remove the gap under it.
Example without the gap
img {
vertical-align: top;
}
My problem is that i want to display block from left to right. You can see my current effect and red box what I'm expecting to get.
what I'm doing wrong? as i did tried to use float left on nmenu_drop class.
CSS:
.wraper{
margin-left:10px;
float:left;
position:relative;
}
.notification_dropdown{
height:40px;
margin-right:10px;
float: right;
position:relative;
padding-left: 10px;
width:30px;
}
.nmenu_drop{
width:200px;
height:300px;
background:#FFF;
clear:both;
position:absolute;
margin-top:40px;
float:right;
}
.nmenu_drop{
display: none;
}
.notification_dropdown:hover + .nmenu_drop {
display: block;
background:#4B4B4B;
}
.nmenu_drop:hover {
display: block;
}
.notification_dropdown:hover{
background:#4B4B4B;
}
HTML:
<div class="wraper">
<div class="notification_dropdown">
<i class="fa fa-globe" style="font-size: 21;color: #8a8a8a; margin-top: 9px;"></i>
</div>
<div class="nmenu_drop">
notification
</div>
</div>
Try adding:
.nmenu_drop {
right: 0;
}
You can play with left and transition:
#wrapper{
position: relative; /* Important, we are going to offset to this div*/
}
#menu{
position: absolute;
width: 100%; /* It looks mobile, so I took this */
top: 0;
left: -105%; /* The extra 5% is easy fix to paddings and borders and stuff */
transition: left 0.5s; /* animate it */
}
#menu.Opened{
left: 0; /* position moved back in */
}
All you have to do now is to add a class Opened to it.
I've made a small demo