When the browser window is resized, the borders are shifting away from the content?
How can I achieve a design where the border remains in one place, no matter the height of the window?
.story_header {
position: relative;
display: flex;
justify-content: center;
}
.story_header:before,
.story_header:after {
content: '';
width: 100px;
position: absolute;
border: 2px solid black;
margin-top: 20px;
left: 35%;
}
.story_header:after {
right: 35%;
left: auto;
}
<div class='section_1'>
<div class="grid-x">
<div class='large-12 cell'>
<h2 class='story_header'>Our Story</h2>
</div>
</div>
You need to wrap the 'Our Story' to an element let's say span then add the pseudo elements on that span. Try this:
CSS:
.story_header{
position:relative;
display:flex;
justify-content: center;
}
.story_title{
position:relative;
}
.story_title:before, .story_title:after{
content:'';
width:100px;
position:absolute;
border:2px solid black;
margin-top:20px;
}
.story_title:before{
right:100%;
}
.story_title:after{
left:100%;
}
HTML:
<div class="grid-x">
<div class='large-12 cell'>
<h2 class='story_header'> <span class="story_title">Our Story</span></h2>
</div>
</div>
Related
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>
I can't sort out how to move the element, which is placed under .content-wrapper{ overflow:hidden; .content{position:absolute;} }, to the very top.
Consider a screenshot below:
An image element with man photo is placed under the .content element. But the part of his head on photo, which is highlighted with yellow (pointed with red arrow) is hidden due to the parent .content-wrapper has an overflow:hidden property. The main problem is that I can't change the hidden overflow to whatever else.
Is that actually real to solve such a problem without using a JavaScript?
==== Supplement 1 ====
To clarify the problem, I've made up a code snippet below:
.wrapper{
width:100%;
overflow:hidden;
position:initial;
padding:0 10px;
background-color:#EEEEEE;
box-sizing:border-box;
}
.content-wrapper{
position:relative;
overflow:hidden;
background-color:#DDDDDD;
margin:10px 0;
min-height:350px;
}
.content{
background-color:white;
position:absolute;
top:30px;
left:10px;
right:10px;
bottom:10px;
}
.content.grayed{
background-color:#CCCCCC;
}
.content.positioned{
top:50px;
left:180px;
bottom:-50px; //negative positioned parts supposed to be hidden
right:-50px; //as .content-wrapper has overflow:hidden;
}
.content.positioned img{
width:40%;
height:auto;
margin-top:-40vh; //but that is not supposed to be hidden out of .content-wrapper
margin-left:10vw;
min-width:250px;
}
<div class="wrapper">
.wrapper
<div class="content-wrapper">
.content-wrapper
<div class="content grayed" style="transform: rotate(-35deg); padding:20px;">
<strong>.content</strong> with cut off edges - that is supposed behaviour
</div>
</div>
<div class="content-wrapper">
.content-wrapper
<div class="content positioned">
<strong>.content</strong>
<img src="//i.imgur.com/DsOdy1V.png">
<br>
...and a man above is with sliced head - that is UNsupposed behaviour
</div>
</div>
</div>
Is there really no any solution?
I would consider adding the image outside and adjust the position to obtain this. Change the translation to adjust the position:
.wrapper {
width: 100%;
overflow: hidden;
position: relative; /*change this*/
padding: 0 10px;
background-color: #EEEEEE;
box-sizing: border-box;
}
.content-wrapper {
position: relative;
overflow: hidden;
background-color: #DDDDDD;
margin: 10px 0;
min-height: 350px;
}
.content {
background-color: white;
position: absolute;
top: 30px;
left: 10px;
right: 10px;
bottom: 10px;
}
.content.grayed {
background-color: #CCCCCC;
}
.content.positioned {
top: 50px;
left: 180px;
bottom: 0;
right: 0;
padding: 20px calc(40% - 0.4*148px) 0 20px; /* the space of the image*/
}
.content.positioned img {
position: absolute;
opacity: 0; /*Hide this one*/
}
.hack {
/*Don't use any top/bottom here !!*/
left: 190px;
right: 10px;
position: absolute;
z-index: 1;
}
.hack img {
width: 40%;
position: absolute;
right: 0;
bottom: 0;
transform: translateY(70%);
max-width:300px;
}
<div class="wrapper">
.wrapper
<div class="content-wrapper">
.content-wrapper
<div class="content grayed" style="transform: rotate(-35deg); padding:20px;">
<strong>.content</strong> with cut off edges - that is supposed behaviour
</div>
</div>
<div class="hack">
<img src="//i.imgur.com/DsOdy1V.png">
</div>
<div class="content-wrapper">
.content-wrapper
<div class="content positioned">
<strong>.content</strong>
<img src="//i.imgur.com/DsOdy1V.png">
<br> ...and a man above is with sliced head - that is UNsupposed behaviour
</div>
</div>
</div>
Add a <div> like content-wrapper-inner and move the height, position from content-wrapper into it.
.wrapper{
width:100%;
overflow:hidden;
position:initial;
padding:0 10px;
background-color:#EEEEEE;
box-sizing:border-box;
}
.content-wrapper{
overflow:hidden;
background-color:#DDDDDD;
margin:10px 0;
}
.content{
background-color:white;
position:absolute;
top:30px;
left:10px;
right:10px;
bottom:10px;
}
.content-wrapper-inner {
min-height:350px;
position:relative;
background-color: red;
}
.content.grayed{
background-color:#CCCCCC;
}
.content.positioned{
top:50px;
left:180px;
bottom:-50px; //negative positioned parts supposed to be hidden
right:-50px; //as .content-wrapper has overflow:hidden;
}
.content.positioned img{
width:40%;
height:auto;
margin-top:-40vh; //but that is not supposed to be hidden out of .content-wrapper
margin-left:10vw;
min-width:250px;
}
<div class="wrapper">
.wrapper
<div class="content-wrapper">
.content-wrapper
<div class="content grayed" style="transform: rotate(-35deg); padding:20px;">
<strong>.content</strong> with cut off edges - that is supposed behaviour
</div>
</div>
<div class="content-wrapper">
.content-wrapper
<div class="content-wrapper-inner">
<div class="content positioned">
<strong>.content</strong>
<img src="//i.imgur.com/DsOdy1V.png">
<br>
...and a man above is with sliced head - that is UNsupposed behaviour
</div>
</div>
<div class="content positioned">
<strong>.content</strong>
<img src="//i.imgur.com/DsOdy1V.png">
<br>
...and a man above is with sliced head - that is UNsupposed behaviour
</div>
</div>
</div>
Try to make overflow:visibleof the outer div of the content.
You can't have content reach out of a parent with overflow: hidden and still find a way to show the head. The question is why you need overflow hidden on the parent.
Perhaps you could use a sibling element for the image container and limit overflow on the content container.
Something like:
HTML
<div class="parent">
<div class="child-content-wrapper">
Content goes here
</div>
<div class="child-image">
Image goes here
</div>
</div>
CSS:
.parent {
position: relative;
}
.child-content-wrapper {
overflow: hidden;
}
.child-image {
position: absolute;
right: 0;
bottom: 0;
z-index: 1;
}
That should work and you'll be able to get the cut off effect on the rotated content box and the whole head.
How do I place an image on top of a button with html and css?
<div>
<img src="photo.jpg">
<button>Text</button>
</div>
I guess it should be something like
div {
position: relative;
}
img {
position: absolute;
top: 10px;
}
but it acts a bit weird.
Is it possible to just have a normal div and then set the img to float on top of everything else in the div element?
I don't know what's your purpose exactly, if you want the image to take the whole line, make the button lay beneath, why don't set the CSS display attribute of the image to display:block;?
hello see the below one its simple with a few line code
<div style="position:relative;" >
<img src="http://www.industrydynamics.ca/images/skype_icon.png" width="100" height="100" >
<input type="button" name="" value="Button" style="position:absolute;width:80px;left:10px;top:120px;" >
</div>
You can use position: absolute with transform: translate() on img.
This calc(-100% - 1px) means
-100% or - height of element (img in this case) that you are performing transform on, so it will translate for its own height up on Y axis
-1px is for top border on div element.
div {
position: relative;
display: inline-block;
border: 1px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 1px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
Just to demonstrate if you have border of 5px then you should use -5px in calc.
div {
position: relative;
display: inline-block;
border: 5px solid black;
margin-top: 100px;
}
img {
position: absolute;
top: 0;
transform: translateY(calc(-100% - 5px));
}
<div>
<img src="http://placehold.it/50x50">
<button>Text</button>
</div>
#bottom{
background-repeat: repeat-x;
height:121px;
width: 984px;
margin-left: 20px;
margin-top: 13px;
}
#bottom .content{
width: 182px; /*328 co je 1/3 - 20margin left*/
height: 121px;
line-height: 20px;
margin-top: 0px;
margin-left: 9px;
margin-right:0px;
display:inline-block;
position:relative;
}
<div id="bottom">
<div class="content">
<img src="http://placehold.it/182x121"/>
<button>Text</button>
</div>
</div>
May be you are trying to achieve something like this.
.userIcon {
background: url('https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png') no-repeat;
height:20px;
width:20px;
background-size:20px;
top: 8px;
}
.left {
float:left;
}
.right {
float:right;
}
.clear{
clear:both;
}
.button{
padding:10px;
color: #FFF;
background-color: #0095ff;
border:1px solid #07c;
box-shadow: inset 0 1px 0 #66bfff;
}
.btnText{
margin:2px 0px 0px 10px;
}
<div>
<button class="button">
<span class="left userIcon"></span>
<span class="right btnText">Create user account</span>
<span class="clear"></span>
</button>
</div>
If you just want to make the image to come over the button, you can make the display as block
check the following snippet
div img{
display:block;
}
button{
text-align:center;
margin:40px;
padding:10px;
}
<div>
<img src="https://cdn1.iconfinder.com/data/icons/user-pictures/100/male3-128.png">
<button>Text</button>
</div>
Hope this helps
I have the code which got me three circles connected by two lines. Have a look here: JSFIDDLE
Here is my code:
HTML
<div class="form-group">
<div class="col-md-4"></div>
<div class="col-md-4">
<div class="circle" style="float:left;"></div>
<div id="horizontal" style="float:left;"></div>
<div class="circle" style="float: right;"></div>
<div id="horizontal" style="float: right;"></div>
<div class="circle"></div>
</div>
<div class="col-md-4"></div>
</div>
</div>
CSS
#horizontal
{
width: 230px;
border-bottom: 2px solid #CCCCCC;
padding-top: 6px;
}
.circle {
background: #CCCCCC;
width: 15px;
height: 15px;
border-radius: 50%;
border:1px solid #CCCCCC;
}
But this wont be responsive as i am setting width component to it. Is there anyway i can make it responsive using twitter bootstrap.
Using #media queries wont help for this case. Any help will be appreciated.
For info:
You could use a background-image or gradient too : DEMO
CSS revisited
.form-group {
background:linear-gradient(to top,#cccccc,#cccccc) repeat-x center;/* gradient can be replace for a 1pixel gray image */
background-size:2px 2px;
min-width:50px;/* keep those 3 15px boxes on one line */
}
.circle {
background: #CCCCCC;
width: 15px;
height: 15px;
border-radius: 50%;
border:1px solid #CCCCCC;
margin:auto;
}
& less HTML
<div class="form-group">
<div class="circle" style="float:left"></div>
<div class="circle" style="float: right;"></div>
<div class="circle"></div>
</div>
The simplest solution contains two divs and two pseudo elements. position: absolute keeps the circles over the parents border and position: relative keeps the circles positioned relative to the parent.
Have an example!
HTML
<div class="parent"><div class="child"></div></div>
CSS
* {
margin:0;
padding:0;
}
.parent {
margin:100px 0 0;
width:100%;
border-bottom:2px solid #CCC;
position:relative;
z-index:-1;
}
.parent:before,.parent:after,.child {
background:#CCC;
width:15px;
height:15px;
border-radius:50%;
border:1px solid #CCC;
position:absolute;
content:'';
top:-8px;
}
.parent:before {
left:0;
}
.parent:after {
right:0;
}
.child {
left:50%;
margin-left:-8px;
}
Try this:
html:
<div class="responsive-circle"><i></i></div>
css:
.responsive-circle {
height: 2px;
background-color: #CCC;
overflow: visible;
position: relative;
}
.responsive-circle:before,
.responsive-circle:after,
.responsive-circle > i {
background: #CCCCCC;
width: 15px;
height: 15px;
border-radius: 50%;
border:1px solid #CCCCCC;
position: absolute;
content: "";
top: -7px;
}
.responsive-circle:after {
right: 0;
}
.responsive-circle > i {
left: 50%;
left: calc(50% - 9px);
}
demo: http://jsfiddle.net/m787ydjz/
So I have this template design that is currently absolutely positioned, but I'm trying to make it centered in any widescreen browser. I've tried making the width auto on the left and right side in my container, but it is still aligned with the left side.
Css
.JosephSettin_png
{
position: absolute;
left:0px;
top:0px;
width:216px;
height:40px;
background: url("JosephSettin.png") no-repeat;
}
.home_png
{
position: absolute;
left:472px;
top:16px;
width:48px;
height:16px;
}
.discography_png
{
position: absolute;
left:528px;
top:16px;
width:80px;
height:24px;
}
.purchase_png
{
position: absolute;
left:608px;
top:16px;
width:88px;
height:24px;
}
.about_png
{
position: absolute;
left:696px;
top:16px;
width:48px;
height:24px;
}
.contact_png
{
position: absolute;
left:744px;
top:16px;
width:56px;
height:24px;
}
.main__pic_png
{
position: absolute;
left:0px;
top:56px;
width:264px;
height:264px;
background: url("main_pic.png") no-repeat;
}
.footer__lines_png
{
position: absolute;
left:0px;
top:512px;
width:800px;
height:24px;
background: url("footer_lines.png") no-repeat;
}
.info__heading_png
{
position: absolute;
left:32px;
top:360px;
width:216px;
height:32px;
background: url("info_heading.png") no-repeat;
}
.info__pic3_png
{
position: absolute;
left:265px;
top:360px;
width:159px;
height:112px;
background: url("info_pic3.png") no-repeat;
}
.info__pic2_png
{
position: absolute;
left:432px;
top:360px;
width:176px;
height:112px;
background: url("info_pic2.png") no-repeat;
}
.info__pic1_png
{
position: absolute;
left:616px;
top:360px;
width:177px;
height:112px;
background: url("info_pic1.png") no-repeat;
}
.info__pane_png
{
position: absolute;
left:0px;
top:345px;
width:800px;
height:144px;
background: url("info_pane.png") no-repeat;
}
body
{
text-align: center;
background-color:maroon;
}
#wrapper {
width: 800px;
margin-left: auto;
margin-right: auto;
text-align: left;
}
#a {
text-decoration: none;
color:white;
font-weight:bold;
}
.style1 {
font-weight: bold;
color: #FFFFFF;
}
html
<body>
<center>
<div id="wrapper">
<div class="JosephSettin_png"> </div>
<div class="home_png"> Home</div>
<div class="discography_png"> Discography</div>
<div class="purchase_png"><span class="style1">Store</span></div>
<div class="about_png">About</div>
<div class="contact_png"><span class="style1"></span>Contact</div>
<div class="ad_png"> </div>
<div class="main__pic_png"> </div>
<div class="welcome__header_png"> </div>
<div class="welcome__text_png"> </div>
<div class="footer__lines_png"> </div>
<div class="footer__text_png"> </div>
<div class="info__pane_png"></div>
<div class="info__heading_png"> </div>
<div class="info__text_png"> </div>
<div class="info__pic3_png"> </div>
<div class="info__pic2_png"> </div>
<div class="info__pic1_png"> </div>
<div class="info__pic3_png"> </div>
</div>
</center>
</body>
I know the container I create works if all my div classes aren't absolutely positioned. Do I have to change the position or did I make another error?
Add position: relative; to the .wrapper definition.
http://www.w3.org/TR/CSS2/visuren.html#choose-position
An absolutely positioned item must be inside of a relatively positioned item, or it will not display as you intended.
Your main problem is that your wrapper needs to be position:relative; and margin:0 auto; will center the wrapper. also you can get rid of you HTML element its not needed.
CSS:
#wrapper {
position:relative;
width: 800px;
margin:0 auto;
text-align: left;
}
Hope this helps.
I strongly suggest using a CSS framework like "Blueprint CSS". It'll save you a lot of time and helps not just with positioning of elements but comes with a lot of nice features like typography, css reset for multi-browser support, etc.