This question already has answers here:
How do I center floated elements?
(12 answers)
Advantages of using display:inline-block vs float:left in CSS
(5 answers)
Closed 4 years ago.
So i wrote this code to be responsive and I wanted each picture horizontally and in smaller screens, it would go vertical. My only issue is that on larger screens I want the imgs to be centered but no code seems to work. I tried some solutions from Stack users but I can only get it to go either completely left or right but not centered.
Thank you for helping.
* {
box-sizing: border-box;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
max-width: 200px;
display: block;
margin: 15px auto;
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}
/* Responsive layout - makes the three columns stack on top of each other
instead of next to each other */
#media screen and (max-width: 500px) {
.column {
width: 100%;
}
}
<h2>Responsive "Side-by-Side" Images</h2>
<p>How to create side-by-side images with the CSS float property. On screens that are 500px wide or less, the images will stack on top of each other instead of next to each other:</p>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="column">
<img src="http://zoeaa.com/public/admin/starbucksoffer.png" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="http://zoeaa.com/public/admin/mysteryoffers.jpg" alt="Forest" style="width:100%">
</div>
<div class="column">
<img src="http://zoeaa.com/public/admin/targetoffers.png" alt="Mountains" style="width:100%">
</div>
<div class="column">
<img src="http://zoeaa.com/public/admin/starbucksoffer.png" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="http://zoeaa.com/public/admin/mysteryoffers.jpg" alt="Forest" style="width:100%">
</div>
</div>
It is easiest to use a flexbox. It is responsive by nature and keeps the document flow intact.
* {
box-sizing: border-box;
}
.row {
display: flex;
}
.column {
width: 33.33%;
padding: 5px;
max-width: 200px;
display: block;
margin: 15px auto;
}
/* Responsive layout - makes the three columns stack on top of each other
instead of next to each other */
#media screen and (max-width: 500px) {
.column {
width: 100%;
}
}
<h2>Responsive "Side-by-Side" Images</h2>
<p>How to create side-by-side images with the CSS float property. On screens that are 500px wide or less, the images will stack on top of each other instead of next to each other:</p>
<p>Resize the browser window to see the effect.</p>
<div class="row">
<div class="column">
<img src="http://zoeaa.com/public/admin/starbucksoffer.png" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="http://zoeaa.com/public/admin/mysteryoffers.jpg" alt="Forest" style="width:100%">
</div>
<div class="column">
<img src="http://zoeaa.com/public/admin/targetoffers.png" alt="Mountains" style="width:100%">
</div>
<div class="column">
<img src="http://zoeaa.com/public/admin/starbucksoffer.png" alt="Snow" style="width:100%">
</div>
<div class="column">
<img src="http://zoeaa.com/public/admin/mysteryoffers.jpg" alt="Forest" style="width:100%">
</div>
</div>
Related
I am creating a sample website which has three divisions horizontally.
I want the left most div to be 25% width, the middle one to be 50% width, and right to be 25% width so that the divisions fill all the 100% space horizontally.
<html>
<title>
Website Title
</title>
<div id="the whole thing" style="height:100%; width:100%" >
<div id="leftThing" style="position: relative; width:25%; background-color:blue;">
Left Side Menu
</div>
<div id="content" style="position: relative; width:50%; background-color:green;">
Random Content
</div>
<div id="rightThing" style="position: relative; width:25%; background-color:yellow;">
Right Side Menu
</div>
</div>
</html>
http://imgur.com/j4cJu
When I execute this code, the divs appear over each other. I want them to appear beside each other!
How can i do this?
I'd refrain from using floats for this sort of thing; I'd rather use inline-block.
Some more points to consider:
Inline styles are bad for maintainability
You shouldn't have spaces in selector names
You missed some important HTML tags, like <head> and <body>
You didn't include a doctype
Here's a better way to format your document:
<!DOCTYPE html>
<html>
<head>
<title>Website Title</title>
<style type="text/css">
* {margin: 0; padding: 0;}
#container {height: 100%; width:100%; font-size: 0;}
#left, #middle, #right {display: inline-block; *display: inline; zoom: 1; vertical-align: top; font-size: 12px;}
#left {width: 25%; background: blue;}
#middle {width: 50%; background: green;}
#right {width: 25%; background: yellow;}
</style>
</head>
<body>
<div id="container">
<div id="left">Left Side Menu</div>
<div id="middle">Random Content</div>
<div id="right">Right Side Menu</div>
</div>
</body>
</html>
Here's a jsFiddle for good measure.
I know this is a very old question. Just posting this here as I solved this problem using FlexBox. Here is the solution
#container {
height: 100%;
width: 100%;
display: flex;
}
#leftThing {
width: 25%;
background-color: blue;
}
#content {
width: 50%;
background-color: green;
}
#rightThing {
width: 25%;
background-color: yellow;
}
<div id="container">
<div id="leftThing">
Left Side Menu
</div>
<div id="content">
Random Content
</div>
<div id="rightThing">
Right Side Menu
</div>
</div>
Just had to add display:flex to the container! No floats required.
You can use floating elements like so:
<div id="the whole thing" style="height:100%; width:100%; overflow: hidden;">
<div id="leftThing" style="float: left; width:25%; background-color:blue;">Left Side Menu</div>
<div id="content" style="float: left; width:50%; background-color:green;">Random Content</div>
<div id="rightThing" style="float: left; width:25%; background-color:yellow;">Right Side Menu</div>
</div>
Note the overflow: hidden; on the parent container, this is to make the parent grow to have the same dimensions as the child elements (otherwise it will have a height of 0).
Easiest way
I can see the question is answered , I'm giving this answer for the ones who is having this question in future
It's not good practise to code inline css , and also ID for all inner div's , always try to use class for styling .Using inline css is a very bad practise if you are trying to be a professional web designer.
Here in your question
I have given a wrapper class for the parent div and all the inside div's are child div's in css you can call inner div's using nth-child selector.
I want to point few things here
Do not use inline css ( it is very bad practise )
Try to use classes instead of id's because if you give an id you can use it only once, but if you use a class you can use it many times and also you can style of them using that class so you write less code.
Codepen link for my answer
https://codepen.io/feizel/pen/JELGyB
.wrapper {
width: 100%;
}
.box {
float: left;
height: 100px;
}
.box:nth-child(1) {
width: 25%;
background-color: red;
}
.box:nth-child(2) {
width: 50%;
background-color: green;
}
.box:nth-child(3) {
width: 25%;
background-color: yellow;
}
<div class="wrapper">
<div class="box">
Left Side Menu
</div>
<div class="box">
Random Content
</div>
<div class="box">
Right Side Menu
</div>
</div>
You add a
float: left;
to the style of the 3 elements and make sure the parent container has
overflow: hidden; position: relative;
this makes sure the floats take up actual space.
<html>
<head>
<title>Website Title </title>
</head>
<body>
<div id="the-whole-thing" style="position: relative; overflow: hidden;">
<div id="leftThing" style="position: relative; width: 25%; background-color: blue; float: left;">
Left Side Menu
</div>
<div id="content" style="position: relative; width: 50%; background-color: green; float: left;">
Random Content
</div>
<div id="rightThing" style="position: relative; width: 25%; background-color: yellow; float: left;">
Right Side Menu
</div>
</div>
</body>
</html>
Also please note that the width: 100% and height: 100% need to be removed from the container, otherwise the 3rd block will wrap to a 2nd line.
Get rid of the position:relative; and replace it with float:left; and float:right;.
Example in jsfiddle: http://jsfiddle.net/d9fHP/1/
<html>
<title>
Website Title </title>
<div id="the whole thing" style="float:left; height:100%; width:100%">
<div id="leftThing" style="float:left; width:25%; background-color:blue;">
Left Side Menu
</div>
<div id="content" style="float:left; width:50%; background-color:green;">
Random Content
</div>
<div id="rightThing" style="float:right; width:25%; background-color:yellow;">
Right Side Menu
</div>
</div>
</html>
I'm trying to display the Instagram feed on a website, but the column breakpoint is not working.
When in a small device all the columns on the other sections stacks like they are supposed to, but for this part the feed part it is no stacking. They still side by side even in a small screen device.
I didn't do any customization for the bootstrap.
The custom css for the images is listed below.
I'm suspecting that my css is interfering with it somehow, but i didn't find a solution. Can you help me?
<div class="container">
<div class="row" id="instagram-feed">
{loop="$feed"}
<div class="col-md-4 col-sm-12 instagram-image">
<a
href="{$value.permalink}"
target="_blank"
style="background-image: url('{$value.media_url}')"
></a>
</div>
{/loop}
</div>
</div>
<div class="container">
<div class="row">
<div class="col-12 gallery-link" >
<p>
xpto
<a
href="https://www.instagram.com/xpto/"
target="_blank"
rel="noopener noreferrer"
>instagram</a
>
</p>
</div>
</div>
</div>
i'm using rain/tpl to loop the values.
Rendered result:
<div class="col-md-4 col-sm-12 instagram-image">
<a
href="https://www.instagram.com/p/Ce3K0vtqwWg/"
target="_blank"
rel="noopener"
style="
background-image: url('https://scontent-frx5-1.cdninstagram.com/v/t51.2885-15/288042510_360927436108874_1443195410220397807_n.jpg?_nc_cat=106&ccb=1-7&_nc_sid=8ae9d6&_nc_ohc=BcBzX46rui8AX9LhNfW&_nc_ht=scontent-frx5-1.cdninstagram.com&edm=ANQ71j8EAAAA&oh=00_AT-UQWOTJQXMvRivbpb7IAutNaT6D2_1ws1WdzhSNMARWA&oe=62B4FE5D');"
>
</a>
</div>
The css i added for this part:
.instagram-image a:before {
content: "";
display: flex;
font-family: "Font Awesome 5 Brands";
font-size: 50px;
color: var(--primary);
background-color: #73a2a9;
opacity: 0;
text-align: center;
transition: all 0.5s;
width: 100%;
height: 100%;
justify-content: center;
align-items: center;
}
.instagram-image a:hover:before {
opacity: 0.5;
}
#instagram-feed {
width: 100%;
float: left;
display: flex;
justify-content: space-around;
}
I use html2pdf to generate pdf with table data but I have some issue that I can't deal with. No matter how I set margins i always have some additional blank page at the end of pdf.
This is how looks like my pdf template :
<body>
<div class="page">
<div class="inner-page">
<div class="dealers-table">
<div class="head">
<div class="it">Lp.</div>
<div class="name">Name</div>
<div class="street">street</div>
<div class="post-code">Post Code</div>
<div class="city">City</div>
<div class="phone">Phone</div>
<div class="services">Services</div>
</div>
<div class="body">
<div>
<div class="it"></div>
<div class="name"></div>
<div class="street"></div>
<div class="post-code"></div>
<div class="city"></div>
<div class="phone"></div>
<div class="services"> /</div>
</div>
</div>
</div>
</div>
</div>
And css:
.page {
width: 210mm;
height: 280mm;
margin: 0 auto;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
position: relative;
}
.inner-page {
padding: 5mm 10mm;
}
.dealers-table {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
font-size: 6.5pt;
line-height: 1;
}
I don't set any margins in options of my Converter.
When I set page width less than 280px table from second page starts at the end of first page and additional blank page doesn't appear, in other situations there is always useless blank page.
How can I fix it?
EDIT 1
There is some code where I generate pdf on server side:
public function generatePdf() {
$autoDealers = $this->autoDealersOrServices(0);
(some function where i fetch array of dealers from my DB)
$autoDealers = view('pdf.template', [
'autoDealers' => $autoDealers
])->render();
$input = new StringInput();
$input->setHtml($view);
$converter = new Converter($input, new FileOutput());
$converter->setOption('landscape', false);
$converter->setOptions([
'printBackground' => true
]);
$output = $converter->convert();
$output->store('pdf/auto/dealers.pdf');
}
SyntaxEditor Code Snippet
"--encoding UTF-8 --page-size A4 --margin-left 10 --margin-right 10 --margin-top 20 --margin-bottom 0"
I need help with adjusting a certain html element <div class="content"> with css so that it will be fixed and responsive like this (https://i.imgur.com/vYsIUXy.jpg) on that position regardless of screen dimensions and not like this (https://i.imgur.com/qUHHI0q.jpg).
I change the width of #info #head>.content from 100% to 82% but on a smaller screen dimension it overlaps with the cover image.
HTML Code
Snippet
<div id="head">
<div class="content">
<div class="uigrid">
<div class="contingo">
<p style="font-size:30px;">Meng Qi Shi Shen</p>
<div class="horizontal-list">
Adventure
Comedy
Drama
Historical
Romance
Shoujo
<div class="type"><span class="sub" onclick="if (!window.__cfRLUnblockHandlers) return false; changegrid()">Sub</span><span class="dub" onclick="if (!window.__cfRLUnblockHandlers) return false; changegrid()">Dub</span></div> </div>
</div>
</div>
</div>
<div class="overlay"></div>
</div>
Full php(html) code
https://codeshare.io/arj6eA
CSS Code
https://codeshare.io/GbyP86
you can try to use max-width of device to adjust the with you want. Like for instance if the decive is width is 600ps
#media (max-width: 600px) {
#info #head:after {
content: '';
position: absolute;
bottom: 0;
width: 82%;
height: 3px;
box-shadow: 0 2px #1b1c1d;
}
}
or like this one when the width of the device is 1000px
#media (max-width: 1000px) {
#info #head:after {
content: '';
position: absolute;
bottom: 0;
width: 75%;
height: 3px;
box-shadow: 0 2px #1b1c1d;
}
}
for more of this please check here https://www.w3schools.com/css/css_templates.asp
This is my very first thread, I'll try to be as precise as possible.
I'm very new to working with php, and my current project is therefor quite a challenge.
I have 2 products, I would like to be able to, through ACF, to exchange both the default BG image and the hover image.
ATM I can exchange the hover, but its visible at all time.
If I add an image through the wysiwyg editor, it wont set as bg image, but on top of the content.
Heres what I have:
These are the two products. The left one has the hover bg img, shown at all time. The right one doesnt have any for now
Here you can see the ACF on the relevant page
Here is what it looks like, if I add an image through the wysiwyg editor (the hover img shows in the background)
Here is my css, for the products
Here what the code looks like:
<?php
/**
* Variables
*/
$introductiontitle = get_sub_field('introduction_title');
$introductionsubtitle = get_sub_field('introduction_subtitle');
$introductionsubtitle2 = get_sub_field('introduction_subtitle_2');
$hover_image1 = get_sub_field('hover_element_1_background');
$hover_image2 = get_sub_field('hover_element_2_background');
<!-- Introduction
-------------------------------------------------------------->
<div class="container-fluid pt-5 pb-8">
<div class="container">
<div class="row">
<div class="col-12 text-center mb-3">
<h1 class="font-weight-bold mb-3">
<?php echo $introductiontitle; ?>
</h1>
<p>
<?php echo $introductionsubtitle; ?>
</p>
<p>
<?php echo $introductionsubtitle2; ?>
</p>
</div>
<div class="col-12 col-md-6">
<div class="col-12 product chart py-5 mb-3 bg-center bg-cover"
<?php if ($hover_image1) { ?>
style="background-image: url(<?php echo $hover_image1 ?>"
<?php } ?>
>
<?php the_sub_field('hover_element_1'); ?>
</div>
</div>
<div class="col-12 col-md-6">
<div class="col-12 product chart py-5 mb-3 bg-center bg-cover"
<?php if ($hover_image2) { ?>
style="background-image: url(<?php echo $hover_image2 ?>"
<?php } ?>
>
<?php the_sub_field('hover_element_2'); ?>
</div>
</div>
</div>
</div>
I hope this all made sense!? Otherwise just let me know, and I'll explain it better.
Thanks in advance
I would've posted a comment for clarification but don't have enough points for that yet so decided I'd post an answer as it might be what you're trying to achieve.
Using a combination of layered elements and opacity you should be able to achieve an effect where the background image changes.
Here's an example using solid colours, but they can easily be changed to other elements (e.g. your custom background images, and images):
https://codepen.io/epsilon42/pen/NBNVad
HTML:
<div class="product" style="background: #ccc;"><!-- change inline style to to ACF initial background-image -->
<div class="hover-background" style="background: #666;"><!-- change inline style to to ACF hover background-image --></div>
<div class="copy">
<h2>test</h2>
<p>lorem ipsum lorem ipsum</p>
<div class="icon">
<div class="initial-icon" style="background: #f00;"><!-- change this div to initial <img> --></div>
<div class="hover-icon" style="background: #b4d455;"><!-- change this div to hover <img> --></div>
</div>
</div>
</div>
CSS:
.product {
width: 300px;
height: 300px;
position: relative;
}
.product .hover-background,
.product .copy {
width: 100%;
height: 100%;
position: absolute;
}
.product .hover-background {
opacity: 0;
transition: 0.2s all ease-in;
}
.product .copy {
text-align: center;
}
.product .copy .icon {
width: 50px;
height: 50px;
margin: 0 auto;
position: relative;
}
.product .copy .icon .initial-icon,
.product .copy .icon .hover-icon {
width: 100%;
height: 100%;
position: absolute;
}
.product .copy .icon .hover-icon {
opacity: 0;
transition: 0.2s all ease-in;
}
.product:hover .hover-background {
opacity: 1;
}
.product:hover .copy .icon .hover-icon {
opacity: 1;
}
You will need to adjust the CSS a bit to suit your situation.