Working on a HTML page that requires me to have two elements side by side to replicate a 50/50 scenario sort of thing. I am using w3.css to help me since I am not so familiar with HTML/CSS.
My code is below for the section. So when the AWords/BWords grows too big, the cell grows so it does not match the other half. What I'm trying to ask is how can I implement a uniformly increase in size? So that both halves match each other, and the halfway mark stays in the middle of the screen?
<div class="Options w3-cell-row w3-center" style="width:75%;margin: 0 auto;">
<div class="OptionA w3-container w3-cell" style="background-color: #EA4D63;border-style: solid;border-top-left-radius:25px;border-bottom-left-radius: 25px;">
<div class="w3-container">
<p class="AWords w3-xxlarge"></p>
</div>
<div class="w3-container">
<p class="AVotes w3-large"></p>
</div>
</div>
<div class="OptionB w3-container w3-cell" style="background-color:#2BA9E5;border-style: solid;border-top-right-radius: 25px;border-bottom-right-radius: 25px;">
<div class="w3-container">
<p class="BWords w3-xxlarge"></p>
</div>
<div class="w3-container">
<p class="BVotes w3-large"></p>
</div>
</div>
</div>
JSFiddle of what the code currently does
Assuming by the 'halfway' mark you mean the line that divides the two elements vertically, this arises due to the fact that W3 uses a table-based layout. Tables automatically expand to contain their contents.
As such, in order to ensure that both elements occupy the same amount of horizontal space, you simply give your cells a fixed width. This can be done by targeting .w3-cell:
.w3-cell {
width: 200px;
}
And can be seen in the following:
.w3-cell {
width: 200px;
}
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"/>
<div class="Options w3-cell-row w3-center" style="width:75%;margin: 0 auto;">
<div class="OptionA w3-container w3-cell" style="background-color: #EA4D63;border-style: solid;border-top-left-radius:25px;border-bottom-left-radius: 25px;">
<div class="w3-container">
<p class="AWords w3-xxlarge">Idk what to do</p>
</div>
<div class="w3-container">
<p class="AVotes w3-large"></p>
</div>
</div>
<div class="OptionB w3-container w3-cell" style="background-color:#2BA9E5;border-style: solid;border-top-right-radius: 25px;border-bottom-right-radius: 25px;">
<div class="w3-container">
<p class="BWords w3-xxlarge">If this side gets too big it looks weird</p>
</div>
<div class="w3-container">
<p class="BVotes w3-large"></p>
</div>
</div>
</div>
I've also created a Fiddle showcasing this here.
Note that if you want to continue to use inline styles everywhere, you'll have to apply this to both <div> elements with this class.
Hope this helps :)
Related
I tried to align several items by using two columns and positioning the text, icon, and line within the left column and the other text on the right column, but they don't align properly. It currently looks like this but it should look like the picture attached. How can I fix this?
<div class="col-12">
<h1 class="orange">LET'S RUB IT IN</h1>
<h2>How Much?</h2>
</div>
<div class="col-6"> <!--left column-->
<div class="circle side">
<img src="./chemical#2x.png" alt="chemical" class="icon">
</div>
<h5 class="side">1 Shot Glass<br>or 1 oz.</h5>
<div class="line v side"></div> <!--vertical line-->
</div>
<div class="col-6"> <!--right[enter image description here][1] column-->
<p>To fully cover your body, you'll need about 1 ounce of sunscreen or just enough to fill a shot glass.</p>
</div>
It looks like the issue is you aren't using the .container > .row > .col convention. You've skipped the .container, and are sometimes skipping the .row. Additionally, you are not using the grid for the section shown in your screenshot.
Refer to the Bootrap documentation when there are Bootstrap issues.
https://getbootstrap.com/docs/5.0/layout/grid/
The first thing is you should wrap all/most of your <body> content in a <div class="container-fluid">.
Then add any missing .rows.
This is what you have:
This is what you should have:
Write the contents of that next section to match your design.
ex.
<div class="row">
<div class="col-sm-6">
<div class="row">
<div class="col-6" style="border-right: 2px solid orange;">
<div class="circle side" data-sr-id="9" style="visibility: visible; opacity: 1; transition: opacity 2s cubic-bezier(0.5, 0, 0, 1) 0s;">
<img src="./chemical#2x.png" alt="chemical" class="icon">
</div>
</div>
<div class="col-6">
<h5 class="side">1 Shot Glass<br>or 1 oz.</h5>
<div class="line v side"></div>
</div>
</div>
</div>
<div class="col-sm-6">
<p>To fully cover your body, you'll need about 1 ounce of sunscreen or just enough to fill a shot glass. </p>
</div>
</div>
You can Refere Bootstrap Grid System
Here:https://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
It will fix your problem
I am using w3.css. So you need this in your header:
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
I want to have a twothird container (coloured green so it is easy to see it), centered in the middle of the page, but with the internal text of the twothird container appearing on the left of the container. Ie the green area is central in the white page, but the text is on the left of the green area.
This does not work (it just appears on the left):
<div class="w3-container w3-center">
<div class="w3-container w3-twothird w3-left w3-green">
Some profound utterance.
</div>
</div>
Edit:
This is the solution based on the idea presented by albydamed.
<div class="w3-row">
<div class="w3-col w3-container s0 m1 l1"></div>
<div class="w3-col w3-container s12 m10 l10 w3-green" style="text-align: left;">
Some profound utterance
</div>
<div class="w3-col w3-container s0 m1 l1"></div>
</div>
In the above 's' refers to small screens (phones), 'm' refers to medium screens (tablets) and 'l' refers to large screens. <div class="w3-row"> is the containing div for 3 column divs. In each of s, m and l the sum of the internal columns must add to 12, as the screen is split into 12 invisible columns.
In my 'm' and 'l' case I split the 3-columns 1-10-1 (must always add to 12). So my middle div takes up 10/12 of the screen width. However, in my 's' case I split it 0-12-0, instructing my middle column to take up the full width of the phone.
Apply css to the text inside your container.
CSS:
.left {
text-align: left;
}
HTML:
<div class="w3-container w3-center">
<div class="w3-container w3-twothird w3-green">
<p class="left">Some profound utterance.</p>
</div>
</div>
Although, if you really want it centered I would remove w3-two-third. That restricts where it is placed. I would recommend a more responsive design like this:
<div class="w3-row">
<div class="w3-container w3-quarter"></div>
<div class="w3-container w3-green w3-half">
<p class="left">Some profound utterance.</p>
</div>
<div class="w3-container w3-quarter"></div>
</div>
The classes have to be changed slightly for the text alignment, and you'll need to add a class with the "!important" tag following width or, in this example, inline style:
<div class="w3-content">
<div class="w3-container w3-twothird w3-green" style="float: none; margin: 0 auto; width: 66.67% !important;">
Some profound utterance.
</div>
</div>
JsFiddle
I have 2 different partial views that I am calling in my main view like this:
<div class="col-md-6">
#Html.Action("Chart", "Teams")
</div>
<div class="col-md-6">
#Html.Action("SeriesWinsChart", "Teams")
</div>
<div class="next-game">
<h3 class="text-center">The Next Game Is:</h3>
</div>
<br />
<div class="text-center">
<h3 style="color:red;">#ViewBag.NextGame</h3>
</div>
Now my problem is this:
All I have done is put background-color: green in my CSS for the class .next-game (honestly just to see what it looked like.. green is not what I am going to use)... I have gone into Inspect Element on IE and I cannot find the problem as to why the background is so big. I just want the background to be around The Next Game Is:
CSS:
.next-game{
background-color: green;
}
How do I shrink the background? I have tried width: 50%; height: 10px; //etc just to see the different changes but can't figure this out
UPDATE:
I have changed the HTML to:
<div class="next-game">
<h3 class="text-center">The Next Game Is:</h3>
<div class="text-center">
<h3 style="color:red;">#ViewBag.NextGame</h3>
</div>
</div>
<div class="col-md-6">
#Html.Action("Chart", "Teams")
</div>
<div class="col-md-6">
#Html.Action("SeriesWinsChart", "Teams")
</div>
This at least made the background render properly. So this has something to do with the partial views?
The most likely cause for this issue is that your twitter bootstrap columns have no wrapping row. You generally need all three (container, row, column) for it to render properly. What you're running into here is probably a clearfix issue. The columns are floated, which makes the next available non-floating element appear to "wrap" them. Below is a possible solution to the problem.
<div class="container">
<div class="row">
<div class="col-md-6">
#Html.Action("Chart", "Teams")
</div>
<div class="col-md-6">
#Html.Action("SeriesWinsChart", "Teams")
</div>
</div>
</div>
<div class="next-game">
<h3 class="text-center">The Next Game Is:</h3>
</div>
<br />
<div class="text-center">
<h3 style="color:red;">#ViewBag.NextGame</h3>
</div>
Other solutions include adding a .clearfix class to a wrapper for the columns or adding clear:both to .next-game.
You need
.next-game h3{
background-color: green;
}
(it's just for the header h3 inside the element with that class .next-game)
Ok so I have the following HTML
<div class="container">
<div class="row col-sm-12" id="productBrief">
<div id="RaspberryAndChocolate" style="display:none; height:200px;">
<div class="col-sm-6 text-center">
<img src="~/Content/Images/YogurtImages_404x290/Rasberry_White_Chocolate_Yogurt.png" class="img-responsive" style="margin: 0 auto; padding-top: 5%" alt="Rasberry White Chocolate Yogurt" />
</div>
<div class="col-sm-6">
<h2 class="raspberryRed productLineHeight">FLAVOUR #3</h2>
<h1 class="raspberryRed">
RASPBERRY &<br /> WHITE CHOCOLATE
</h1>
<p class="productPara">
A decadent combination of whole raspberries and smooth white chocolate that you will want to make last as long as possible. Teaspoon recommended.
</p>
<p>
<span class="label label-danone label-as-badge" style="font-size: 0.9em; padding:3%">VIEW ALL FLAVOURS</span>
</p>
</div>
</div>
<div class="clearfix"></div>
<div id="BlueBerry" style="display:none; height:200px;">
<div class="col-sm-6 text-center">
<img src="~/Content/Images/YogurtImages_404x290/Blueberry_Yogurt.png" class="img-responsive" style="margin: 0 auto; padding-top: 5%" alt="Blueberry Yogurt" />
</div>
<div class="col-sm-6">
<h2 class="blueBerry productLineHeight">FLAVOUR #6</h2>
<h1 class="blueBerry">
BLUEBERRY
</h1>
<p class="productPara">
Just imagine plump and juicy blueberries immersed in a deliciously creamy yoghurt. Enough said.
</p>
<p>
<span class="label label-as-badge" style="font-size: 0.9em; padding:3%">VIEW ALL FLAVOURS</span>
</p>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
<div class="row">
<div class="col-lg-12 text-center">
<div class="col-lg-2"></div>
<p style="width:70%;" class="text-center col-lg-8">
Experiencing Ultimate's uniquely luscious texture for the first time is beyond words. So don't even try. Take a moment to enjoy the ultra creaminess, the juicy ripened fruits and an array of wicked indulgences that come together to create a yoghurt like no other.
</p>
<div class="col-lg-2"></div>
</div>
</div>
Now there are roughly about 8 different divs but for simplicity I am only showing 2, but only one div is shown look at it as a random affect so the user refreshes the page a different div is shown (this is done in jquery) but if you look at the bottom of the HTML you will see another row with a P tag this is what is causing he issue, when displayed on a desktop it shows like this
when I minimize the browser the text at the bottom of the image displays under the text located to the right hand side of the yogurt box as shown here.
I have added the clearfix, tried adding a new container and yet the problem still remains....
You are using invalid bootstrap grid. Col should be a child of row. Use correct grid and everything will work perfectly.
Scott, hunzaboy says you need to use the dive like this
<div class="row">
<div class="col-sm-12"></div>
</div>
I don't fully understand your question, but hope you asking this,
when re-sizing your first image, I will suitably re-size without any harm to other divs. For that You need to devide that into 3 main divs, check the below code
<div class="row">
<div class="col-md-6">This is the image holding div</div><div class="col-md-6"> this is the right side text "Flavour #6, etc..."</div>
<div class="col-md-12">This is the text on the bottom</div>
</div>
I will look, 2 columns on the top and one column in the bottom.
For mobile view, you can use col-xs-12class, the it will show as stack.
Hope this is you asking. Thanks
I am using uikit 2.8.0. I am trying to create a two column grid structure. But the two columns don't appear adjacent to each other. The second column slides down the first one.
<body>
<div class="uk-container uk-container-center uk-margin-large-bottom">
<nav var code.......>
<div class="uk-grid" data-uk-grid-margin>
<div class="uk-width-medium-1-1 uk-text-center">
<h1>Tell us more about yourself</h1>
</div>
</div>
<div class="uk-grid" data-uk-grid-match="{target:'.equal-height'}">
<div class="uk-width-large-6-10" style="margin: 0 20% 0 20%;">
<div class="uk-width-7-10 uk-width-small-1-1 uk-width-medium-7-10 uk-width-large-7-10" style="border: 1px solid #B4B3B3;height:100px;">
</div>
<div class="uk-width-3-10 uk-width-small-1-1 uk-width-medium-3-10 uk-width-large-3-10" style="border: 1px solid #B4B3B3;height:100px;">
</div>
</div>
</div>
</div>
I tried many options. But come what may, the second grid would not stay side by side to the first one.
How can I fix this? Any tool that I can use to debug the layout? I am using chrome developer tools without any success.
You needed to add class ".uk-grid" to the div with styled margin (uk-width-large-6-10), as you want to make a grid inside that element.
Plus this, the "Target" element should target to something existing, best to "uk-panel" placed inside the element with "uk-width".
<div class="uk-container uk-container-center uk-margin-large-bottom">
<nav var code.......>
<div class="uk-grid" data-uk-grid-margin>
<div class="uk-width-medium-1-1 uk-text-center">
<h1>Tell us more about yourself</h1>
</div>
</div>
<div class="uk-grid">
<div class="uk-width-large-6-10 uk-grid" style="margin: 0 20% 0 20%;" data-uk-grid-match="{target:'.uk-panel'}">
<div class="uk-width-7-10 uk-width-small-1-1 uk-width-medium-7-10 uk-width-large-7-10" style="background-color:green; height:100px;">
<div class="uk-panel"> </div>
</div>
<div class="uk-width-3-10 uk-width-small-1-1 uk-width-medium-3-10 uk-width-large-3-10" style="background-color:red; height:100px;">
<div class="uk-panel"> </div>
</div>
</div>
</div>