i created a responsive rectangle and a responsive triangle with css only.
How can i align the triangle so it is always vertically centered on the right side of the box?
I´d like to do it just with css but if it is not possible i appreciate any hint for alternative options.
HTML:
<div class="container">
<div class="box green rightbox">
<div class="innerbox">Lorem ipsum....</div>
</div>
<div class="mother-triangle">
<div class="triangle-right green"></div>
</div>
</div>
CSS:
.container {
max-width: 1200px;
margin-right: auto;
margin-left: auto;
z-index: 1;
position: relative;
}
.box {
height: auto!important;
min-height: 300px;
}
.box.green {
background-color: rgba(51, 223, 9, 0.75)!important;
}
.innerbox {
padding: 12px;
}
.triangle-right {
width: 0;
height: 0;
padding-top: 10%;
padding-bottom: 10%;
padding-left: 10%;
overflow: hidden;
position: relative;
margin-top: auto;
margin-bottom: auto;
display: inline-block;
vertical-align: middle;
}
.triangle-right:after {
content: "";
display: block;
width: 0;
height: 0;
margin-top: -500px;
margin-left: -500px;
border-top: 500px solid transparent;
border-bottom: 500px solid transparent;
border-left: 500px solid rgba(51, 223, 9, 0.75);
}
.rightbox {
width: 90%;
float: left;
}
JSFiddel demo:
You can use absolute positioning to do that.
Just change position: relative to position: absolute in .triangle-right.
Add top: 50% to move the triangle to the vertical middle.
Updated fiddle
.container {
max-width: 1200px;
margin-right: auto;
margin-left: auto;
z-index: 1;
position: relative;
}
.box {
height: auto!important;
min-height: 300px;
}
.box.green {
background-color: rgba(51, 223, 9, 0.75)!important;
}
.innerbox {
padding: 12px;
}
.triangle-right {
width: 0;
height: 0;
padding-top: 10%;
padding-bottom: 10%;
padding-left: 10%;
overflow: hidden;
position: absolute;
margin-top: auto;
margin-bottom: auto;
display: inline-block;
vertical-align: middle;
top: 50%;
}
.triangle-right:after {
position: absolute;
content: "";
display: block;
width: 0;
height: 0;
margin-top: -500px;
margin-left: -500px;
border-top: 500px solid transparent;
border-bottom: 500px solid transparent;
border-left: 500px solid rgba(51, 223, 9, 0.75);
}
.rightbox {
width: 90%;
float: left;
}
<!-----container start---->
<div class="container">
<div class="box green rightbox">
<div class="innerbox">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>
<div class="mother-triangle">
<div class="triangle-right green"></div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
<!-----container end ---->
Related
I have a problem with text-indent.
Here is the image what I want to make.
I don't want to use <li>.
I want to make custom list style.
Here is my code.
.dotted-style{
width: 200px;
word-break: break-all;
}
.dotted-style::before{
display: inline-block;
content: '';
width: 4px;
height: 4px;
background-color: gray;
border-radius: 100%;
margin: auto 5px;
vertical-align: middle;
}
<p class="dotted-style">Lorem ipsum dolor sit amet consectetur, adipisicing elit. Possimus aliquam non aspernatur reprehenderit, velit, laboriosam harum aut dolorum, quasi a iure maiores. Eos laboriosam exercitationem quasi magni doloribus fuga rerum?
</p>
Try this with margin:
CSS:
.dotted-style {
width: 200px;
word-break: break-all;
margin-left: 15px;/*added*/
}
.dotted-style::before {
display: inline-block;
content: '';
width: 4px;
height: 4px;
background-color: gray;
border-radius: 100%;
margin: auto 5px auto -10px;/*modified*/
vertical-align: middle;
}
Demo: http://jsfiddle.net/lotusgodkk/GCu2D/2189/
Try this:
.dotted-style{
width: 200px;
word-break: break-all;
position:relative;
padding-left:15px;
}
.dotted-style::before{
display: inline-block;
content: '';
width: 4px;
height: 4px;
background-color: gray;
border-radius: 100%;
margin: auto 5px;
vertical-align: middle;
position:absolute;
left:0;
top:10px;
}
Good day,
I'm not new to CSS or DIVs but have been out of touch for long enough. Trying to work out with Containers and nested DIVs but not getting much success in doing what I'm trying to do. Have already searched enough on SO and Goog but, hopefully you can help me.
Here's the representation of what I wish to achieve.
Screenshot of the layout
And here is what I have done so far ..
.dealsglobal {
width: 45%;
display: inline-block;
float: left;
margin-right:20px;
height: auto;
overflow: auto;
}
.dealsglobal h2 {
margin-left: 10px;
}
.dealsindia {
width: 45%;
height: auto;
overflow: auto;
}
.dealsindia h2 {
margin-left: 10px;
}
.dealsleft {
margin: 0px 25px 10px 0px;
padding: 5px;
border: 1px solid #ccc;
height: auto;
position: relative;
width: 40%;
float: left;
display: inline-block;
overflow: auto;
}
.dealsleft img {
border: 1px solid #ddd;
background: #fff;
border-radius: 4px;
margin-left: auto;
margin-right: auto;
width: 100px;
}
.dealsright {
margin-bottom: 10px;
padding: 5px;
border: 1px solid #ccc;
height: auto;
position: relative;
width: 40%;
display: inline-block;
overflow: auto;
}
<div class="dealsglobal">
<h2>Global Coupons</h2>
<div class="dealsleft">
<img src="thumb-heavengifts.jpg" alt="HeavenGifts.com Web Store" align="middle" />
</div>
<div class="dealsright">
Test
</div>
</div>
<div class="dealsindia">
<h2>Indian Coupons</h2>
<div class="dealsleft">
Test
</div>
<div class="dealsright">
Test
</div>
</div>
The image just wont center, no matter what I do. I believe, somewhere I have set the property to align left or something. Can anyone please point me to the correct direction? Thanks for your help!
I changed your code a little bit, but you'll get idea :
Here is html :
<div class="container">
<div class="left">
<h2 class="inner-text">title</h2>
<div class="image">
<img src="http://via.placeholder.com/350x150" />
</div>
<h5 class="inner-text">description</h5>
</div>
<div class="right">
<h2 class="inner-text">title</h2>
<div class="image">
<img src="http://via.placeholder.com/350x150" />
</div>
<h5 class="inner-text">description</h5>
</div>
<div style="clear: both" />
</div>
And here is the css:
.container{
width: 98%;
border: 2px solid #f00;
padding: 10px;
}
.left {
width: 47%;
float: left;
margin: 0 1% 0 1%;
border: 1px solid green;
}
.right {
width: 47%;
float: left;
margin: 0 1% 0 1%;
border: 1px solid green;
}
.inner-text{
text-align:center;
}
.image{
padding: 20px;
}
.image img{
max-width: 100%;
}
Check here jsfiddle.
You missed adding this css property:
.dealsleft {
text-align:center;
}
You can center elements inside a div by using text-align:center; for all the text elements like: h1, p, h2, a etc. To center an img or a div inside another div you can use margin: 0 auto; the auto is the important part for centering the left and right margins.
More info here
i've updated your code snippet.
.dealsglobal {
width: 45%;
display: inline-block;
float: left;
margin-right:20px;
height: auto;
overflow: auto;
}
.dealsglobal h2 {
margin-left: 10px;
}
.dealsindia {
width: 45%;
height: auto;
overflow: auto;
}
.dealsindia h2 {
margin-left: 10px;
}
.dealsleft {
margin: 0px 25px 10px 0px;
padding: 5px;
border: 1px solid #ccc;
height: auto;
position: relative;
width: 40%;
float: left;
display: inline-block;
overflow: auto;
text-align: center;
}
.dealsleft img {
border: 1px solid #ddd;
background: #fff;
border-radius: 4px;
margin: 5px auto;
width: 100px;
}
.dealsright {
margin-bottom: 10px;
padding: 5px;
border: 1px solid #ccc;
height: auto;
position: relative;
width: 40%;
display: inline-block;
overflow: auto;
text-align: center;
}
<div class="dealsglobal">
<h2>Global Coupons</h2>
<div class="dealsleft">
<img src="thumb-heavengifts.jpg" alt="HeavenGifts.com Web Store" align="middle" />
</div>
<div class="dealsright">
Test
</div>
</div>
<div class="dealsindia">
<h2>Indian Coupons</h2>
<div class="dealsleft">
Test
</div>
<div class="dealsright">
Test
</div>
</div>
I have added background colors for visualization purposes.
* {
box-sizing: border-box;
}
#container {
width: 100%;
padding: 10px;
background-color: red;
display: flex;
justify-content: space-between;
}
.subcontainer-outer {
width: 49%;
background-color: green;
}
.subcontainer {
width: 100%;
background-color: blue;
display: flex;
justify-content: space-between;
}
.content {
width: 45%;
text-align: center;
background-color: yellow;
}
<h3>Container</h3>
<div id="container">
<div class="subcontainer-outer">
<h4>Sub container 1</h4>
<div class="subcontainer">
<div class="content">
<img src="http://placehold.it/100" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="content">
<img src="http://placehold.it/100" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
<div class="subcontainer-outer">
<h4>Sub container 2</h4>
<div class="subcontainer">
<div class="content">
<img src="http://placehold.it/100" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div class="content">
<img src="http://placehold.it/100" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
</div>
You can get it by using flex below an example as your requirement.
.dealsglobal {
width: 48%;
margin-right: 10px;
height: auto;
float: left;
}
.flex {
display: flex;
justify-content: flex-start;
align-items: center;
flex-flow: row nowrap;
border: 1px solid red;
padding: 10px;
}
.dealsglobal h2 {
margin-left: 10px;
}
.dealsindia h2 {
margin-left: 10px;
}
.dealsleft {
margin: 0px 25px 10px 0px;
padding: 5px;
border: 1px solid #ccc;
flex: 1 0 0;
align-self: flex-start;
}
.dealsleft img {
border: 1px solid #ddd;
background: #fff;
border-radius: 4px;
margin-left: auto;
margin-right: auto;
width: 100%;
}
.dealsright {
margin-bottom: 10px;
padding: 5px;
border: 1px solid #ccc;
overflow: auto;
flex: 1 0 0;
align-self: flex-start;
}
<div class="dealsglobal">
<h2>Global Coupons</h2>
<div class="flex">
<div class="dealsleft">
<img src="http://lorempixel.com/400/200/sports/" alt="HeavenGifts.com Web Store" align="middle" />
</div>
<div class="dealsright">
Test
</div>
</div>
</div>
<div class="dealsglobal">
<h2>Global Coupons</h2>
<div class="flex">
<div class="dealsleft">
<img src="http://lorempixel.com/400/200/sports/" alt="HeavenGifts.com Web Store" align="middle" />
</div>
<div class="dealsright">
Test
</div>
</div>
</div>
Here is working fiddle
fiddle
You are probably looking for any of these 2:
parentSelector {
display: block; /* can also be an inline-block, with set width */
text-align: center;
}
childSelector {
width: 60%; /* generic. Change it */
display: block;
margin: 0 auto;
}
... or:
parentSelector {
display: flex;
flex-direction: column;
align-items: center;
}
childSelector {
max-width: 60%; /* optional. Change it.
* You don't need to set width here and,
* it's OK not to limit max-width, either
*/
}
I'm having trouble understanding why my images don't shrink when I shrink/resize my Chrome. Can someone explain and help me?
I have been trying for a while now but I can't seem to figure it out or find the answer elsewhere. The image shrinks in firefox running on my localhost, but not inside jsfiddle. Still not working in Chrome(57.0.2987.110).
<div class="page">
<div class="container">
<div class="title">
<H1>FLEXBOX PRACTICE</H1>
</div>
<div class="content">
<div class="text">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.</p>
</div>
<div class="images">
<img src="http://www.placebacon.net/1280/720" alt="Bacn">
</div>
</div>
</div>
body {
margin: 0;
}
p {
margin: 0;
padding: 0;
}
h1 {
font-size: 72px;
margin: 20px 0;
}
.page {
width: 100vw;
height: 100vh;
background-color: pink;
}
.container {
margin: 0 auto;
width: 80vw;
display: flex;
flex-direction: column;
align-items: center;
}
.content {
display: flex;
justify-content: space-between;
height: 80vh;
width: 60vw;
align-items: center;
background-color: salmon;
}
.text {
flex-grow: 0;
padding: 10px 20px 10px 20px;
background-color: red;
color: white;
border-radius: 10px;
width: 340px;
font-size: 24px;
font-family: verdana;
}
.images {
display: flex;
align-items: center;
flex-grow: 1;
flex-shrink: 1;
max-width: 600px;
width: 600px;
background-color: yellow;
}
.images img {
display: flex;
flex-grow: 1;
flex-shrink: 1;
max-width: inherit;
width: inherit;
}
https://jsfiddle.net/xb4obfce/
You're telling the image to inherit the width of its parent, which is at 600px.
Changing the .images class to width: 100%; should make it responsive.
Here is a top menu:
When browser width is < 1000px, I would like to :
Hide the 3 top-right <input> fields (I achieved it with display:none in the media query)
The "Post" button now becomes a button that opens a collapsible menu with the 3 input fields now displayed one after another in a new line, like this:
But I think this would require to completely change the DOM element order with CSS / media query. Is this possible / needed here?
How would you implement such top menu collapsible menu?
* { margin: 0; padding: 0; }
a { text-decoration: none; }
img { border: 0; }
body { overflow: hidden; height: 100%; font-family: arial; }
#header { border-bottom: 1px solid #dedede; height: 60px; margin: 0; display: -ms-flexbox; display: -webkit-flex; display: flex; }
#topleft { border-right: 1px solid #dedede; padding: 0px; float: left; -ms-flex: 0 0 155px; -webkit-flex: 0 0 155px; flex: 0 0 155px; height:100%; }
#topmid { border-right: 1px solid #dedede; float: left; -ms-flex: 0 0 40%; -webkit-flex: 0 0 40%; flex: 0 0 40%; height:100%; transition: all 0.3s ease-in-out; }
#topright { -ms-flex: 1; -webkit-flex: 1; flex: 1; position: relative; }
#logo { color: #ff0048; font-family: arial; font-size: 1.625em; font-weight: bold; padding-top: 14px; padding-left: 7px; }
#snif { margin-left: 0px; border: 0; margin-top: 22px; outline: 0px !important; width: calc(100% - 55px);}
#searchpng { background: #ffffff url("search.png") no-repeat left top; width: 40px; height: 30px; float:left; margin: 17 0 10 10px; }
.post { border: 1px solid #c4c4c4; padding: 5 2 5 10px; border-radius: 2px; }
#input1 { margin-left: 12px; width: calc(40% - 75px); position: relative; top:-7px; }
#input2 { margin-left: 0px; margin-top: 22px; width: calc(35% - 75px); position: relative; top:-7px; }
#input3 { width: calc(35% - 75px); position: relative; top:-7px; max-width: 230px;}
#deposer { background-color: #fb0149; color: white; padding: 6 10 5 10px; border-radius: 2px; position: relative; top:-7px; width: 65px; display: inline-block; text-align: center; margin-left: 5px; font-size: 0.875em; font-weight: bold; }
#spacer { max-width: 15px; width: calc(100% - 552px); display: inline-block; }
#media (max-width: 1000px) {
#topmid { -webkit-flex: 0 0 30%; -ms-flex: 0 0 30%; flex: 0 0 30%; }
body { overflow-y: scroll; }
}
<div id="header">
<div id="topleft" class="unselectable">
<div id="logo"><img src="logo.png" /></div>
</div>
<div id="topmid">
<div id="searchpng"></div>
<input type="text" placeholder="Lorem ipsum" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Lorem ipsum'" autocomplete="off" id="snif"></input>
</div>
<div id="topright" class="unselectable">
<input id="input1" class="post" type="textarea" placeholder="" autocomplete="off"/>
<input id="input2" class="post" type="textarea" placeholder="" autocomplete="off"/>
<input id="input3" class="post unselectable" placeholder="" value="" autocomplete="off"/>
Post
</div>
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
I would just change the position of the current menu on the media query for <1000px.
You could also create new html elements and set them to display:none until the media query is activated, and set them to display:block or whatever you wanted.
added html:
<div id="mobile-topright" class="unselectable">
<input id="input1" class="post" type="textarea" placeholder="" autocomplete="off"/></div>
<input id="input2" class="post" type="textarea" placeholder="" autocomplete="off"/>
<input id="input3" class="post unselectable" placeholder="" value="" autocomplete="off"/>
Post
</div>
added CSS:
#media (max-width: 1000px) {
#topmid { -webkit-flex: 0 0 30%; -ms-flex: 0 0 30%; flex: 0 0 30%; }
body { overflow-y: scroll; }
#topright {display:none;}
#mobile-topright {margin-top:5%;
}
#input1, #input2, #input3 {width:60%;
max-width:60%;
margin:0 auto;
padding:5px;}
}
I have checked several answers on this topic, but they are either not responsive or just don't work for me.
I have two columns and I would like the right one to always match the height of the left one. If there is too much content in the right column, make it scrollable. Is that possible?
I have one example for you (using table layout):
HTML:
<div class="row no-gutter">
<div class="row-same-height">
<div class="col-xs-6 col-xs-height">
<div class="content-left">
<img src="http://www.gettyimages.in/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" class="img-responsive">
</div>
</div>
<div class="col-xs-6 col-xs-height col-top">
<div class="content-right">
<div class="content-box">
<h2>Responsive two sections (equal height)</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
</div>
</div>
</div>
CSS:
.no-gutter.row {
margin-left: 0;
margin-right: 0;
}
.no-gutter > [class*="col-"],
.no-gutter .row-same-height > [class*="col-"] {
padding-right: 0;
padding-left: 0;
}
#media (min-width: 992px) {
.no-gutter-desktop.row {
margin-left: 0;
margin-right: 0;
}
.no-gutter-desktop > [class*="col-"],
.no-gutter .row-same-height > [class*="col-"] {
padding-right: 0;
padding-left: 0;
}
}
.inside {
margin-top: 20px;
margin-bottom: 20px;
background: #ededed;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f4f4f4), color-stop(100%, #ededed));
background: -moz-linear-gradient(top, #f4f4f4 0%, #ededed 100%);
background: -ms-linear-gradient(top, #f4f4f4 0%, #ededed 100%);
}
.inside-full-height {
height: 100%;
margin-top: 0;
margin-bottom: 0;
}
.content {
padding: 12px 3px;
}
.row-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-height {
display: table-cell;
float: none;
height: 100%;
}
.col-top {
vertical-align: top;
}
.col-middle {
vertical-align: middle;
}
.col-bottom {
vertical-align: bottom;
}
#media (min-width: 480px) {
.row-xs-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-xs-height {
display: table-cell;
float: none;
height: 100%;
}
.col-xs-top {
vertical-align: top;
}
.col-xs-middle {
vertical-align: middle;
}
.col-xs-bottom {
vertical-align: bottom;
}
}
#media (min-width: 768px) {
.row-sm-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-sm-height {
display: table-cell;
float: none;
height: 100%;
}
.col-sm-top {
vertical-align: top;
}
.col-sm-middle {
vertical-align: middle;
}
.col-sm-bottom {
vertical-align: bottom;
}
}
#media (min-width: 992px) {
.row-md-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-md-height {
display: table-cell;
float: none;
height: 100%;
}
.col-md-top {
vertical-align: top;
}
.col-md-middle {
vertical-align: middle;
}
.col-md-bottom {
vertical-align: bottom;
}
}
#media (min-width: 1200px) {
.row-lg-height {
display: table;
table-layout: fixed;
height: 100%;
width: 100%;
}
.col-lg-height {
display: table-cell;
float: none;
height: 100%;
}
.col-lg-top {
vertical-align: top;
}
.col-lg-middle {
vertical-align: middle;
}
.col-lg-bottom {
vertical-align: bottom;
}
}
[class*="col-"] {
background: #d6ec94;
}
.content-right {
overflow-y: auto;
}
JS:
var leftHeight = $('.content-left').height();
$('.right').css('max-height', leftHeight);
$(window).resize(function () {
var leftHeight = $('.content-left').height();
$('.content-right').css('max-height', leftHeight);
});
CODEPEN