I'd like to center three boxes like this: https://drive.google.com/file/d/0B4gPO2Q50KsZcGxrbGEySFV5eU0/view?usp=sharing
What I want to achieve is to show the boxes one over the another in mobile devices but I do not know how to do so.
I am using this code:
div#alex_box {
border: solid 1px #aaa;
overflow: hidden;
}
div.img_home {
margin: 5px;
padding: 5px;
border: 1px solid #0000ff;
height: auto;
width: auto;
float: left;
text-align: center;
}
div.img_home img {
display: inline;
margin: 5px;
border: 1px solid #ffffff;
}
div.img_home a:hover img {
border: 1px solid #0000ff;
}
div.img_desc_home {
text-align: center;
font-weight: normal;
width: 120px;
margin: 5px;
}
<div id="alex_box">
<div class="img_home">
<a target="_blank" href=""><img src="http://dev.lifeonbikes.com/wp-content/uploads/2015/01/depositphotos_18467679-Travel-car-illustration.jpg" alt="primera imagen"></a>
<div class="img_desc_home">Texto primera imagen</div>
</div>
<div class="img_home">
<a target="_blank" href=""><img src="http://dev.lifeonbikes.com/wp-content/uploads/2015/01/images.jpg" alt="segunda imagen"></a>
<div class="img_desc_home">Texto segunda imagen</div>
</div>
<div class="img_home">
<a target="_blank" href=""><img src="http://dev.lifeonbikes.com/wp-content/uploads/2015/01/bus-icon120413.png" alt="tercera imagen"></a>
<div class="img_desc_home">Texto tercera imagen</div>
</div>
</div>
Try this zoom out and in to see the change Fiddle
#media screen and (max-width: 2000px) and (min-width: 300px){
img {
height:100px;
}
div#alex_box {
border: solid 1px #aaa;
overflow: hidden;
}
div.img_home {
margin: 5px;
padding: 5px;
border: 1px solid #0000ff;
height: auto;
width: auto;
float: left;
text-align: center;
}
div.img_home img {
display: inline;
margin: 5px;
border: 1px solid #ffffff;
}
div.img_home a:hover img {
border: 1px solid #0000ff;
}
div.img_desc_home {
text-align: center;
font-weight: normal;
width: 120px;
margin: 5px;
}
}
<div id="container">
<div id="alex_box">
<div class="img_home"> <a target="_blank" href=""><img src="http://dev.lifeonbikes.com/wp-content/uploads/2015/01/depositphotos_18467679-Travel-car-illustration.jpg" alt="primera imagen"></a>
<div class="img_desc_home">Texto primera imagen</div>
</div>
<div class="img_home"> <a target="_blank" href=""><img src="http://dev.lifeonbikes.com/wp-content/uploads/2015/01/images.jpg" alt="segunda imagen"></a>
<div class="img_desc_home">Texto segunda imagen</div>
</div>
<div class="img_home"> <a target="_blank" href=""><img src="http://dev.lifeonbikes.com/wp-content/uploads/2015/01/bus-icon120413.png" alt="tercera imagen"></a>
<div class="img_desc_home">Texto tercera imagen</div>
</div>
</div>
</div>
You can achieve it using margin-left: auto;margin-right: auto; within your parent div :
div#alex_box {
border: solid 1px #aaa;
margin-left: auto;
margin-right: auto;
overflow: hidden;
padding:10px;
display:table;
}
I also added display:table; to the parent div and display:table-cell; for each child div, and it works fine and it's responsive too.
This is the working Fiddle.
EDIT:
To separate boxes with spaces you just need to add margin:5px; to their CSS: Take a look at this Fiddle.
Related
I have some panels for recipes which have a photo and a title, but the title is too long and I need it to be that size. But word-break: break-word; isn't working. This is what I mean:
This is my code:
<div class="recipe-container">
<div class="recipe-window">
<img src="https://images.immediate.co.uk/production/volatile/sites/30/2020/08/millionaires-shortbread-52587dd.jpg?quality=90&webp=true&resize=300,272">
<p class="recipe-title">Millionare's Shortbread</p>
</div>
<div class="recipe-window">
<img src="https://images.immediate.co.uk/production/volatile/sites/30/2020/08/recipe-image-legacy-id-559666_11-b53071d.jpg?quality=90&webp=true&resize=300,272">
</div>
</div>
.recipe-container {
margin: 0px;
padding: 10px;
display: inline-flex;
}
.recipe-window {
margin: 10px;
padding: 10px;
border: 1px solid #ffffff;
background-color: #ffffff;
word-break: break-word;
width: auto;
}
.recipe-title {
color: black;
margin-top: 5px;
padding: 0px;
font-size: 40px;
}
How can I fix this?
You need to set the width of .recipe-window to min-content.
.recipe-container {
margin: 0px;
padding: 10px;
display: inline-flex;
}
.recipe-window {
margin: 10px;
padding: 10px;
border: 1px solid #ffffff;
background-color: #ffffff;
word-break: break-word;
width: min-content;
}
.recipe-title {
color: black;
margin: 0;
margin-top: 5px;
font-size: 40px;
}
<div class="recipe-container">
<div class="recipe-window">
<a href="https://www.bbcgoodfood.com/recipes/easy-millionaires-shortbread">
<img src="https://images.immediate.co.uk/production/volatile/sites/30/2020/08/millionaires-shortbread-52587dd.jpg?quality=90&webp=true&resize=300,272" />
</a>
<p class="recipe-title">Millionare's Shortbread</p>
</div>
<div class="recipe-window">
<a href="https://www.bbcgoodfood.com/recipes/classic-white-loaf">
<img src="https://images.immediate.co.uk/production/volatile/sites/30/2020/08/recipe-image-legacy-id-559666_11-b53071d.jpg?quality=90&webp=true&resize=300,272" />
</a>
</div>
</div>
.recipe-container {
margin: 0px;
padding: 10px;
display: inline-flex;
flex-wrap: wrap;
}
.recipe-window {
margin: 10px;
padding: 10px;
border: 1px solid #ffffff;
background-color: #ffffff;
width: 300px;
}
.recipe-title {
color: black;
margin-top: 5px;
padding: 0px;
font-size: 40px;
}
<div class="recipe-container">
<div class="recipe-window">
<a href="https://www.bbcgoodfood.com/recipes/easy-millionaires-shortbread">
<img
src="https://images.immediate.co.uk/production/volatile/sites/30/2020/08/millionaires-shortbread-52587dd.jpg?quality=90&webp=true&resize=300,272">
</a>
<p class="recipe-title">Millionare's Shortbread</p>
</div>
<div class="recipe-window">
<a href="https://www.bbcgoodfood.com/recipes/classic-white-loaf">
<img
src="https://images.immediate.co.uk/production/volatile/sites/30/2020/08/recipe-image-legacy-id-559666_11-b53071d.jpg?quality=90&webp=true&resize=300,272">
</a>
</div>
</div>
I'm using html and css to make 3 boxes act as links, equally spaced apart. For some reason when I got the divs to be equally spaced, a line was created between all three, acting as a link to the div left of the line.
Why is the line there?
here is the code: (with some stuff taken out)
.divider{
text-align: center;
}
.image{
float:left;
}
#javatut, #frgames, #scratchtut{
display: inline-block;
zoom: 2.0;
background-color: #c0c0c0;
text-align: center;
padding: 10px;
width: 20%;
}
#javatut {
border: 2px solid #ff8300;
}
#frgames {
border: 2px solid #0000ff;
}
#scratchtut {
border: 2px solid #ff8300;
}
#container {
text-align: justify;
}
.stretch {
width: 100%;
display: inline-block;
}
<div id="container">
<a href="url">
<div id="javatut">
<!-- stuff in here -->
</div>
</a>
<a href="url">
<div id="frgames">
<!-- stuff in here -->
</div>
</a>
<a href="url">
<div id="scratchtut">
<!-- stuff in here -->
</div>
</a>
<span class="stretch"></span>
</div>
This line is caused by the browsers default styling of links as underlined. Just set text-decoration: none; on your links and the line will be invisible.
a {
text-decoration: none;
}
.divider {
text-align: center;
}
.image {
float: left;
}
#javatut,
#frgames,
#scratchtut {
display: inline-block;
zoom: 2.0;
background-color: #c0c0c0;
text-align: center;
padding: 10px;
width: 20%;
}
#javatut {
border: 2px solid #ff8300;
}
#frgames {
border: 2px solid #0000ff;
}
#scratchtut {
border: 2px solid #ff8300;
}
#container {
text-align: justify;
}
.stretch {
width: 100%;
display: inline-block;
}
<div id="container">
<a href="url">
<div id="javatut">
<!-- stuff in here -->
</div>
</a>
<a href="url">
<div id="frgames">
<!-- stuff in here -->
</div>
</a>
<a href="url">
<div id="scratchtut">
<!-- stuff in here -->
</div>
</a>
<span class="stretch"></span>
</div>
It's because text-decoration CSS property. Set to none, and it works.
#container a {
text-decoration: none;
}
Your markup is not right
Make your a tags inside the div, all your styles will work correctly
check this
.divider {
text-align: center;
}
.image {
float: left;
}
#javatut,
#frgames,
#scratchtut {
display: inline-block;
zoom: 2.0;
background-color: #c0c0c0;
text-align: center;
padding: 10px;
width: 20%;
}
#javatut {
border: 2px solid #ff8300;
}
#frgames {
border: 2px solid #0000ff;
}
#scratchtut {
border: 2px solid #ff8300;
}
#container {
text-align: justify;
}
.stretch {
width: 100%;
display: inline-block;
}
<div id="container">
<div id="javatut">
<a href="url">
</a>
</div>
<div id="frgames">
<!-- stuff in here -->
<a href="url">
</a>
</div>
<div id="scratchtut">
<!-- stuff in here -->
</div>
<span class="stretch"></span>
</div>
Hope this helps
You can also do using flexbox for this
How do I put these <a>'s in the center of the div, next to each other with 40px of space in between them inside of a 100% width div?
a.explore {
padding: 15px 20px;
text-decoration: none;
text-align: center;
border: 1px solid #4f96b6;
font-size: 20px;
}
#container {
width: 100%;
}
<div id="container">
<a class="explore" href="#" target="_blank">I'm Ready To Go</a>
<a class="explore" href="#" target="_blank">Take Me Somewhere</a>
</div>
You can do this by using display:flex and justify-content:center on #container
a.explore {
padding: 15px 20px;
text-decoration: none;
text-align: center;
border: 1px solid #4f96b6;
font-size: 20px;
}
a.explore:first-child {
margin-right:40px;
}
#container {
width: 100%;
display:flex;
justify-content: center;
}
<div id="container">
<a class="explore" href="#" target="_blank">I'm Ready To Go</a>
<a class="explore" href="#" target="_blank">Take Me Somewhere</a>
</div>
These aren't buttons...they're links...there's a difference.
However, flexbox is ideal here:
a.explore {
padding: 15px 20px;
text-decoration: none;
text-align: center;
border: 1px solid #4f96b6;
font-size: 20px;
}
#container {
width: 100%;
display: flex;
justify-content: center;
padding: 1em;
background: #c0ffee;
}
a:first-child {
margin-right: 20px;
}
a:last-child {
margin-left: 20px;
}
<div id="container">
<a class="explore" href="#" target="_blank">I'm Ready To Go</a>
<a class="explore" href="#" target="_blank">Take Me Somewhere</a>
</div>
So I got a sketch of a designer I worked with and was wondering how I create the border arrows in the picture below
I tried to put out this font-awesome icon by using the :after selector, it got pretty ugly:
http://fortawesome.github.io/Font-Awesome/icon/angle-right/
So instead, I tried to put an arrow on an arrow through this arrow generator:
http://apps.eky.hk/css-triangle-generator/
It also became very ugly. So now I wonder if there is anyone who has a good idea on how to solve this?
How my html look like so far:
<div class="bx-pager bx-default-pager">
<div class="bx-pager-item">
<a class="bx-pager-link active" data-slide-index="0" href=""> 1. DIN EXPERT </a>
</div>
<div class="bx-pager-item">
<a class="bx-pager-link" data-slide-index="1" href=""> 2. VÅRA TJÄNSTER </a>
</div>
<div class="bx-pager-item">
<a class="bx-pager-link" data-slide-index="2" href=""> 3. CASE </a>
</div>
<div class="bx-pager-item">
<a class="bx-pager-link" data-slide-index="3" href=""> 4. KONTAKT </a>
</div>
</div>
You can create triangles with CSS borders by:
border-top: 20px solid transparent;
border-bottom: 20px solid transparent; /* 40px height (20+20) */
border-left: 20px solid green
I've created the same thing as you see above here:
#container {
width:150px;
height:40px;
background-color:green;
position:relative;
}
.arrow-right {
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent; /* 40px height (20+20) */
border-left: 20px solid green;
position:absolute;
right:-20px;
}
<div id="container">
<div class="arrow-right"></div>
</div>
Atlast!! :)
div.main {
margin-right:30px;
}
ol > li {
display: table-cell;
height: 30px;
position: relative;
padding: 0px;
margin: 0px;
text-align: center;
border: 1px solid #d68a3a;
}
ol > li > div {
position:relative;
line-height: 30px; /* equal to the list item's height */
height:100%;
width: 100%;
}
ol>li:hover {
background-color: #d68a3a;
cursor: pointer;
color: white;
}
ol {
display: table;
width: 100%;
padding: 0px;
margin: 0px;
position: relative;
}
ol > li > div:after, ol > li > div:before {
content:"";
display:inline-block;
border-width: 16px;
border-style: solid;
width: 0px;
height: 0px;
left: 100%;
top: -1px;
position: absolute;
z-index: 1;
}
ol > li > div:after, ol > li:hover > div:before {
border-color: transparent transparent transparent #d68a3a;
}
ol > li > div:before {
border-width: 14px;
display: block;
border-color: transparent transparent transparent #ffffff;
z-index: 2;
top:1px;
}
Working Fiddle
You have to make little bit changes to your html structure
Put active class at bx-pager-item element level
Put 1 extra element after anchor tag .
Please refer below code snippet.
Working fiddle link: Fiddle
.container {
max-width: 700px;
margin: auto;
}
.bx-pager {
display: flex;
align-items: center;
height: 34px;
border-left: 1px solid #d68a3a;
}
.bx-pager .bx-pager-item {
display: flex;
align-items: center;
height: 100%;
flex: 0 25%;
border-top: 1px solid #d68a3a;
border-bottom: 1px solid #d68a3a;
}
.bx-pager .bx-pager-item .bx-pager-link {
text-decoration: none;
color: #222;
font-size: 13px;
flex: 1;
padding-left: 16px;
text-align: center;
}
.bx-pager .bx-pager-item .arrow {
border: solid #d68a3a;
display: inline-block;
padding: 9px;
border-width: 0 1px 1px 0;
transform: translateY(15.5px) rotate(-45deg) skew(-15deg, -15deg) translateX(18px);
background-color: #FFF;
}
.bx-pager .bx-pager-item.active {
background-color: #d68a3a;
}
.bx-pager .bx-pager-item.active .bx-pager-link {
color: white;
}
.bx-pager .bx-pager-item.active .arrow {
background-color: #d68a3a;
}
<body>
<div class="container">
<div class="bx-pager bx-default-pager">
<div class="bx-pager-item active">
<a class="bx-pager-link " data-slide-index="0" href=""> 1. DIN EXPERT </a>
<div class="arrow">
</div>
</div>
<div class="bx-pager-item">
<a class="bx-pager-link" data-slide-index="1" href=""> 2. VÅRA TJÄNSTER </a>
<div class="arrow">
</div>
</div>
<div class="bx-pager-item">
<a class="bx-pager-link" data-slide-index="2" href=""> 3. CASE </a>
<div class="arrow">
</div>
</div>
<div class="bx-pager-item">
<a class="bx-pager-link" data-slide-index="3" href=""> 4. KONTAKT </a>
<div class="arrow">
</div>
</div>
</div>
</div>
</body>
Please Change according to your specification.
<style>
.menu {
position: relative;
background: #88b7d5;
width:150px;
height:60px;
}
.menu:after, .menu:before {
left: 100%;
top: 50%;
border: solid transparent;
content: " ";
height: 0px;
width: 0px;
position: absolute;
pointer-events: none;
}
.menu:after {
border-color: rgba(136, 183, 213, 0);
border-left-color: #88b7d5;
border-width: 30px;
margin-top: -30px;
}
</style>
<div class="menu">
</div>
In case it is needed for others here is another solution, that can work as the requested answer, but will work if there is a need of separation of the elements.
Using the above examples, what will happen is that the background must always remain the same color. Like this it will always have a separation thus transparency between items.
Hope this helps, this post really helped me to find this solution :)
.items--container {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.item {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
margin-left: 1rem;
width: 150px;
height: 50px;
}
.item.active .content {
color: #FFFFFF;
}
.item.active .arrow {
background: #d68a3a;
}
.content {
color: #000000;
position: absolute;
z-index: 2;
}
.arrow {
width: 100%;
height: 50%;
background: #FFFFFF;
}
.arrow.top {
transform: skew(45deg, 0deg);
border-left: 1px solid #d68a3a;
border-right: 1px solid #d68a3a;
border-top: 1px solid #d68a3a;
}
.arrow.bottom {
transform: skew(-45deg, 0deg);
border-left: 1px solid #d68a3a;
border-right: 1px solid #d68a3a;
border-bottom: 1px solid #d68a3a;
}
<div class="items--container">
<div class='item'>
<div class="arrow top"></div>
<div class="content">Menu Item 1</div>
<div class="arrow bottom"></div>
</div>
<div class='item'>
<div class="arrow top"></div>
<div class="content">Menu Item 2</div>
<div class="arrow bottom"></div>
</div>
<div class='item active'>
<div class="arrow top"></div>
<div class="content">Menu Item 3</div>
<div class="arrow bottom"></div>
</div>
<div class='item'>
<div class="arrow top"></div>
<div class="content">Menu Item 4</div>
<div class="arrow bottom"></div>
</div>
</div>
I'm currently working on some web coursework and as you'll notice I lack experience in web development. Basically I'm trying to create tables that hold products for a shop, however I want to use div tree's for the most part and if necessary forms for the text.
Essentially I want each independent table to hold an image, a description and eventually other data implemented with JS (I don't need help with this.. yet ^^). Hopefully you'll see what I'm trying to do from the code;
<div id="items">
<div id="item1" class="items">
<img src="img/products/robot1.jpg"/>
</div>
<div id="item2" class="items">
<img src="img/products/robot2.jpg"/>
</div>
<div id="item3" class="items">
<img src="img/products/robot3.jpg"/>
</div>
</div>
#content {
width: 600px;
padding-top: 10px;
padding-bottom: 30px;
margin-left: auto;
margin-right: auto;
}
.items{
display:inline;
}
#items {
padding-top:10px;
}
#items img{
border: 1px solid rgba(207, 207, 207, .7);
border-radius:20px;
}
The div's are parented by the 'content' container which is 600px wide, each table would have to be roughly 193px wide to fit three "products" on a row taking margins into consideration.
I drew a quick picture to represent exactly what I'm aiming for (the 'button' represents the 'add to basket' feature).
Unfortunately I can't use any frameworks such as jquery for the task so I'm stuck doing things the hard way. Apologies in advance for my lack of experience but hopefully you can put me in the right direction.
Edit: Using div's is just a preference, if it would be easier to use standalone forms I wouldn't mind.
Maybe this will point you in the right direction.
HTML:
<div id="content" class="clearfix">
<div id="items">
<div id="item1" class="items">
<img src="img/products/robot1.jpg"/>
Add
</div>
<div id="item2" class="items">
<img src="img/products/robot2.jpg"/>
Add
</div>
<div id="item3" class="items">
<img src="img/products/robot3.jpg"/>
Add
</div>
</div>
</div>
CSS:
.clearfix { *zoom: 1; }
.clearfix:before, .clearfix:after { content: ""; display: table; }
.clearfix:after { clear: both; }
#content {
width: 600px;
padding-top: 10px;
padding-bottom: 30px;
margin-left: auto;
margin-right: auto;
background:red;
}
.items{
float:left;
width:193px;
min-height:100px;
border:1px solid black;
position:relative;
}
.items a.add-basket {
position:absolute;
bottom:0;
right:0;
background:black;
color:#fff;
}
#item1 { margin-right:7px; }
#item2 { margin-right:7px; }
#items {
padding-top:10px;
}
#items img {
border: 1px solid rgba(207, 207, 207, .7);
border-radius:20px;
}
http://jsfiddle.net/DNS8P/1/
Here's a FIDDLE by the image you provide.
<div id="content">
<h1>Products</h1>
<div id="items">
<div id="item1" class="items">
<img src="img/products/robot1.jpg"/>
<span class="desc">Description</span>
<span class="price">$100</span>
<span class="other">Other</span>
<button>BUY</button>
</div>
<div id="item2" class="items">
<img src="img/products/robot2.jpg"/>
<span class="desc">Description</span>
<span class="price">$100</span>
<span class="other">Other</span>
<button>BUY</button>
</div>
<div id="item3" class="items">
<img src="img/products/robot3.jpg"/>
<span class="desc">Description</span>
<span class="price">$100</span>
<span class="other">Other</span>
<button>BUY</button>
</div>
</div>
</div>
#content {
width: 600px;
padding: 10px 10px 30px 10px;
margin: 30px auto;
text-align: center;
border: 1px solid #999;
}
#items {
padding-top:10px;
}
.items{
display: inline-block;
text-align: center;
width: 180px;
margin: 0 7px 0 7px;
padding-top: 10px;
border: 1px solid #999;
border-radius: 20px;
}
.items img {
width: 160px;
height: 140px;
border: 1px solid rgba(207, 207, 207, .7);
}
.items button {
background: #666;
width: 80px;
height: 26px;
float: right;
border-top: 1px solid #999;
border-left: 1px solid #999;
border-right: none;
border-bottom: none;
outline: none;
cursor: pointer;
border-bottom-right-radius: 20px;
transition: background 0.2s ease-in;
}
.items button:hover {
background: #888;
}
.desc,
.price,
.other {
display: block;
margin-bottom: 10px;
}